Module:Time/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 528:
mimics templates {{Time/GMT offset}}, {{Time/EST offset}}, etc.
 
{{#invoke:Time/sandbox|tz_offsetutc_offset|<tz>}} – for a stand-alone invoke
{{#invoke:Time/sandbox|tz_offsetutc_offset}} – for an invoke in a template (<tz> is first positional parameter in the template call)
 
where <tz> is a timezone abbreviation known to Module:Time/data
 
returns a UTC offset string suitable for use with the {{#time:}} parser function:
{{#time:H:i | {{#invoke:Time/sandbox|tz_offsetutc_offset|MST}} }}
{{#time:H:i | {{UTC_offset|MST}} }}
 
Line 564:
local utc_offset;
 
local DST = first_set (cfg.aliases['dst'], args_t) or true; -- string 'always' or boolean
if is_set (tz.dst_begins) and is_set (tz.dst_ends) and is_set (tz.dst_time) then -- make sure we have all of the parts
if 'always' == DST then -- if needed to always display dst time
local dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp); -- get begin and end dst timestamps and <invert> flag
utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
 
elseif not yesno (DST) then -- for timezones that DO observe dst but for this ___location ...
if nil == dst_begin_ts or nil == dst_end_ts then -- if either of these are nil
utc_offset = tz.utc_offset; -- return... timezone-offsetdst is not observed (|dst=no) show time as fromstandard utctime
return error_msg ({'UTC offset', cfg.err_text['bad_dst']}); -- abandon with error message
else
end
if is_set (tz.dst_begins) and is_set (tz.dst_ends) and is_set (tz.dst_time) then -- make sure we have all of the parts
 
local dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp); -- get begin and end dst timestamps and <invert> flag
if invert then -- southern hemisphere; use beginning and ending of standard time in the comparison
if utc_timestamp >= dst_end_ts and utc_timestamp < dst_begin_ts then -- is current date time standard time?
if nil == dst_begin_ts or nil == dst_end_ts then -- if either of these are nil
utc_offset = tz.utc_offset; -- return timezone-offset from utc
return error_msg ({'UTC offset', cfg.err_text['bad_dst']}); -- abandon with error message
else
utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
end
else -- northern hemisphere
if invert then -- southern hemisphere; use beginning and ending of standard time in the comparison
if utc_timestamp >= dst_begin_ts and utc_timestamp < dst_end_ts then -- is current date time daylight time?
if utc_timestamp >= dst_end_ts and utc_timestamp < dst_begin_ts then -- is current date time standard time?
utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
utc_offset = tz.utc_offset; -- return timezone-offset from utc
else
else
utc_offset = tz.utc_offset; -- return timezone-offset from utc
utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
end
else else -- northern hemisphere
if utc_timestamp >= dst_begin_ts and utc_timestamp < dst_end_ts then -- is current date time daylight time?
utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
else
utc_offset = tz.utc_offset; -- return timezone-offset from utc
end
end
elseif is_set (tz.dst_begins) or is_set (tz.dst_ends) or is_set (tz.dst_time) then -- if some but not all not all parts then emit error message
return error_msg ({'UTC offset', substitute (cfg.err_text['bad_def'], args_t[1]:upper())});
else -- timezone does not use dst
utc_offset = tz.utc_offset; -- return timezone-offset from utc
end
 
elseif is_set (tz.dst_begins) or is_set (tz.dst_ends) or is_set (tz.dst_time) then -- if some but not all not all parts then emit error message
return error_msg ({'UTC offset', substitute (cfg.err_text['bad_def'], args_t[1]:upper())});
 
else -- timezone does not use dst
utc_offset = tz.utc_offset; -- return timezone-offset from utc
end