view m-toolbox/classes/@time/plus.m @ 2:18e956c96a1b database-connection-manager

Add LTPDADatabaseConnectionManager implementation. Matlab code
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Sun, 04 Dec 2011 21:23:09 +0100
parents f0afece42f48
children
line wrap: on
line source

% PLUS Implements addition operator for time objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: Implements addtion operator for time objects. Numeric and string
% operands are transparently handled converting them to time objects. Vector
% operands are handled accordingly to MATLAB conventions.
%
% VERSION: $Id: plus.m,v 1.20 2011/05/05 12:29:34 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function t = plus(t1, t2)

  if isnumeric(t1)
    d1 = t1*1000;
  elseif ischar(t1)
    d1 = time(t1).utc_epoch_milli;
  elseif isa(t1, 'time')
    d1 = t1.utc_epoch_milli;
  else
    error('LTPDA:TypeError', ...
          '### unsupported operand classes for plus: ''%s'' and ''%s''', ...
          class(t1), class(t2));
  end

  if isnumeric(t2)
    d2 = t2*1000;
  elseif ischar(t2)
    d2 = time(t2).utc_epoch_milli;
  elseif isa(t2, 'time')
    d2 = t2.utc_epoch_milli;
  else
    error('LTPDA:TypeError', ...
          '### unsupported operand classes for plus: ''%s'' and ''%s''', ...
          class(t1), class(t2));
  end
  
  t = time((d1 + d2)/1000);
end