Content deleted Content added
No edit summary |
No edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 522:
--[[--------------------------< U T
implements {{UTC offset}}
Mimics templates {{Time/GMT offset}}, {{Time/EST offset}}, etc.▼
{{#invoke:Time/sandbox|tz_offset|<tz>}} – for a stand-alone invoke▼
{{#invoke:Time/sandbox|tz_offset}} – for an invoke in a template (<tz> is first positional parameter in the template call)▼
▲ {{#invoke:Time
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|utc_offset|MST}} }}
{{#time:H:i | {{UTC_offset|MST}} }}
]]
local function
local function apply_dst_ajdust (offset) -- local function to adjust standard time to daylight time; called when adjustment is needed
local hours, minutes = offset:match ('^(%-?%d%d):(%d%d)'); -- extract signed hours and minutes from specified offset
Line 560 ⟶ 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▼
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▼
return error_msg ({'UTC offset', cfg.err_text['bad_dst']}); -- abandon with error message▼
end▼
▲
▲ 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?▼
▲ utc_offset = tz.utc_offset; -- return timezone-offset from utc
else ▼
▲ utc_offset = apply_dst_ajdust (tz.utc_offset); -- return dst-adjusted timezone-offset from utc
end
else -- northern hemisphere▼
▲ if invert then
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▼
▲ else
▲ else
▲ utc_offset = tz.utc_offset; -- return timezone-offset from utc
▲ end
▲ if utc_timestamp >= dst_begin_ts and utc_timestamp < dst_end_ts then -- is current date time daylight time?
else
utc_offset = tz.utc_offset; -- return timezone-offset from utc
end
end
return error_msg ({'UTC offset', substitute (cfg.err_text['bad_def'], args_t[1]:upper())});▼
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
Line 606 ⟶ 617:
return {
time = time,
utc_offset = utc_offset,
}
|