diff m-toolbox/classes/@time/minus.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/@time/minus.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,39 @@
+% MINUS Implements subtraction operator for time objects.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: Implements subtraction 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: minus.m,v 1.18 2011/05/05 12:29:34 hewitson Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function t = minus(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 minus: ''%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 minus: ''%s'' and ''%s''', ...
+          class(t1), class(t2));
+  end
+  
+  t = time((d1 - d2)/1000);
+end