Home > classes > @time > time.m

time

PURPOSE ^

TIME time object class constructor.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 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.54 2008/08/11 07:25:40 hewitson Exp $

 HISTORY:      23-07-2007 Diepholz
                  Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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.54 2008/08/11 07:25:40 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   %---------- Abstract Properties ----------
0151   properties (Abstract = true, SetAccess = protected)
0152   end
0153 
0154   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0155   %                          Check property setting                           %
0156   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0157 
0158   methods
0159     function obj = set.time_str(obj, val)
0160       if ~ischar(val)
0161         error('### The value for the property ''time_str'' must be a string.');
0162       end
0163       obj.time_str = val;
0164     end
0165     function obj = set.timeformat(obj, val)
0166       if ~ischar(val)
0167         error('### The value for the property ''timeformat'' must be a string.');
0168       end
0169       obj.timeformat = val;
0170     end
0171     function obj = set.timezone(obj, val)
0172       if ~strcmp(class(val), 'sun.util.calendar.ZoneInfo')
0173         error('### The value for the property ''timezone'' must be a java sun.util.calendar.ZoneInfo object.');
0174       end
0175       obj.timezone = val;
0176     end
0177     function obj = set.utc_epoch_milli(obj, val)
0178       if ~isnumeric(val)
0179         error('### The value for the property ''utc_epoch_milli'' must be a number.');
0180       end
0181       obj.utc_epoch_milli = val;
0182     end
0183   end % End check property methods
0184 
0185   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0186   %                               Constructor                                 %
0187   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0188   methods
0189     function obj = time(varargin)
0190 
0191       %%% Call superclass
0192       obj = obj@ltpda_nuo(varargin{:});
0193 
0194       %%%%%%%%%%   Set dafault values   %%%%%%%%%%
0195       %%% Exept for a struct as an input
0196       if ~(nargin == 1 && isstruct(varargin{1}))
0197         import java.util.GregorianCalendar;
0198         import java.util.TimeZone;
0199         unix_time = getTime(java.util.Date);
0200         obj.timezone   = java.util.TimeZone.getTimeZone(getappdata(0, 'timezone'));
0201         obj.timeformat = getappdata(0, 'time_format_str');
0202         % Define local/utc timezone
0203         obj.timezone = TimeZone.getTimeZone(getappdata(0, 'timezone'));
0204 
0205         % set version
0206         obj.setVersion('$Id: time.m,v 1.54 2008/08/11 07:25:40 hewitson Exp $');
0207       end
0208 
0209       switch nargin
0210         case 0
0211           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0212           %%%%%%%%%%%%%%%%%%%%%%%%%%%   no input   %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0213           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0214 
0215           %%%%%%%%%%  t1 = time()   %%%%%%%%%%
0216           obj.utc_epoch_milli = unix_time;
0217         case 1
0218           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0219           %%%%%%%%%%%%%%%%%%%%%%%%%%%   one input   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0220           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0221 
0222           if isa(varargin{1}, 'time')
0223             %%%%%%%%%%   t1 = time(time-object)   %%%%%%%%%%
0224             obj = copy(varargin{1}, 1);
0225 
0226           elseif ischar(varargin{1})
0227             %%%%%%%%%%   t1 = time('foo.xml')   %%%%%%%%%%
0228             %%%%%%%%%%   t1 = time('foo.mat')   %%%%%%%%%%
0229             [path, name, ext] = fileparts(varargin{1});
0230             if ~isempty(ext) && length(ext) == 4 && isempty(str2num(ext(2)))
0231               error('### It is not allowed to read a time-object');
0232             else
0233               %%%%%%%%%%   t1 = time('2007-08-03 10:00:00')   %%%%%%%%%%
0234               obj.setTime_str(varargin{1}, 'internal');
0235             end
0236 
0237           elseif isstruct(varargin{1})
0238             %%%%%%%%%%   t1 = time(structure)   %%%%%%%%%%
0239 
0240             %%% Set properties which are declared in this class
0241             t_struct = varargin{1};
0242 
0243             obj.utc_epoch_milli = t_struct.utc_epoch_milli;
0244             obj.timezone        = t_struct.timezone;
0245             obj.timeformat      = t_struct.timeformat;
0246             obj.time_str        = t_struct.time_str;
0247 
0248           elseif isnumeric(varargin{1})
0249 
0250             %%%%%%%%%%   t1 = time(1214914600000)   %%%%%%%%%%
0251             % We utc epoch milliseconds as input
0252             obj.utc_epoch_milli = varargin{1};
0253 
0254           elseif isa(varargin{1}, 'plist')
0255 
0256             %%%%%%%%%%   t1 = time(plist)   %%%%%%%%%%
0257             pl             = varargin{1};
0258             hostname       = find(pl, 'hostname');
0259             pl_epoch_milli = find(pl, 'utc_epoch_milli');
0260             pl_time_str    = find(pl, 'time_str');
0261             ipl            = find(pl, 'plist');
0262 
0263             if ~isempty(hostname)
0264               %-----------------------------------------------------
0265               %--- Construct from repository
0266               %-----------------------------------------------------
0267               % do hostname constructor
0268               obj = fromRepository(obj, pl, VERSION, ALGONAME);
0269 
0270             elseif ~isempty(pl_epoch_milli)
0271               %-----------------------------------------------------
0272               %--- Construct from millisecs time definition
0273               %-----------------------------------------------------
0274               obj = fromTimeValue(obj, pl);
0275 
0276             elseif ~isempty(pl_time_str)
0277               %-----------------------------------------------------
0278               %--- Construct from string time definition
0279               %-----------------------------------------------------
0280               obj = fromTimeString(obj, pl);
0281 
0282             elseif ~isempty(ipl)
0283               %-----------------------------------------------------
0284               %--- Construct from plist
0285               %-----------------------------------------------------
0286 
0287               % if the plist is empty, we return the default time object
0288               if nparams(ipl) == 0
0289                 % default time object
0290               else
0291                 % do plist constructor
0292                 obj = time(ipl);
0293               end
0294 
0295             else
0296               %-----------------------------------------------------
0297               %--- ERROR
0298               %-----------------------------------------------------
0299 
0300               %%% if the plist is empty then return the default time object
0301               if nparams(pl) == 0
0302                 % default time object
0303               else
0304                 error('### Unknown TIME constructor method.');
0305               end
0306             end
0307 
0308           else
0309             error('### Unknown single argument constructor.');
0310           end
0311 
0312         case 2
0313           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0314           %%%%%%%%%%%%%%%%%%%%%%%%%%%   two input   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0315           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0316 
0317           if isnumeric(varargin{1}) && ischar(varargin{2})
0318             %%%%%%%%%%   t1 = time(2000, 'HH:MM:SS')   %%%%%%%%%%
0319             obj.setEpochtime(varargin{1});
0320             obj.setTimeformat(varargin{2});
0321 
0322           elseif ischar(varargin{1}) && ischar(varargin{2})
0323             %%%%%%%%%%   t1 = time('14:00:00', 'HH:MM:SS')   %%%%%%%%%%
0324             obj.setTime_str(varargin{1});
0325             obj.setTimeformat(varargin{2});
0326 
0327           else
0328             error('### Unknown constructor with two inputs.');
0329           end
0330 
0331         otherwise
0332           error('### Unknown number of constructor arguments.');
0333       end % End switch over input args
0334     end % End time()
0335   end % End constructor
0336 
0337   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0338   %                              Methods  (Public)                            %
0339   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0340 
0341   methods
0342     varargout = copy(varargin)
0343     varargout = format(varargin)
0344     varargout = getTimezones(varargin)
0345     varargout = minus(varargin)
0346     varargout = plus(varargin)
0347     varargout = string(varargin)
0348 
0349     varargout = setEpochtime(varargin)
0350     varargout = setTimezone(varargin)
0351     varargout = setTimeformat(varargin)
0352     varargout = setTime_str(varargin)
0353   end % End public methods
0354 
0355 
0356   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0357   %                              Methods (protected)                          %
0358   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0359 
0360   methods (Access = protected)
0361   end
0362 
0363   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0364   %                               Methods (private)                           %
0365   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0366 
0367   methods (Access = private)
0368     varargout = fromTimeValue(varargin)
0369     varargout = fromTimeString(varargin)
0370   end
0371   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0372   %                            Methods (static)                               %
0373   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0374   methods (Static)
0375 
0376     varargout = update_struct(varargin);
0377 
0378     function ii = getInfo(varargin)
0379       ii = utils.helper.generic_getInfo(varargin{:}, 'time');
0380     end
0381 
0382     function out = VEROUT()
0383       out = '$Id: time.m,v 1.54 2008/08/11 07:25:40 hewitson Exp $';
0384     end
0385 
0386     function out = SETS()
0387       out = {...
0388         'From Repository', ...
0389         'From Time Definition', ...
0390         'From Time String', ...
0391         'From Plist'};
0392     end
0393 
0394     function out = getDefaultPlist(set)
0395 
0396       switch set
0397         case 'From Repository'
0398           %--- Repository constructor
0399           out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []);
0400         case 'From Time Definition'
0401           %--- Definition constructor
0402           out = plist(...
0403             'utc_epoch_milli',  0, ...
0404             'timezone',        'UTC', ...
0405             'timeformat',      'yyyy-mm-dd HH:MM:SS.FFF');
0406         case 'From Time String'
0407           %--- String constructor
0408           out = plist(...
0409             'time_str', '1970-01-01 00:00:00.000', ...
0410             'timezone',   'UTC', ...
0411             'timeformat', 'yyyy-mm-dd HH:MM:SS.FFF');
0412           %--- Create from a plist
0413         case 'From Plist'
0414           out = plist('Plist', []);
0415         otherwise
0416           error('### Unknown set [%s] to get the default plist.', set);
0417       end
0418     end % End getDefaultPlist
0419 
0420   end % End static methods
0421 
0422   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0423   %                         Methods (static, private)                         %
0424   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0425 
0426   methods (Static, Access=private)
0427 
0428     varargout = parse_time_string(varargin)
0429     [time_str, created_str] = epoch2str(tt)
0430 
0431   end % End static, private methods
0432 end % End classdef
0433 
0434

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003