TIME time object class constructor. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: TIME time object class constructor. Create a time object. SUPER CLASSES: ltpda_nuo < ltpda_obj PROPERTIES: Inherit Properties (read only) version - cvs-version string. Protected Properties (read only) utc_epoch_milli - Unix epoch time of the utc time. timezone - Timezone of the date/time timeformat - Matlab timeformat of the date/time time_str - Time string of the unix time in the specified timezone. TIME METHODS: Defined Abstract methods: char - returns one character string which represents the object copy - copies an object display - displays an object update_struct - updates a object structure to the current tbx-version Public methods: format - returns a time-string in specified format. getTimezones - get all possible timezones minus - overloads '-' operator for time objects. plus - overloads '+' operator for time objects. setEpochtime - set the 'utc_epoch_milli' property setTimeformat - set the 'timeformat' property setTime_str - set the 'time_str' property setTimezone - set the 'timezone' property string - writes a command string that can be used to recreate the object CONSTRUCTORS: t1 = time() t1 = time('14:00:05.000') t1 = time('2007-06-06 14:00:05') t1 = time('14:00:05 2007-06-06') t1 = time(1186135200000) t1 = time(plist) t1 = time(1186135200000, 'HH:MM:SS') Parameter sets for plist constructor (in order of priority): From XML File ------------- Construct an TIME by loading it from an XML file. 'filename' - construct an TIME from a filename. Example: plist('filename', 't1.xml') [default: empty string] From MAT File ------------- Construct an TIME by loading it from a MAT file. 'filename' - construct an TIME from a filename. Example: plist('filename', 't1.mat') [default: empty string] From Repository --------------- Construct an TIME by retrieving it from an LTPDA repository. 'Hostname' - the repository hostname. Only those objects which are TIMEs are returned. [default: 'localhost']; Additional parameters: 'Database' - The database name [default: 'ltpda'] 'ID' - A vector of object IDs. [default: []] From Time Definition -------------------- Construct an TIME by its properties definition 'utc_epoch_milli' - the time in milliseconds [default: 0]; Additional parameters: 'timezone' - Timezone (string or java object) [default: 'UTC'] 'timeformat' - Time format (string) [default: 'yyyy-mm-dd HH:MM:SS.FFF']% From Time String -------------------- Construct an TIME by its properties definition 'time_str' - the time string [default: '1970-01-01 00:00:00.000']; Additional parameters: 'timezone' - Timezone (string or java object) [default: 'UTC'] 'timeformat' - Time format (string) [default: 'yyyy-mm-dd HH:MM:SS.FFF'] From Plist ---------- 'Plist' - construct from a plist. The value passed should be a plist object. [default: empty plist] M-FILE INFO: The following call returns an minfo object that contains information about the time constructor: >> info = time.getInfo or >> info = time.getInfo('time') You can get information about class methods by calling: >> info = time.getInfo(method) e.g. >> info = time.getInfo('eq') You can also restrict the sets of parameters contained in the minfo object by calling: >> info = time.getInfo(method, set) e.g. >> info = time.getInfo('time', 'From Time String') VERSION: $Id: time.m,v 1.56 2008/09/03 16:39:15 hewitson Exp $ HISTORY: 23-07-2007 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % TIME time object class constructor. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: TIME time object class constructor. 0005 % Create a time object. 0006 % 0007 % SUPER CLASSES: ltpda_nuo < ltpda_obj 0008 % 0009 % PROPERTIES: 0010 % 0011 % Inherit Properties (read only) 0012 % version - cvs-version string. 0013 % 0014 % Protected Properties (read only) 0015 % utc_epoch_milli - Unix epoch time of the utc time. 0016 % timezone - Timezone of the date/time 0017 % timeformat - Matlab timeformat of the date/time 0018 % time_str - Time string of the unix time in the specified 0019 % timezone. 0020 % 0021 % TIME METHODS: 0022 % 0023 % Defined Abstract methods: 0024 % char - returns one character string which represents the object 0025 % copy - copies an object 0026 % display - displays an object 0027 % update_struct - updates a object structure to the current tbx-version 0028 % 0029 % Public methods: 0030 % format - returns a time-string in specified format. 0031 % getTimezones - get all possible timezones 0032 % minus - overloads '-' operator for time objects. 0033 % plus - overloads '+' operator for time objects. 0034 % setEpochtime - set the 'utc_epoch_milli' property 0035 % setTimeformat - set the 'timeformat' property 0036 % setTime_str - set the 'time_str' property 0037 % setTimezone - set the 'timezone' property 0038 % string - writes a command string that can be used to recreate the object 0039 % 0040 % CONSTRUCTORS: 0041 % 0042 % t1 = time() 0043 % t1 = time('14:00:05.000') 0044 % t1 = time('2007-06-06 14:00:05') 0045 % t1 = time('14:00:05 2007-06-06') 0046 % t1 = time(1186135200000) 0047 % t1 = time(plist) 0048 % t1 = time(1186135200000, 'HH:MM:SS') 0049 % 0050 % Parameter sets for plist constructor (in order of priority): 0051 % 0052 % From XML File 0053 % ------------- 0054 % 0055 % Construct an TIME by loading it from an XML file. 0056 % 0057 % 'filename' - construct an TIME from a filename. 0058 % Example: plist('filename', 't1.xml') 0059 % [default: empty string] 0060 % 0061 % 0062 % From MAT File 0063 % ------------- 0064 % 0065 % Construct an TIME by loading it from a MAT file. 0066 % 0067 % 'filename' - construct an TIME from a filename. 0068 % Example: plist('filename', 't1.mat') 0069 % [default: empty string] 0070 % 0071 % 0072 % From Repository 0073 % --------------- 0074 % 0075 % Construct an TIME by retrieving it from an LTPDA repository. 0076 % 0077 % 'Hostname' - the repository hostname. Only those objects which 0078 % are TIMEs are returned. 0079 % [default: 'localhost']; 0080 % 0081 % Additional parameters: 0082 % 0083 % 'Database' - The database name [default: 'ltpda'] 0084 % 'ID' - A vector of object IDs. [default: []] 0085 % 0086 % 0087 % From Time Definition 0088 % -------------------- 0089 % Construct an TIME by its properties definition 0090 % 'utc_epoch_milli' - the time in milliseconds [default: 0]; 0091 % 0092 % Additional parameters: 0093 % 0094 % 'timezone' - Timezone (string or java object) [default: 'UTC'] 0095 % 'timeformat' - Time format (string) [default: 'yyyy-mm-dd HH:MM:SS.FFF']% 0096 % 0097 % From Time String 0098 % -------------------- 0099 % Construct an TIME by its properties definition 0100 % 'time_str' - the time string [default: '1970-01-01 00:00:00.000']; 0101 % 0102 % Additional parameters: 0103 % 0104 % 'timezone' - Timezone (string or java object) [default: 'UTC'] 0105 % 'timeformat' - Time format (string) [default: 'yyyy-mm-dd HH:MM:SS.FFF'] 0106 % 0107 % 0108 % From Plist 0109 % ---------- 0110 % 0111 % 'Plist' - construct from a plist. The value passed should be a plist 0112 % object. 0113 % [default: empty plist] 0114 % 0115 % M-FILE INFO: The following call returns an minfo object that contains 0116 % information about the time constructor: 0117 % >> info = time.getInfo 0118 % or >> info = time.getInfo('time') 0119 % 0120 % You can get information about class methods by calling: 0121 % >> info = time.getInfo(method) 0122 % e.g. >> info = time.getInfo('eq') 0123 % 0124 % You can also restrict the sets of parameters contained in 0125 % the minfo object by calling: 0126 % >> info = time.getInfo(method, set) 0127 % e.g. >> info = time.getInfo('time', 'From Time String') 0128 % 0129 % VERSION: $Id: time.m,v 1.56 2008/09/03 16:39:15 hewitson Exp $ 0130 % 0131 % HISTORY: 23-07-2007 Diepholz 0132 % Creation 0133 % 0134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0135 0136 classdef time < ltpda_nuo 0137 %------------------------------------------------ 0138 %---------- Private read-only Properties -------- 0139 %------------------------------------------------ 0140 properties (SetAccess = private) 0141 utc_epoch_milli = 0; 0142 timezone = ''; 0143 timeformat = ''; 0144 time_str = ''; 0145 end 0146 %---------- Private Properties ---------- 0147 properties (GetAccess = protected, SetAccess = protected) 0148 end 0149 0150 %---------- Protected Properties ---------- 0151 properties (SetAccess = protected) 0152 version = '$Id: time.m,v 1.56 2008/09/03 16:39:15 hewitson Exp $'; 0153 end 0154 0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0156 % Check property setting % 0157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0158 0159 0160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0161 % Constructor % 0162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0163 methods 0164 function obj = time(varargin) 0165 0166 %%% Call superclass 0167 obj = obj@ltpda_nuo(varargin{:}); 0168 0169 %%%%%%%%%% Set dafault values %%%%%%%%%% 0170 %%% Exept for a struct as an input 0171 if ~(nargin == 1 && isstruct(varargin{1})) 0172 import java.util.GregorianCalendar; 0173 import java.util.TimeZone; 0174 unix_time = getTime(java.util.Date); 0175 obj.timezone = java.util.TimeZone.getTimeZone(getappdata(0, 'timezone')); 0176 obj.timeformat = getappdata(0, 'time_format_str'); 0177 % Define local/utc timezone 0178 obj.timezone = TimeZone.getTimeZone(getappdata(0, 'timezone')); 0179 end 0180 0181 switch nargin 0182 case 0 0183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0184 %%%%%%%%%%%%%%%%%%%%%%%%%%% no input %%%%%%%%%%%%%%%%%%%%%%%%%%%% 0185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0186 0187 %%%%%%%%%% t1 = time() %%%%%%%%%% 0188 obj.utc_epoch_milli = unix_time; 0189 case 1 0190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0191 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%% 0192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0193 0194 if isa(varargin{1}, 'time') 0195 %%%%%%%%%% t1 = time(time-object) %%%%%%%%%% 0196 obj = copy(varargin{1}, 1); 0197 0198 elseif ischar(varargin{1}) 0199 %%%%%%%%%% t1 = time('foo.xml') %%%%%%%%%% 0200 %%%%%%%%%% t1 = time('foo.mat') %%%%%%%%%% 0201 [path, name, ext] = fileparts(varargin{1}); 0202 if ~isempty(ext) && length(ext) == 4 && isempty(str2num(ext(2))) 0203 error('### It is not allowed to read a time-object'); 0204 else 0205 %%%%%%%%%% t1 = time('2007-08-03 10:00:00') %%%%%%%%%% 0206 obj.setTime_str(varargin{1}, 'internal'); 0207 end 0208 0209 elseif isstruct(varargin{1}) 0210 %%%%%%%%%% t1 = time(structure) %%%%%%%%%% 0211 0212 %%% Set properties which are declared in this class 0213 t_struct = varargin{1}; 0214 0215 obj.utc_epoch_milli = t_struct.utc_epoch_milli; 0216 obj.timezone = t_struct.timezone; 0217 obj.timeformat = t_struct.timeformat; 0218 obj.time_str = t_struct.time_str; 0219 obj.version = t_struct.version; 0220 0221 elseif isnumeric(varargin{1}) 0222 0223 %%%%%%%%%% t1 = time(1214914600000) %%%%%%%%%% 0224 % We utc epoch milliseconds as input 0225 obj.utc_epoch_milli = varargin{1}; 0226 0227 elseif isa(varargin{1}, 'plist') 0228 0229 %%%%%%%%%% t1 = time(plist) %%%%%%%%%% 0230 pl = varargin{1}; 0231 hostname = find(pl, 'hostname'); 0232 pl_epoch_milli = find(pl, 'utc_epoch_milli'); 0233 pl_time_str = find(pl, 'time_str'); 0234 ipl = find(pl, 'plist'); 0235 0236 if ~isempty(hostname) 0237 %----------------------------------------------------- 0238 %--- Construct from repository 0239 %----------------------------------------------------- 0240 % do hostname constructor 0241 obj = fromRepository(obj, pl, VERSION, ALGONAME); 0242 0243 elseif ~isempty(pl_epoch_milli) 0244 %----------------------------------------------------- 0245 %--- Construct from millisecs time definition 0246 %----------------------------------------------------- 0247 obj = fromTimeValue(obj, pl); 0248 0249 elseif ~isempty(pl_time_str) 0250 %----------------------------------------------------- 0251 %--- Construct from string time definition 0252 %----------------------------------------------------- 0253 obj = fromTimeString(obj, pl); 0254 0255 elseif ~isempty(ipl) 0256 %----------------------------------------------------- 0257 %--- Construct from plist 0258 %----------------------------------------------------- 0259 0260 % if the plist is empty, we return the default time object 0261 if nparams(ipl) == 0 0262 % default time object 0263 else 0264 % do plist constructor 0265 obj = time(ipl); 0266 end 0267 0268 else 0269 %----------------------------------------------------- 0270 %--- ERROR 0271 %----------------------------------------------------- 0272 0273 %%% if the plist is empty then return the default time object 0274 if nparams(pl) == 0 0275 % default time object 0276 else 0277 error('### Unknown TIME constructor method.'); 0278 end 0279 end 0280 0281 else 0282 error('### Unknown single argument constructor.'); 0283 end 0284 0285 case 2 0286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0287 %%%%%%%%%%%%%%%%%%%%%%%%%%% two input %%%%%%%%%%%%%%%%%%%%%%%%%%% 0288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0289 0290 if isnumeric(varargin{1}) && ischar(varargin{2}) 0291 %%%%%%%%%% t1 = time(2000, 'HH:MM:SS') %%%%%%%%%% 0292 obj.setEpochtime(varargin{1}); 0293 obj.setTimeformat(varargin{2}); 0294 0295 elseif ischar(varargin{1}) && ischar(varargin{2}) 0296 %%%%%%%%%% t1 = time('14:00:00', 'HH:MM:SS') %%%%%%%%%% 0297 obj.setTime_str(varargin{1}); 0298 obj.setTimeformat(varargin{2}); 0299 0300 else 0301 error('### Unknown constructor with two inputs.'); 0302 end 0303 0304 otherwise 0305 error('### Unknown number of constructor arguments.'); 0306 end % End switch over input args 0307 end % End time() 0308 end % End constructor 0309 0310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0311 % Methods (Public) % 0312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0313 0314 methods 0315 varargout = copy(varargin) 0316 varargout = format(varargin) 0317 varargout = getTimezones(varargin) 0318 varargout = minus(varargin) 0319 varargout = plus(varargin) 0320 varargout = string(varargin) 0321 0322 varargout = setEpochtime(varargin) 0323 varargout = setTimezone(varargin) 0324 varargout = setTimeformat(varargin) 0325 varargout = setTime_str(varargin) 0326 end % End public methods 0327 0328 0329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0330 % Methods (protected) % 0331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0332 0333 methods (Access = protected) 0334 end 0335 0336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0337 % Methods (private) % 0338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0339 0340 methods (Access = private) 0341 varargout = fromTimeValue(varargin) 0342 varargout = fromTimeString(varargin) 0343 end 0344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0345 % Methods (static) % 0346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0347 methods (Static) 0348 0349 varargout = update_struct(varargin); 0350 0351 function ii = getInfo(varargin) 0352 ii = utils.helper.generic_getInfo(varargin{:}, 'time'); 0353 end 0354 0355 function out = VEROUT() 0356 out = '$Id: time.m,v 1.56 2008/09/03 16:39:15 hewitson Exp $'; 0357 end 0358 0359 function out = SETS() 0360 out = {... 0361 'Default', ... 0362 'From Repository', ... 0363 'From Time Definition', ... 0364 'From Time String', ... 0365 'From Plist'}; 0366 end 0367 0368 function out = getDefaultPlist(set) 0369 0370 switch set 0371 case 'Default' 0372 out = plist(); 0373 case 'From Repository' 0374 %--- Repository constructor 0375 out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []); 0376 case 'From Time Definition' 0377 %--- Definition constructor 0378 out = plist(... 0379 'utc_epoch_milli', 0, ... 0380 'timezone', 'UTC', ... 0381 'timeformat', 'yyyy-mm-dd HH:MM:SS.FFF'); 0382 case 'From Time String' 0383 %--- String constructor 0384 out = plist(... 0385 'time_str', '1970-01-01 00:00:00.000', ... 0386 'timezone', 'UTC', ... 0387 'timeformat', 'yyyy-mm-dd HH:MM:SS.FFF'); 0388 %--- Create from a plist 0389 case 'From Plist' 0390 out = plist('Plist', []); 0391 otherwise 0392 error('### Unknown set [%s] to get the default plist.', set); 0393 end 0394 end % End getDefaultPlist 0395 0396 end % End static methods 0397 0398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0399 % Methods (static, private) % 0400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0401 0402 methods (Static, Access=private) 0403 0404 varargout = parse_time_string(varargin) 0405 [time_str, created_str] = epoch2str(tt) 0406 0407 end % End static, private methods 0408 end % End classdef 0409 0410