Module:Time/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 336:
end
 
--[[--------------------------< D S T _ A C T I V E >----------------------------------------------------------
 
Return 1 of dst is active or 0 if it's not
 
]]
 
local function dst_active (frame)
local args = getArgs (frame);
return _dst_active (args)
end
local function _dst_active (frame)
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
dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp); -- get begin and end dst timestamps and invert flag
if nil == dst_begin_ts or nil == dst_end_ts then
return error_msg ('bad_dst');
end
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?
tz_abbrreturn 0 = tz.abbr; -- standard time abbreviation
else
timestamp = timestamp + 3600; -- add an hour
tz_abbrreturn = tz.dst_abbr;1 -- dst abbreviation
end
else -- northern hemisphere
if utc_timestamp >= dst_begin_ts and utc_timestamp < dst_end_ts then -- all timestamps are UTC
timestamp = timestamp + 3600; -- add an hour
return 1
else
return 0
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 ('bad_def', args[1]:upper());
else
return 0 -- dst not observed for this timezone
end
end
--[=[-------------------------< T I M E >----------------------------------------------------------------------
 
Line 365 ⟶ 405:
local invert; -- true when southern hemisphere
local DF; -- date format flag; the |df= parameter
local is_dst = tonumber(dst_active(frame))
local data = 'Module:Time/data'..set_sandbox(frame) -- make a data module name; sandbox or live
Line 371 ⟶ 412:
local formats = data.formats;
local tz_aliases = {}
local aliases_table = data.tz_aliases; -- get the aliases table
local dst_table = data.dst_tz;
local tz_data = data.tz_data; -- get the tz data table
 
for k,v in pairs(dst_table) do -- add dst offsets to tz_aliases
tz_aliases[k] = v
end
for k,v in pairs(aliases_table) do -- add dst offsets to tz_aliases
tz_aliases[k] = v
end
local Timeonly = 'yes' == first_set (cfg.aliases['timeonly'], args); -- boolean
Line 439 ⟶ 478:
tz_abbr = tz.dst_abbr; -- dst abbreviation
else
if is_dst ~= 0 and is_dst ~= 1 then
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
return is_dst
dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp); -- get begin and end dst timestamps and invert flag
elseif dst == 0 then
 
timestamp = timestamp + 3600;
if nil == dst_begin_ts or nil == dst_end_ts then
tz_abbr = tz.dst_abbr;
return error_msg ('bad_dst');
end
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?
tz_abbr = tz.abbr; -- standard time abbreviation
else
timestamp = timestamp + 3600; -- add an hour
tz_abbr = tz.dst_abbr; -- dst abbreviation
end
else -- northern hemisphere
if utc_timestamp >= dst_begin_ts and utc_timestamp < dst_end_ts then -- all timestamps are UTC
timestamp = timestamp + 3600; -- add an hour
tz_abbr = tz.dst_abbr;
else
tz_abbr = tz.abbr;
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 ('bad_def', args[1]:upper());
else
tz_abbr = tz.abbr; -- dst not observed for this timezone
end
end