Home > classes > @timespan > private > compute_interval.m

compute_interval

PURPOSE ^

COMPUTE_INTERVAL compute the interval of the time span.

SYNOPSIS ^

function ts = compute_interval(ts)

DESCRIPTION ^

 COMPUTE_INTERVAL compute the interval of the time span.

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

 DESCRIPTION: COMPUTE_INTERVAL compute the interval of the time span.

 CALL:        t1 = compute_interval(t1)

 VERSION:     $Id: compute_interval.m,v 1.4 2008/03/27 12:09:41 ingo Exp $

 HISTORY:     03-08-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ts = compute_interval(ts)
0002 % COMPUTE_INTERVAL compute the interval of the time span.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: COMPUTE_INTERVAL compute the interval of the time span.
0007 %
0008 % CALL:        t1 = compute_interval(t1)
0009 %
0010 % VERSION:     $Id: compute_interval.m,v 1.4 2008/03/27 12:09:41 ingo Exp $
0011 %
0012 % HISTORY:     03-08-2007 Diepholz
0013 %                 Creation
0014 %
0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016 
0017 ts.interval = '';
0018 
0019 number = abs(ts.start.utc_epoch_milli-ts.end.utc_epoch_milli);
0020 
0021 if (ts.end.utc_epoch_milli-ts.start.utc_epoch_milli < 0)
0022   ts.interval = '-';
0023 end
0024 
0025 form = java.text.SimpleDateFormat;
0026 form.setTimeZone(java.util.TimeZone.getTimeZone('UTC'));
0027 
0028 form.applyPattern('yyyy')
0029 num_y = char(form.format(java.util.Date(number)));
0030 num_y = str2num(num_y);
0031 num_y = num_y - 1970;
0032 num_y = sprintf('%02d', num_y);
0033 
0034 form.applyLocalizedPattern('DD')
0035 num_d = char(form.format(java.util.Date(number)));
0036 num_d = sprintf('%02d', str2num(num_d)-1);
0037 
0038 form.applyLocalizedPattern('HH')
0039 num_h = char(form.format(java.util.Date(number)));
0040 
0041 form.applyLocalizedPattern('mm')
0042 num_m = char(form.format(java.util.Date(number)));
0043 
0044 form.applyLocalizedPattern('ss')
0045 num_s = char(form.format(java.util.Date(number)));
0046 
0047 form.applyLocalizedPattern('SSS')
0048 num_milli_s = char(form.format(java.util.Date(number)));
0049 
0050 if ~strcmp(num_y, '00')
0051   ts.interval = [ts.interval num_y ' Years '];
0052 end
0053 
0054 if ~strcmp(num_d, '00')
0055   ts.interval = [ts.interval num_d ' Days '];
0056 end
0057 
0058 if ~strcmp(num_h, '00')
0059   ts.interval = [ts.interval num_h ' Hours '];
0060 end
0061 
0062 if ~strcmp(num_m, '00')
0063   ts.interval = [ts.interval num_m ' Minutes '];
0064 end
0065 
0066 if ~strcmp(num_s, '00')
0067   ts.interval = [ts.interval num_s ' Seconds '];
0068 end
0069 
0070 if ~strcmp(num_milli_s, '000')
0071   ts.interval = [ts.interval num_milli_s ' Milliseconds '];
0072 end
0073 
0074 
0075

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003