Mercurial > hg > ltpda
comparison m-toolbox/classes/@time/time.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 % TIME Time object class constructor. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Time object class constructor. Time objects are lightweight | |
5 % ltpda user objects that can be used to operate with times. | |
6 % Their use in the graphical user interface is limited to | |
7 % their creation. | |
8 % | |
9 % SUPERCLASSES: ltpda_nuo < ltpda_obj | |
10 % | |
11 % CONSTRUCTORS: | |
12 % | |
13 % t1 = time() | |
14 % t1 = time('14:00:05.000') | |
15 % t1 = time('2007-06-06 14:00:05') | |
16 % t1 = time('14:00:05 2007-06-06') | |
17 % t1 = time(1234.5) | |
18 % t1 = time([0 2000 6000]) | |
19 % t1 = time(plist) | |
20 % | |
21 % PLIST CONSTRUCTORS: | |
22 % | |
23 % From Milliseconds | |
24 % ----------------- | |
25 % | |
26 % Construct a time object from its representation in milliseconds since the | |
27 % unix epoch, 1970-01-01 00:00:00.000 UTC: | |
28 % | |
29 % 'milliseconds' - time in milliseconds. default: 0 | |
30 % | |
31 % From Time | |
32 % --------- | |
33 % | |
34 % Construct a time object from its representation as a string or its | |
35 % representation as number of seconds since the unix epoch, 1970-01-01 | |
36 % 00:00:00.000 UTC: | |
37 % | |
38 % 'time' - time string or double. default: '1970-01-01 00:00:00.000 UTC' | |
39 % | |
40 % If the time is specified as a string it is possible to specify the format | |
41 % and the timezone that must be used to interpret the string: | |
42 % | |
43 % 'timezone' - timezone. default: '' | |
44 % 'timeformat' - time format string. default: '' | |
45 % | |
46 % | |
47 % SEE ALSO: timespan | |
48 % | |
49 % VERSION: $Id: time.m,v 1.90 2011/03/28 17:02:29 ingo Exp $ | |
50 % | |
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
52 | |
53 classdef time < ltpda_nuo | |
54 | |
55 % private read-only properties | |
56 properties (SetAccess = private) | |
57 utc_epoch_milli = 0; % unix epoch time in milliseconds | |
58 end | |
59 | |
60 % protected properties | |
61 properties (SetAccess = protected) | |
62 end | |
63 | |
64 % constant properties | |
65 properties (Constant = true) | |
66 timeformat; | |
67 timezone; | |
68 end | |
69 | |
70 % constant properties access methods | |
71 methods | |
72 function value = get.timezone(obj) | |
73 p = getappdata(0, 'LTPDApreferences'); | |
74 value = char(p.getTimePrefs.getTimeTimezone); | |
75 if ischar(value) | |
76 value = java.util.TimeZone.getTimeZone(value); | |
77 end | |
78 end | |
79 | |
80 function value = get.timeformat(obj) | |
81 p = getappdata(0, 'LTPDApreferences'); | |
82 value = char(p.getTimePrefs.getTimestringFormat); | |
83 end | |
84 end | |
85 | |
86 % constructor | |
87 methods | |
88 function obj = time(varargin) | |
89 | |
90 switch nargin | |
91 case 0 | |
92 % no input arguments. return the current time | |
93 obj.utc_epoch_milli = time.now(); | |
94 case 1 | |
95 % one input | |
96 | |
97 if isa(varargin{1}, 'time') | |
98 % t1 = time(time-object) | |
99 obj = copy(varargin{1}, 1); | |
100 | |
101 elseif ischar(varargin{1}) | |
102 % t1 = time('2007-08-03 10:00:00') | |
103 obj.utc_epoch_milli = time.parse(varargin{1}); | |
104 | |
105 elseif isstruct(varargin{1}) | |
106 % t1 = time(structure) | |
107 obj = fromStruct(obj, varargin{1}); | |
108 | |
109 elseif isnumeric(varargin{1}) | |
110 % t1 = time(12345) | |
111 for kk = 1:numel(varargin{1}) | |
112 obj(kk).utc_epoch_milli = 1000*varargin{1}(kk); | |
113 end | |
114 obj = reshape(obj, size(varargin{1})); | |
115 | |
116 elseif iscell(varargin{1}) | |
117 % t1 = time({'14:00:00', '15:00:00'}) | |
118 for kk = 1:numel(varargin{1}) | |
119 obj(kk) = time(varargin{1}{kk}); | |
120 end | |
121 obj = reshape(obj, size(varargin{1})); | |
122 | |
123 elseif isa(varargin{1}, 'plist') | |
124 % t1 = time(plist) | |
125 pl = varargin{1}; | |
126 pl_msec = find(pl, 'milliseconds'); | |
127 pl_time = find(pl, 'time'); | |
128 | |
129 if ~isempty(pl_msec) | |
130 % construct from milliseconds time definition | |
131 obj.utc_epoch_milli = pl_msec; | |
132 | |
133 elseif ~isempty(pl_time) | |
134 % construct from numefic value or string | |
135 if ischar(pl_time) | |
136 pl_timezone = find(pl, 'timezone'); | |
137 pl_format = find(pl, 'timeformat'); | |
138 obj.utc_epoch_milli = time.parse(pl_time, pl_format, pl_timezone); | |
139 elseif isnumeric(pl_time) | |
140 obj.utc_epoch_milli = 1000*pl_time; | |
141 end | |
142 | |
143 else | |
144 % if the plist is empty then return the default time object | |
145 if nparams(pl) == 0 | |
146 % default time object | |
147 else | |
148 error('### Unknown TIME constructor method.'); | |
149 end | |
150 end | |
151 | |
152 else | |
153 error('### Unknown single argument constructor.'); | |
154 end | |
155 | |
156 case 2 | |
157 % two input | |
158 | |
159 if iscellstr(varargin) | |
160 % t1 = time('14:00:00', 'HH:MM:SS') | |
161 obj.utc_epoch_milli = time.parse(varargin{1}, varargin{2}); | |
162 | |
163 elseif isnumeric(varargin{1}) && ischar(varargin{2}) | |
164 % t1 = time(1234.5, 'HH:MM:SS') | |
165 % NOTE: this is kept for back compatibility only. the second argument is just ignored | |
166 warning('LTPDA:time', 'time(numeric, char) costructor is deprecated and will be soon removed'); | |
167 obj = time(varargin{1}); | |
168 | |
169 elseif isa(varargin{1}, 'time') && ischar(varargin{2}) | |
170 % t1 = time(1234.5, 'HH:MM:SS') | |
171 % NOTE: this is kept for back compatibility only. the second argument is just ignored | |
172 warning('LTPDA:time', 'time(time, char) costructor is deprecated and will be soon removed'); | |
173 obj = time(varargin{1}); | |
174 | |
175 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && isa(varargin{2}, 'history') | |
176 % t1 = time(dom-node, history-objects) | |
177 obj = fromDom(obj, varargin{1}, varargin{2}); | |
178 | |
179 else | |
180 error('### Unknown constructor with two inputs: %s %s.', class(varargin{1}), class(varargin{2})); | |
181 end | |
182 | |
183 otherwise | |
184 error('### Unknown number of constructor arguments.'); | |
185 end | |
186 | |
187 end | |
188 end | |
189 | |
190 % public methods | |
191 methods | |
192 varargout = copy(varargin) | |
193 varargout = format(varargin) | |
194 varargout = minus(varargin) | |
195 varargout = plus(varargin) | |
196 varargout = string(varargin) | |
197 varargout = double(varargin) | |
198 varargout = datenum(varargin) | |
199 end | |
200 | |
201 % hidden methods | |
202 methods (Hidden = true) | |
203 varargout = attachToDom(varargin) | |
204 end | |
205 | |
206 % private methods | |
207 methods (Access = private) | |
208 end | |
209 | |
210 % protected methods | |
211 methods (Access = protected) | |
212 varargout = fromStruct(varargin) | |
213 varargout = fromDom(varargin) | |
214 end | |
215 | |
216 % static methods | |
217 methods (Static) | |
218 | |
219 varargout = parse(varargin); | |
220 varargout = getdateform(varargin); | |
221 varargout = matfrmt2javafrmt(varargin); | |
222 varargout = strftime(varargin); | |
223 varargout = getTimezones(varargin) | |
224 | |
225 function msec = now() | |
226 msec = java.util.Date().getTime(); | |
227 end | |
228 | |
229 function ii = getInfo(varargin) | |
230 ii = utils.helper.generic_getInfo(varargin{:}, 'time'); | |
231 end | |
232 | |
233 function out = VEROUT() | |
234 out = '$Id: time.m,v 1.90 2011/03/28 17:02:29 ingo Exp $'; | |
235 end | |
236 | |
237 function out = SETS() | |
238 out = {... | |
239 'Default', ... | |
240 'From Milliseconds', ... | |
241 'From Time' }; | |
242 end | |
243 | |
244 function out = getDefaultPlist(set) | |
245 switch lower(set) | |
246 case 'default' | |
247 out = plist(); | |
248 case 'from milliseconds' | |
249 out = plist('milliseconds', 0); | |
250 case 'from time' | |
251 out = plist('time', '1970-01-01 00:00:00.000 UTC', 'timezone', '', 'timeformat', ''); | |
252 otherwise | |
253 error('### Unknown set ''%s'' to get the default plist.', set); | |
254 end | |
255 end | |
256 | |
257 function obj = initObjectWithSize(n,m) | |
258 obj = time.newarray([n m]); | |
259 end | |
260 | |
261 end % end static methods | |
262 | |
263 % static hidden methods | |
264 methods (Static = true, Hidden = true) | |
265 varargout = loadobj(varargin) | |
266 varargout = update_struct(varargin) | |
267 end | |
268 | |
269 end % end classdef | |
270 |