diff m-toolbox/classes/@timespan/fromTimespanDef.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@timespan/fromTimespanDef.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,69 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% 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)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function obj = fromTimespanDef(obj, pli)
+
+  VERSION = '$Id: fromTimespanDef.m,v 1.17 2011/08/22 05:57:29 hewitson Exp $';
+
+  % get timespan info
+  ii = timespan.getInfo('timespan', 'From Timespan Definition');
+
+  % set the method version string in the minfo object
+  ii.setMversion([VERSION '-->' ii.mversion]);
+
+  % apply default values
+  pl = applyDefaults(ii.plists, pli);
+  
+  % obtain parameters from plist
+  t1 = pl.find('startT');
+  if isempty(t1)
+    t1 = pl.find('start');
+  end
+  t2 = pl.find('endT');
+  if isempty(t2)
+    t2 = pl.find('end');
+  end
+  tf = find(pl, 'timeformat');
+  tz = find(pl, 'timezone');
+
+  if isa(t1, 'time');
+    % if parameter is a time object copy it
+    t1 = copy(t1, 1);
+  else
+    % otherwise costruct a time object from input parameters
+    t1 = time(plist('time', t1, 'timeformat', tf, 'timezone', tz));
+  end
+  if isa(t2, 'time');
+    % if parameter is a time object copy it
+    t2 = copy(t2, 1);
+  else
+    % otherwise costruct a time object from input parameters
+    t2 = time(plist('time', t2, 'timeformat', tf, 'timezone', tz));
+  end
+
+  % set start and end times
+  obj.startT = t1;
+  obj.endT   = t2;
+
+  % NOTE: in principle we should have been able to set the startT and endT
+  % in the plist and let setObjectProperties do the seeting, but since
+  % these properties have non-standard case, it's hard to dynamically
+  % construct the setter name.
+    
+  % add history
+  obj.addHistory(ii, pl, [], obj.hist);
+    
+  % set object properties from plist
+  obj.setObjectProperties(pl, {'startT', 'endT'});
+
+end