Modul:TwitterSnowflake: Unterschied zwischen den Versionen
copy from sandbox (all testcases match)
(use %B %e, %Y by default) |
(copy from sandbox (all testcases match)) |
||
Zeile 13: | Zeile 13: | ||
local hiexp = 1 | local hiexp = 1 | ||
for c in id_str:gmatch(".") do | for c in id_str:gmatch(".") do | ||
lo = lo * 10 + | lo = lo * 10 + c | ||
if lo >= 2^32 then | if lo >= 2^32 then | ||
hi, lo = hi * 10^hiexp + math.floor(lo / 2^32), lo % 2^32 | hi, lo = hi * 10^hiexp + math.floor(lo / 2^32), lo % 2^32 | ||
Zeile 26: | Zeile 26: | ||
function p.getDate(frame) | function p.getDate(frame) | ||
-- just pass frame directly to snowflakeToDate, this wraps it but the args are the same plus | -- just pass frame directly to snowflakeToDate, this wraps it but the args are the same plus | ||
if (frame.args.id_str):match("%D") then -- not a number, so return -2 | |||
return -2 | |||
end | |||
frame.args.format = "%B %e, %Y" | frame.args.format = "%B %e, %Y" | ||
frame.args.epoch = tonumber(frame.args.epoch) or 1288834974 | frame.args.epoch = tonumber(frame.args.epoch) or 1288834974 | ||
Zeile 33: | Zeile 36: | ||
return -1 | return -1 | ||
end | end | ||
local date = Date(frame.args.date) or error("cite tweet: invalid date", 0) | |||
return date - twitterdate | |||
end | end | ||
return p | return p |