Mercurial > hg > ltpda
comparison m-toolbox/classes/@timespan/computeInterval.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % COMPUTEINTERVAL compute the interval of the time span. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: COMPUTE_INTERVAL compute the interval of the time span. | |
5 % | |
6 % CALL: str = compute_interval(t1) | |
7 % | |
8 % VERSION: $Id: computeInterval.m,v 1.3 2010/05/10 13:38:50 ingo Exp $ | |
9 % | |
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
11 | |
12 function interval = computeInterval(ts) | |
13 | |
14 interval = ''; | |
15 | |
16 number = abs(ts.startT.utc_epoch_milli-ts.endT.utc_epoch_milli); | |
17 | |
18 if (ts.endT.utc_epoch_milli-ts.startT.utc_epoch_milli < 0) | |
19 interval = '-'; | |
20 end | |
21 | |
22 form = java.text.SimpleDateFormat; | |
23 form.setTimeZone(java.util.TimeZone.getTimeZone('UTC')); | |
24 | |
25 form.applyPattern('yyyy') | |
26 num_y = char(form.format(java.util.Date(number))); | |
27 num_y = str2double(num_y); | |
28 num_y = num_y - 1970; | |
29 num_y = sprintf('%02d', num_y); | |
30 | |
31 form.applyLocalizedPattern('DD') | |
32 num_d = char(form.format(java.util.Date(number))); | |
33 num_d = sprintf('%02d', str2double(num_d)-1); | |
34 | |
35 form.applyLocalizedPattern('HH') | |
36 num_h = char(form.format(java.util.Date(number))); | |
37 | |
38 form.applyLocalizedPattern('mm') | |
39 num_m = char(form.format(java.util.Date(number))); | |
40 | |
41 form.applyLocalizedPattern('ss') | |
42 num_s = char(form.format(java.util.Date(number))); | |
43 | |
44 form.applyLocalizedPattern('SSS') | |
45 num_milli_s = char(form.format(java.util.Date(number))); | |
46 | |
47 if ~strcmp(num_y, '00') | |
48 interval = [interval num_y ' Years ']; | |
49 end | |
50 | |
51 if ~strcmp(num_d, '00') | |
52 interval = [interval num_d ' Days ']; | |
53 end | |
54 | |
55 if ~strcmp(num_h, '00') | |
56 interval = [interval num_h ' Hours ']; | |
57 end | |
58 | |
59 if ~strcmp(num_m, '00') | |
60 interval = [interval num_m ' Minutes ']; | |
61 end | |
62 | |
63 if ~strcmp(num_s, '00') | |
64 interval = [interval num_s ' Seconds ']; | |
65 end | |
66 | |
67 if ~strcmp(num_milli_s, '000') | |
68 interval = [interval num_milli_s ' Milliseconds ']; | |
69 end | |
70 | |
71 if isempty(interval) | |
72 interval = '0 Seconds'; | |
73 end | |
74 | |
75 end | |
76 | |
77 |