Home > classes > @time > setTimezone.m

setTimezone

PURPOSE ^

SETTIMEZONE Set the property 'timezone'.

SYNOPSIS ^

function varargout = setTimezone(varargin)

DESCRIPTION ^

 SETTIMEZONE Set the property 'timezone'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: Set the property 'timezone'.

 CALL:        obj = obj.setTimezone('new timezone');
              obj = obj.setTimezone(plist('timezone', 'new timezone'));
              obj = setTimezone(obj, 'new timezone');

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

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

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

 VERSION:     $Id: setTimezone.m,v 1.3 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 % SETTIMEZONE Set the property 'timezone'.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: Set the property 'timezone'.
0005 %
0006 % CALL:        obj = obj.setTimezone('new timezone');
0007 %              obj = obj.setTimezone(plist('timezone', 'new timezone'));
0008 %              obj = setTimezone(obj, 'new timezone');
0009 %
0010 % INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
0011 %              pl  - to set the timezone with a plist specify only one plist with
0012 %                    only one key-word 'timezone'.
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> time.getInfo('setTimezone')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> time.getInfo('setTimezone', 'set')
0019 %
0020 % VERSION:     $Id: setTimezone.m,v 1.3 2008/09/04 15:29:31 ingo Exp $
0021 %
0022 % HISTORY:     27-05-2008 Diepholz
0023 %                 Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = setTimezone(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     available_IDs = cell(java.util.TimeZone.getAvailableIDs);
0042     if ischar(varargin{2}) && ismember(varargin{2}, available_IDs)
0043       varargin{1}.timezone = java.util.TimeZone.getTimeZone(varargin{2});
0044     elseif ischar(varargin{2})
0045       error('### Unknown timezone [%s]', varargin{2});
0046     else
0047       varargin{1}.timezone = varargin{2};
0048     end
0049     varargout{1} = varargin{1};
0050     return
0051   end
0052 
0053   %%% Normal call:
0054   [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'time');
0055   [pls,  invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
0056 
0057   timezone = rest;
0058 
0059   if length(timezone) ~=1
0060 
0061     if length(pls) == 1
0062       timezone = {};
0063       if nparams(pls) == 1 && isparam(pls, 'timezone')
0064 
0065         %%% If the plist contains only one parameter with the key-word 'timezone'
0066         %%% then set 'timezone' to the value in the time object.
0067         timezone{1} = find(pls, 'timezone');
0068 
0069       else
0070         timezone{1} = pls;
0071       end
0072     elseif length(pls) > 1
0073       error('### To set the ''timezone'' please specify only one plist')
0074     else
0075       error('### Please specify [only one] value.')
0076     end
0077   end
0078 
0079   %%% Set the timezone
0080   available_IDs = cell(java.util.TimeZone.getAvailableIDs);
0081   if ischar(timezone{1}) && ismember(timezone{1}, available_IDs)
0082     timezone = java.util.TimeZone.getTimeZone(timezone{1});
0083   elseif ischar(timezone{1})
0084     error('### Unknown timezone [%s]', timezone{1});
0085   else
0086     timezone = timezone{1};
0087   end
0088 
0089   for ii = 1:numel(objs)
0090     %%% decide whether we modify the time-object, or create a new one.
0091     objs(ii) = copy(objs(ii), nargout);
0092     objs(ii).timezone = timezone;
0093   end
0094 
0095   %%% Prepare output
0096   varargout{1} = objs;
0097 
0098 end
0099 
0100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0101 %                               Local Functions                               %
0102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0103 
0104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0105 %
0106 % FUNCTION:    getInfo
0107 %
0108 % DESCRIPTION: Get Info Object
0109 %
0110 % HISTORY:     11-07-07 M Hewitson
0111 %                Creation.
0112 %
0113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0114 
0115 function ii = getInfo(varargin)
0116   if nargin == 1 && strcmpi(varargin{1}, 'None')
0117     sets = {};
0118     pl   = [];
0119   else
0120     sets = {'Default'};
0121     pl   = getDefaultPlist;
0122   end
0123   % Build info object
0124   ii = minfo(mfilename, 'time', '', utils.const.categories.internal, '$Id: setTimezone.m,v 1.3 2008/09/04 15:29:31 ingo Exp $', sets, pl);
0125 end
0126 
0127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0128 %
0129 % FUNCTION:    getDefaultPlist
0130 %
0131 % DESCRIPTION: Get Default Plist
0132 %
0133 % HISTORY:     11-07-07 M Hewitson
0134 %                Creation.
0135 %
0136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0137 
0138 function plo = getDefaultPlist()
0139   plo = plist('timezone', '');
0140 end
0141

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