VOOZH about

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

⇱ Module:DateFormat – Minecraft Wiki


Module:DateFormat

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={}
localmonths={"january","february","march","april","may","june","july","august","september","october","november","december"}
localfunctionsplit(inputstr,sep)
ifsep==nilthensep="%s"end
localt={}
forstrinstring.gmatch(inputstr,"([^"..sep.."]+)")do
table.insert(t,str)
end
returnt
end
localfunctionparseDateTable(date)
locald=split(date:gsub('%sof%s','-'),"-")-- "01 of december of 2023"
if#d<2and#split(date:gsub('%s','-'),"-")<4then
d=split(date:gsub('%s','-'),"-")-- "01 december 2023"
end
if#d<2and#split(date:gsub('-','-'),"-")<4then
d=split(date:gsub('-','-'),"-")-- "01-12-2023"
end
if#d<2and#split(date:gsub('/','-'),"-")<4then
d=split(date:gsub('/','-'),"-")-- "01/12/2023"
end
returnd
end
localfunctionformatDate(d,skipTime)
localday,month,year,hour,minute,timeStr,isUTC=nil,nil,nil,nil,nil,nil,false
if#d==2then
month=d[1]:lower()
year=d[2]:match("%d[%d.,]*")
fori,vinpairs(months)do
ifv==monththenmonth=ibreakend
end
elseif#d==3then
ifsplit(d[3]:gsub('%sat%s','-'),"-")[2]then
timeStr=split(d[3]:gsub('%sat%s','-'),"-")[2]
end
day=d[1]:match("%d[%d.,]*")
month=d[2]:lower()
year=d[3]:match("%d[%d.,]*")
fori,vinpairs(months)do
ifv==monththenmonth=ibreakend
end
elseif#d==4then
timeStr=d[1]
day=d[2]:match("%d[%d.,]*")
month=d[3]:lower()
year=string.match(d[4],'%d[%d.,]*')
fori,vinpairs(months)do
ifv==monththenmonth=ibreakend
end
end
ifnotskipTimeandtimeStrthen
localh,m
iftimeStr:match("(.+)h(.+)")then
h,m=timeStr:match("(.+)h(.+)")
elseiftimeStr:match("(.+):(.+)")then
h,m=timeStr:match("(.+):(.+)")
end
iftimeStr:match("UTC")thenisUTC=trueend
ifhandmthen
hour=h:match("%d[%d.,]*")
minute=string.format("%02d",m:match("%d[%d.,]*"))
end
end
ifnotmonthornotyearthen
error('Invalid date format: '..tostring(data))
returnnil
end
localformatted=year.."-"..month
ifdaythen
formatted=formatted.."-"..day
ifhourthen
formatted=formatted.."T"..hour
ifminutethen
formatted=formatted..":"..minute
ifisUTCthen
formatted=formatted.." - 3 hours"-- UTC-3 (Brasília Time)
end
end
end
end
returnformatted
end
functionp.format(frame,asTemplate)
localmwFrame=mw.getCurrentFrame()
localargs=frame.args
localdate=args[1]
localskipTime=args[2]
ifdatethen
locald=parseDateTable(date)
localallNumeric=true
for_,vinipairs(d)do
ifnottonumber(v)thenallNumeric=falsebreakend
end
localformatted=date
ifallNumericthenformatted=formatDate(d,skipTime)end
localparser=mwFrame:callParserFunction('#time','Y-m-d H:i:s',formatted)
ifnotstring.find(parser,'error')then
returnparser
else
formatted=formatDate(d,skipTime)
localfallback=mwFrame:callParserFunction('#time','Y-m-d H:i:s',formatted)
ifnotstring.find(fallback,'error')then
returnfallback
end
end
ifasTemplate==truethen
ifmonthandmonths[tonumber(month)]then
returnday,months[tonumber(month)],year
end
else
ifparserthenreturnparser
elseerror('Invalid date format: '..tostring(date))end
end
end
end
functionp.formatTemplate(frame)
localmwFrame=mw.getCurrentFrame()
localargs=frame.args
localdate=args[1]
localparsed=formatDate(parseDateTable(date),true)
localparts=split(parsed,'-')
localy,m,d=parts[1],parts[2],parts[3]
ifnotmornotythen
return"<strong class=\"error\">Error: Invalid date format - \""..tostring(date).."\"</strong>"
else
ifdthen
returnmwFrame:callParserFunction('#time','F j, Y',parsed,'en')
else
returnmwFrame:callParserFunction('#time','F Y',parsed,'en')
end
end
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:DateFormat?oldid=3052867"

Navigation menu