Content deleted Content added
BrandonXLF (talk | contribs) |
BrandonXLF (talk | contribs) →Template-protected edit request on 9 August 2018: new section |
||
Line 116:
::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 10:33, 9 August 2018 (UTC)
:::{{ping|Trappist the monk}} I'll figure something out. — [[User:BrandonXLF|<span style="outline: 3px double blue;color:lightcyan;background-color:black;'> '''''BrandonXLF''''' </span>]] [[User talk:BrandonXLF|<sup>(t@lk)</sup>]] <span style="color:black"><sup>([[Template:Ping|ping back]])</sup></span> 14:27, 9 August 2018 (UTC)
== Template-protected edit request on 9 August 2018 ==
{{edit template-protected|Module:Time|answered=no}}
replace p.time with
<syntaxhighlight lang=Lua>
function p.time (frame)
local args = getArgs(frame);
local utc_timestamp, timestamp; -- current or _TEST_TIME_ timestamps; timestamp is local ST or DST time used in output
local dst_begin_ts, dst_end_ts; -- DST begin and end timestamps in UTC
local tz_abbr; -- select ST or DST timezone abbreviaion used in output
local tz_string; -- output time in |df= format
local utc_offset;
local invert; -- true when southern hemisphere
local df; -- date format flag; the |df= parameter
local hf; -- hour format flag; derived from the |df=dmy12 and |df=mdy12 parameters
local timeonly;
local dateonly;
if args[1] then
args[1] = args[1]:lower(); -- make lower case because tz table member indexes are lower case
if mw.ustring.match (args[1], 'utc[%+%-±−]?%d%d:%d%d') then -- if rendering time for a UTC offset timezone
tz['utc_offsets'].abbr = args[1]:upper():gsub('%-', '−'); -- set the link label to upper case and replace hyphen with a minus character (U+2212)
tz['utc_offsets'].article = tz['utc_offsets'].abbr; -- article title same as abbreviation
tz['utc_offsets'].utc_offset = mw.ustring.match (args[1], 'utc([%+%-±−]?%d%d:%d%d)'):gsub('−', '%-'); -- extract the offset value; replace minus character with hyphen
args[1] = 'utc_offsets'; -- point to the generic utc offsets table
end
if not is_set (tz[args[1]]) then
return '<span style="font-size:100%" class="error">{{time}} – unknown timezone ([[Template:Time#Error messages|help]])</span>';
end
else
args[1] = 'utc'; -- default to utc
end
timeonly = args.timeonly;
dateonly = args.dateonly;
df = args.df or args[2] or tz[args[1]].df or ''; -- template |df= overrides typical df from tz properties TODO: error check these values?
if is_set (df) then
df = df:lower(); -- lower case because we will compare to lower case values later
end
hf = df:match ('%l%ly(12)'); -- hf == '12' selects 12-hour AM/PM display; other values ignored and 24 hour clock time displayed
if is_set (hf) then
df = df:match ('(%l%ly)12'); -- extract df
end
if is_set (args._TEST_TIME_) then -- typically used to test the code at a specific utc time
local test_time = get_test_time (args._TEST_TIME_);
if not test_time then
return '<span style="font-size:100%" class="error">{{time}} – malformed or incomplete _TEST_TIME_ ([[Template:Time#Error messages|help]])</span>';
end
-- utc_timestamp = os.time(get_test_time (args._TEST_TIME_));
utc_timestamp = os.time(test_time);
else
utc_timestamp = os.time (); -- get current server time (UTC)
end
utc_offset = get_utc_offset (args[1]); -- utc offset for specified timezone
timestamp = utc_timestamp + utc_offset; -- make local time timestamp
if 'no' == args.dst then -- for timezones that DO observe dst but for this ___location ...
tz_abbr = tz[args[1]].abbr; -- ... dst is not observed (|dst=no) show time as standard time
else
if is_set (tz[args[1]].dst_begins) and is_set (tz[args[1]].dst_ends) and is_set (tz[args[1]].dst_time) then -- make sure we have all of the parts
dst_begin_ts, dst_end_ts, invert = make_dst_timestamps (timestamp, args[1]); -- get begin and end dst timestamps and invert flag
if nil == dst_begin_ts or nil == dst_end_ts then
return '<span style="font-size:100%" class="error">{{time}} – error calculating dst timestamps ([[Template:Time#Error messages|help]])</span>';
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[args[1]].abbr; -- standard time abbreviation
else
timestamp = timestamp + 3600; -- add an hour for
tz_abbr = tz[args[1]].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[args[1]].dst_abbr;
else
tz_abbr = tz[args[1]].abbr;
end
end
elseif is_set (tz[args[1]].dst_begins) or is_set (tz[args[1]].dst_ends) or is_set (tz[args[1]].dst_time) then -- if some but not all not all parts then emit error message
return '<span style="font-size:100%" class="error">{{time}} – incomplete definition for ' .. args[1]:upper() .. ' ([[Template:Time#Error messages|help]])</span>';
else
tz_abbr = tz[args[1]].abbr; -- dst not observed for this timezone
end
end
if 'yes' == timeonly then
if '12' == hf then
tz_string = mw.text.trim (os.date ('%l:%M %p'));
else
tz_string = os.date ('%R');
end
elseif 'yes' == dateonly then
if 'dmy' == hf or 'y' == df then
tz_string = mw.text.trim (os.date ('%e %B %Y', timestamp));
else
tz_string = os.date ('%B %e %Y', timestamp);
end
else
if 'y' == df or 'dmy' == df then -- format the output (|df=y is legacy from original template)
if '12' == hf then
tz_string = mw.text.trim (os.date ('%l:%M %p, %e %B %Y', timestamp)); -- dmy, 12 hour am/pm
else
tz_string = os.date ('%R, %e %B %Y', timestamp); -- dmy
end
elseif 'iso' == df then
tz_string = os.date ('%FT%R', timestamp); -- iso
else
if '12' == hf then
tz_string = mw.text.trim (os.date ('%l:%M %p, %B %e, %Y', timestamp)); -- mdy (legacy default)
else
tz_string = os.date ('%R, %B %e, %Y', timestamp); -- mdy (legacy default)
end
end
end
if not is_set (tz[args[1]].article) then -- if some but not all not all parts then emit error message
return '<span style="font-size:100%" class="error">{{time}} – incomplete definition for ' .. args[1]:upper() .. ' ([[Template:Time#Error messages|help]])</span>';
end
local refreshLink = mw.title.getCurrentTitle():fullUrl{action = 'purge'} -- create a refresh link
return string.format ('%s [[%s|%s]] <span class="plainlinks" style="font-size:80%%;">[[%s refresh]]</span>', tz_string, tz[args[1]].article, tz_abbr, refreshLink);
end
</syntaxhighlight>
What it does is add parameters timeonly and dateonly, which allows the module to output the time or date of an timezone. This would be very helpful in the userspace and in some templates.
— [[User:BrandonXLF|<span style="outline: 3px double blue;color:lightcyan;background-color:black;'> '''''BrandonXLF''''' </span>]] [[User talk:BrandonXLF|<sup>(t@lk)</sup>]] <span style="color:black"><sup>([[Template:Ping|ping back]])</sup></span> 20:46, 9 August 2018 (UTC)
|