Modul:TwitterSnowflake: Unterschied zwischen den Versionen
(fix weird edge case with 574608900537761792 returning a date of April 11, 2011) |
(add function to determine if date matches) |
||
Zeile 1: | Zeile 1: | ||
local p = {}; | local p = {}; | ||
local Date = require('Module:Date')._Date | |||
p.snowflakeToDate = function (frame) | p.snowflakeToDate = function (frame) | ||
Zeile 20: | Zeile 22: | ||
local timestamp = math.floor((hi * 1024 + math.floor(lo / 4194304)) / 1000) + epoch | local timestamp = math.floor((hi * 1024 + math.floor(lo / 4194304)) / 1000) + epoch | ||
return os.date(format, timestamp) | return os.date(format, timestamp) | ||
end | |||
p.getDate = function (frame) | |||
-- just pass frame directly to snowflakeToDate, this wraps it but the args are the same plus | |||
frame.args["format"] = "%B %e, %Y" | |||
frame.args["epoch"] = tonumber(frame.args["epoch"]) or 1288834974 | |||
epochdate = Date(os.date("%B %e, %Y", frame.args["epoch"])) | |||
twitterdate = Date(p.snowflakeToDate(frame)) | |||
if twitterdate == epochdate then -- created before epoch, so can't determine the date | |||
return -1 | |||
end | |||
return Date(frame.args["date"]) - twitterdate | |||
end | end | ||
return p | return p |