Home > classes > @timespan > fromTimespanDef.m

fromTimespanDef

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function obj = fromTimespanDef(obj, pli)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    fromTimespanDef

 DESCRIPTION: Construct an timespan from start and end time

 CALL:        ts = fromTimespanDef(ts, t1, t2)

 INPUT:       ts = timespan-object
              t1 = start time (char or time-object)
              t2 = end   time (char or time-object)

 HISTORY:     23-07-2008 Diepholz
              Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0002 %
0003 % FUNCTION:    fromTimespanDef
0004 %
0005 % DESCRIPTION: Construct an timespan from start and end time
0006 %
0007 % CALL:        ts = fromTimespanDef(ts, t1, t2)
0008 %
0009 % INPUT:       ts = timespan-object
0010 %              t1 = start time (char or time-object)
0011 %              t2 = end   time (char or time-object)
0012 %
0013 % HISTORY:     23-07-2008 Diepholz
0014 %              Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 function obj = fromTimespanDef(obj, pli)
0018 
0019   VERSION = '$Id: fromTimespanDef.m,v 1.3 2008/09/04 13:37:15 ingo Exp $';
0020   % get timespan info
0021   ii = timespan.getInfo('timespan', 'From Timespan Definition');
0022 
0023   % Set the method version string in the minfo object
0024   ii.setMversion([VERSION '-->' ii.mversion]);
0025   
0026   t1 = pli.find('startT');
0027   if isempty(t1)
0028     t1 = pli.find('start');
0029   end
0030   t2 = pli.find('endT');
0031   if isempty(t2)
0032     t2 = pli.find('end');
0033   end
0034   
0035   % Add default values
0036   pl = combine(pli, ii.plists);
0037 
0038   tf = pl.find('timeformat');
0039   tz = pl.find('timezone');
0040 
0041   
0042   if ischar(t1) || isnumeric(t1)
0043     t1 = time(t1);
0044   elseif ~isa(t1, 'time')
0045     error('### The start time must be a string or a time-object. But it is from the class [%s]', class(t1));
0046   end
0047 
0048   if ischar(t2) || isnumeric(t2)
0049     t2 = time(t2);
0050   elseif ~isa(t2, 'time')
0051     error('### The end time must be a string or a time-object. But it is from the class [%s]', class(t2));
0052   end
0053 
0054   obj.startT = time(t1);
0055   obj.endT   = time(t2);
0056 
0057   % Adjust the 'timeformat' AND the 'timezone' of the end time to the start time.
0058   if isempty(tf)
0059     obj.setTimeformat(obj.startT.timeformat, 'internal');
0060   else
0061     obj.setTimeformat(tf, 'internal');
0062   end
0063   if isempty(tz)
0064     obj.setTimezone(obj.startT.timezone, 'internal');
0065   else
0066     obj.setTimezone(tz, 'internal');
0067   end
0068 
0069   % Compute the interval
0070   obj = computeInterval(obj);
0071   
0072   % Add history
0073   obj.addHistory(ii, pl, [], obj.hist);
0074 
0075 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003