view m-toolbox/classes/@timespan/fromTimespanDef.m @ 13:e05504b18072 database-connection-manager

Move more functions to utils.repository
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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