44
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % UTP_TIME_FORMAT
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % <MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % Test the 'format' method of the time class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % </MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % NOTE: in this test we manipulate user preferences thus we should make
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % sure we restore the original user preferences at the end of the testing
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % $Id: utp_time_format.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 function results = utp_time_format(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % check inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 if nargin == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % some keywords
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 class = 'time';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 mthd = 'format';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 results = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 disp(['**** Running UTPs for ' class '/' mthd]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % get preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 prefs = getappdata(0, 'LTPDApreferences');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 oldTimezone = char(prefs.getTimePrefs.getTimeTimezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 oldTimeformat = char(prefs.getTimePrefs.getTimestringFormat);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % get preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 results = [results utp_901];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 catch ex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % restore preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 prefs.getTimePrefs.setTimeTimezone(oldTimezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 rethrow(ex);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % restore preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 prefs.getTimePrefs.setTimeTimezone(oldTimezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 prefs.getTimePrefs.setTimestringFormat(oldTimeformat);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 disp('Done.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 elseif nargin == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % check for UTP functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 if strcmp(varargin{1}, 'isutp')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 results = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 results = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 error('### Incorrect inputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 %% UTP_901
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % Tests 'format' static method.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 function result = utp_901
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % Use the static format method to produce a number of time strings in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % different formats and for different time-zones.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % set time zone and time format in the toolbox preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 prefs.getTimePrefs.setTimeTimezone('CET');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 prefs.getTimePrefs.setTimestringFormat('yyyy-mm-dd HH:MM:SS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 t = time('1970-01-01 00:00:00.000 UTC');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 str1 = t.format();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 str2 = t.format('HH:MM:SS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 str3 = t.format('HH:MM:SS', 'JST');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 % set time zone and time format in the toolbox preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 prefs.getTimePrefs.setTimeTimezone('UTC');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 prefs.getTimePrefs.setTimestringFormat('yyyy-mm-dd HH:MM:SS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 str4 = t.format();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 str5 = t.format('HH:MM:SS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 str6 = t.format('HH:MM:SS', 'JST');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % do not run algorithm tests if sintax tests failed
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 assert(stest);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % Check that the returned strings match the expected strings.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 assert(strcmp(str1, '1970-01-01 01:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 assert(strcmp(str2, '01:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 assert(strcmp(str3, '09:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 assert(strcmp(str4, '1970-01-01 00:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 assert(strcmp(str5, '00:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 assert(strcmp(str6, '09:00:00'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 catch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 % return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 end
|