update from sandbox per Module talk:Date#Month abbreviations: when parsing a date, remove '.' from month names so 'Feb.' => 'Feb'
 
m 1 revision imported from wikipedia:Module:Date
 
(2 intermediate revisions by 2 users not shown)
Line 695: Line 695:
end
end


-- A table to get the current date/time (UTC), but only if needed.
-- Cache the current date/time (UTC).
local current = setmetatable({}, {
--
__index = function (self, key)
-- Note that os.date() returns an empty object with optimized lazy getters for each field.
local d = os.date('!*t')
-- Avoid current.min or current.sec in articles! https://phabricator.wikimedia.org/T416616
self.year = d.year
--
self.month = d.month
-- Beware that while os.date() uses 'min' and 'sec', our Date() uses 'minute' and 'second'.
self.day = d.day
local current = os.date('!*t')
self.hour = d.hour
self.minute = d.min
self.second = d.sec
return rawget(self, key)
end })


local function extract_date(newdate, text)
local function extract_date(newdate, text)
Line 1,295: Line 1,290:
if argtype == 'currentdatetime' then
if argtype == 'currentdatetime' then
newdate.hour = current.hour
newdate.hour = current.hour
newdate.minute = current.minute
newdate.minute = current.min
newdate.second = current.second
newdate.second = current.sec
newdate.hastime = true
newdate.hastime = true
end
end