VOOZH about

URL: https://minecraft.wiki/w/Module:TwitterSnowflake

⇱ Module:TwitterSnowflake – Minecraft Wiki


Module:TwitterSnowflake

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[create] [purge]
This module has no documentation. If you know how to use this module, please create it.
localp={}
localDate=require('Module:Date')._Date
functionp.snowflakeToDate(frame)
localformat=frame.args.formator"%B %e, %Y"
localepoch=tonumber(frame.args.epoch)or1288834974
localid_str=frame.args.id_str
iftype(id_str)~="string"thenerror("bad argument #1 (expected string, got "..type(id_str)..")",2)end
iftype(format)~="string"thenerror("bad argument #2 (expected string, got "..type(format)..")",2)end
iftype(epoch)~="number"thenerror("bad argument #3 (expected number, got "..type(epoch)..")",2)end
localhi,lo=0,0
localhiexp=1
localtwo32=2^32
forcinid_str:gmatch(".")do
lo=lo*10+c
iflo>=two32then
hi,lo=hi*10^hiexp+math.floor(lo/two32),lo%two32
hiexp=1
elsehiexp=hiexp+1end
end
hi=hi*10^(hiexp-1)
localtimestamp=math.floor((hi*1024+math.floor(lo/4194304))/1000)+epoch
returnos.date(format,timestamp)
end
functionp.getDate(frame)
-- 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.epoch=tonumber(frame.args.epoch)or1288834974
localepochdate=Date(os.date("%B %e, %Y",frame.args.epoch))
localtwitterdate=Date(p.snowflakeToDate(frame))
iftwitterdate==epochdatethen-- created before epoch, so can't determine the date
return-1
end
localdate=Date(frame.args.date)or0-- if we error here, then an input of no date causes an error, which is contrary to the entire way {{TwitterSnowflake/datecheck}} works
returndate-twitterdate
end
localfunctionabs_datediff(x)
iftype(x)=='number'thenreturnmath.abs(x)end
returnmath.abs(x.age_days)
end
functionp.datecheck(frame)
localargs=frame.args
ifnot(args.dateandargs.id_str)then
error('Must define date and id_str, even if they are blank.')
end
localerrors={
args.error1or'Date mismatch of two or more days',
args.error2or'No date, and posted before November 4, 2010',
args.error3or'Invalid id_str'
}
ifmw.title.getCurrentTitle():inNamespace(0)andargs.error_catthen
fori=1,3doerrors[i]=errors[i]..'[['..args.error_cat..']]'end
end
ifnotargs.date:match('^%s*$')then-- #if:{{{date|}}}
localtestResult=p.getDate{args={date=args.date,id_str=args.id_str}}
iftestResult==-2thenreturnerrors[3]end
ifabs_datediff(testResult)>1thenreturnerrors[1]end
elseifnotargs.id_str:match('^%s*$')then
localtestResult=p.getDate{args={id_str=args.id_str}}
iftestResult==-1thenreturnerrors[2]end
iftestResult==-2thenreturnerrors[3]end
end
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:TwitterSnowflake?oldid=2929017"

Navigation menu