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.4 2008/09/04 15:29:31 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.4 2008/09/04 15:29:31 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     elseif ischar(timeformat{1})
0084       objs(ii).timeformat = timeformat{1};
0085     else
0086       error('### Timeformat must be a string');
0087     end
0088   end
0089 
0090   %%% Prepare output
0091   varargout{1} = objs;
0092 
0093 end
0094 
0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0096 %                               Local Functions                               %
0097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0098 
0099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0100 %
0101 % FUNCTION:    matlab_format2str
0102 %
0103 % DESCRIPTION: Convert the standard MATLAB Date format definitions into a string
0104 %
0105 % HISTORY:     11-07-07 M Diepholz
0106 %                Creation.
0107 %
0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0109 
0110 function val_str = matlab_format2str(val)
0111 
0112   switch val
0113     case 0
0114       val_str = 'dd-mmm-yyyy HH:MM:SS';
0115     case 1
0116       val_str = 'dd-mmm-yyyy';
0117     case 2
0118       val_str = 'mm/dd/yy';
0119     case 3
0120       val_str = 'mmm';
0121     case 4
0122       val_str = 'm';
0123     case 5
0124       val_str = 'mm';
0125     case 6
0126       val_str = 'mm/dd';
0127     case 7
0128       val_str = 'dd';
0129     case 8
0130       val_str = 'ddd';
0131     case 9
0132       val_str = 'd';
0133     case 10
0134       val_str = 'yyyy';
0135     case 11
0136       val_str = 'yy';
0137     case 12
0138       val_str = 'mmmyy';
0139     case 13
0140       val_str = 'HH:MM:SS';
0141     case 14
0142       val_str = 'HH:MM:SS PM';
0143     case 15
0144       val_str = 'HH:MM';
0145     case 16
0146       val_str = 'HH:MM PM';
0147     case 19
0148       val_str = 'dd/mm';
0149     case 20
0150       val_str = 'dd/mm/yy';
0151     case 21
0152       val_str = 'mmm.dd,yyyy HH:MM:SS';
0153     case 22
0154       val_str = 'mmm.dd,yyyy';
0155     case 23
0156       val_str = 'mm/dd/yyyy';
0157     case 24
0158       val_str = 'dd/mm/yyyy';
0159     case 25
0160       val_str = 'yy/mm/dd';
0161     case 26
0162       val_str = 'yyyy/mm/dd';
0163     case 28
0164       val_str = 'mmmyyyy';
0165     case 29
0166       val_str = 'yyyy-mm-dd';
0167     case 31
0168       val_str = 'yyyy-mm-dd HH:MM:SS';
0169     otherwise
0170       error('### The format number [%d] is not supported', val);
0171   end
0172 end
0173 
0174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0175 %
0176 % FUNCTION:    getInfo
0177 %
0178 % DESCRIPTION: Get Info Object
0179 %
0180 % HISTORY:     11-07-07 M Hewitson
0181 %                Creation.
0182 %
0183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0184 
0185 function ii = getInfo(varargin)
0186   if nargin == 1 && strcmpi(varargin{1}, 'None')
0187     sets = {};
0188     pl   = [];
0189   else
0190     sets = {'Default'};
0191     pl   = getDefaultPlist;
0192   end
0193   % Build info object
0194   ii = minfo(mfilename, 'time', '', utils.const.categories.internal, '$Id: setTimeformat.m,v 1.4 2008/09/04 15:29:31 ingo Exp $', sets, pl);
0195 end
0196 
0197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0198 %
0199 % FUNCTION:    getDefaultPlist
0200 %
0201 % DESCRIPTION: Get Default Plist
0202 %
0203 % HISTORY:     11-07-07 M Hewitson
0204 %                Creation.
0205 %
0206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0207 
0208 function plo = getDefaultPlist()
0209   plo = plist('timeformat', '');
0210 end
0211

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003