Home > classes > @time > setTimeformat.m

setTimeformat

PURPOSE ^

SETTIMEFORMAT Set the property 'timeformat'.

SYNOPSIS ^

function varargout = setTimeformat(varargin)

DESCRIPTION ^

 SETTIMEFORMAT Set the property 'timeformat'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: Set the property 'timeformat'.

 CALL:        obj = obj.setTimeformat('new timeformat');
              obj = obj.setTimeformat(plist('timeformat', 'new timeformat'));
              obj = setTimeformat(obj, 'new timeformat');

 INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
              pl  - to set the timeformat with a plist specify only one plist with
                    only one key-word 'timeformat'.

 M-FILE INFO: Get information about this methods by calling
              >> time.getInfo('setTimeformat')

              Get information about a specified set-plist by calling:
              >> time.getInfo('setTimeformat', 'set')

 VERSION:     $Id: setTimeformat.m,v 1.2 2008/07/11 15:16:45 ingo Exp $

 HISTORY:     27-05-2008 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % SETTIMEFORMAT Set the property 'timeformat'.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: Set the property 'timeformat'.
0005 %
0006 % CALL:        obj = obj.setTimeformat('new timeformat');
0007 %              obj = obj.setTimeformat(plist('timeformat', 'new timeformat'));
0008 %              obj = setTimeformat(obj, 'new timeformat');
0009 %
0010 % INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
0011 %              pl  - to set the timeformat with a plist specify only one plist with
0012 %                    only one key-word 'timeformat'.
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> time.getInfo('setTimeformat')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> time.getInfo('setTimeformat', 'set')
0019 %
0020 % VERSION:     $Id: setTimeformat.m,v 1.2 2008/07/11 15:16:45 ingo Exp $
0021 %
0022 % HISTORY:     27-05-2008 Diepholz
0023 %                 Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = setTimeformat(varargin)
0028 
0029   %%% Check if this is a call for parameters
0030   if utils.helper.isinfocall(varargin{:})
0031     varargout{1} = getInfo(varargin{3});
0032     return
0033   end
0034 
0035   %%% Internal call: Only one object + don't look for a plist
0036   if strcmp(varargin{end}, 'internal')
0037 
0038     %%% decide whether we modify the time-object, or create a new one.
0039     varargin{1} = copy(varargin{1}, nargout);
0040 
0041     if isnumeric(varargin{2})
0042       varargin{1}.timeformat = matlab_format2str(varargin{2});
0043     else
0044       varargin{1}.timeformat = varargin{2};
0045     end
0046     varargout{1} = varargin{1};
0047     return
0048   end
0049 
0050   %%% Normal call:
0051   [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'time');
0052   [pls,  invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
0053 
0054   timeformat = rest;
0055 
0056   if length(timeformat) ~=1
0057 
0058     if length(pls) == 1
0059       timeformat = {};
0060       if nparams(pls) == 1 && isparam(pls, 'timeformat')
0061 
0062         %%% If the plist contains only one parameter with the key-word 'timeformat'
0063         %%% then set 'timeformat' to the value in the time object.
0064         timeformat{1} = find(pls, 'timeformat');
0065 
0066       else
0067         timeformat{1} = pls;
0068       end
0069     elseif length(pls) > 1
0070       error('### To set the ''timeformat'' please specify only one plist')
0071     else
0072       error('### Please specify [only one] value.')
0073     end
0074   end
0075 
0076   %%% Set the timeformat
0077   for ii = 1:numel(objs)
0078     %%% decide whether we modify the time-object, or create a new one.
0079     objs(ii) = copy(objs(ii), nargout);
0080 
0081     if isnumeric(timeformat{1})
0082       objs(ii).timeformat = matlab_format2str(timeformat{1});
0083     else
0084       objs(ii).timeformat = timeformat{1};
0085     end
0086   end
0087 
0088   %%% Prepare output
0089   varargout{1} = objs;
0090 
0091 end
0092 
0093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0094 %                               Local Functions                               %
0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0096 
0097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0098 %
0099 % FUNCTION:    matlab_format2str
0100 %
0101 % DESCRIPTION: Convert the standard MATLAB Date format definitions into a string
0102 %
0103 % HISTORY:     11-07-07 M Diepholz
0104 %                Creation.
0105 %
0106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0107 
0108 function val_str = matlab_format2str(val)
0109 
0110   switch val
0111     case 0
0112       val_str = 'dd-mmm-yyyy HH:MM:SS';
0113     case 1
0114       val_str = 'dd-mmm-yyyy';
0115     case 2
0116       val_str = 'mm/dd/yy';
0117     case 3
0118       val_str = 'mmm';
0119     case 4
0120       val_str = 'm';
0121     case 5
0122       val_str = 'mm';
0123     case 6
0124       val_str = 'mm/dd';
0125     case 7
0126       val_str = 'dd';
0127     case 8
0128       val_str = 'ddd';
0129     case 9
0130       val_str = 'd';
0131     case 10
0132       val_str = 'yyyy';
0133     case 11
0134       val_str = 'yy';
0135     case 12
0136       val_str = 'mmmyy';
0137     case 13
0138       val_str = 'HH:MM:SS';
0139     case 14
0140       val_str = 'HH:MM:SS PM';
0141     case 15
0142       val_str = 'HH:MM';
0143     case 16
0144       val_str = 'HH:MM PM';
0145     case 19
0146       val_str = 'dd/mm';
0147     case 20
0148       val_str = 'dd/mm/yy';
0149     case 21
0150       val_str = 'mmm.dd,yyyy HH:MM:SS';
0151     case 22
0152       val_str = 'mmm.dd,yyyy';
0153     case 23
0154       val_str = 'mm/dd/yyyy';
0155     case 24
0156       val_str = 'dd/mm/yyyy';
0157     case 25
0158       val_str = 'yy/mm/dd';
0159     case 26
0160       val_str = 'yyyy/mm/dd';
0161     case 28
0162       val_str = 'mmmyyyy';
0163     case 29
0164       val_str = 'yyyy-mm-dd';
0165     case 31
0166       val_str = 'yyyy-mm-dd HH:MM:SS';
0167     otherwise
0168       error('### The format number [%d] is not supported', val);
0169   end
0170 end
0171 
0172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0173 %
0174 % FUNCTION:    getInfo
0175 %
0176 % DESCRIPTION: Get Info Object
0177 %
0178 % HISTORY:     11-07-07 M Hewitson
0179 %                Creation.
0180 %
0181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0182 
0183 function ii = getInfo(varargin)
0184   if nargin == 1 && strcmpi(varargin{1}, 'None')
0185     sets = {};
0186     pl   = [];
0187   else
0188     sets = {'Default'};
0189     pl   = getDefaultPlist;
0190   end
0191   % Build info object
0192   ii = minfo(mfilename, 'time', '', 'Internal', '$Id: setTimeformat.m,v 1.2 2008/07/11 15:16:45 ingo Exp $', sets, pl);
0193 end
0194 
0195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0196 %
0197 % FUNCTION:    getDefaultPlist
0198 %
0199 % DESCRIPTION: Get Default Plist
0200 %
0201 % HISTORY:     11-07-07 M Hewitson
0202 %                Creation.
0203 %
0204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0205 
0206 function plo = getDefaultPlist()
0207   plo = plist('timeformat', '');
0208 end
0209

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