Latest revision |
Your text |
Line 307: |
Line 307: |
|
| |
|
| local function formatSurfaceTime(surfaceTime,format) | | local function formatSurfaceTime(surfaceTime,format) |
|
| |
|
| |
| format = format or "yyyy XX mmmm dd HH:MM:SS"
| |
|
| |
| result = format
| |
|
| |
| if (surfaceTime['year'] < 0) then
| |
| era = "BC"
| |
| sign = ""
| |
| else
| |
| era = "AD"
| |
| sign = "+"
| |
| end
| |
|
| |
| if (surfaceTime['hour'] > 11) then
| |
| hour12 = surfaceTime['hour'] - 12
| |
| ampm = "PM"
| |
| elseif (surfaceTime['hour'] == 0) then
| |
| hour12 = 12
| |
| ampm = "AM"
| |
| else
| |
| hour12 = surfaceTime['hour']
| |
| ampm = "AM"
| |
| end
| |
|
| |
| dateStr = string.format("%s%04d-%02d-%02dT00:00:00Z",sign,surfaceTime['year'],surfaceTime['month'],surfaceTime['day'])
| |
|
| |
| wday = Date(dateStr):text("%{dayname}")
| |
|
| |
| result = string.gsub(result,"%a+", {
| |
| ["yyyy"] = string.format("%04d",tostring(math.abs(surfaceTime['year']))),
| |
| ["yy"] = string.format("%02d",tostring(math.abs(surfaceTime['year']))),
| |
| ["y"] = tostring(math.abs(surfaceTime['year'])),
| |
| ["YYYY"] = string.format("%04d",tostring(surfaceTime['year'])),
| |
| ["YY"] = string.format("%02d",tostring(surfaceTime['year'])),
| |
| ["Y"] = tostring(surfaceTime['year']),
| |
| ["mmmm"] = months[surfaceTime['month']],
| |
| ["mmm"] = string.sub(months[surfaceTime['month']],1,3),
| |
| ["mm"] = string.format("%02d",tostring(surfaceTime['month'])),
| |
| ["m"] = tostring(surfaceTime['month']),
| |
| ["dddd"] = wday,
| |
| ["ddd"] = string.sub(wday,1,3),
| |
| ["dd"] = string.format("%02d",tostring(surfaceTime['day'])),
| |
| ["d"] = tostring(surfaceTime['day']),
| |
| ["HH"] = string.format("%02d",tostring(surfaceTime['hour'])),
| |
| ["hh"] = string.format("%02d",tostring(hour12)),
| |
| ["H"] = tostring(surfaceTime['hour']),
| |
| ["h"] = tostring(hour12),
| |
| ["MM"] = string.format("%02d",tostring(surfaceTime['min'])),
| |
| ["M"] = tostring(surfaceTime['min']),
| |
| ["SS"] = string.format("%02d",tostring(surfaceTime['sec'])),
| |
| ["S"] = tostring(surfaceTime['hour']),
| |
| ["tt"] = ampm,
| |
| ["t"] = string.sub(ampm,1,1),
| |
| ["XX"] = era
| |
| })
| |
|
| |
| return result
| |
|
| |
| end
| |
|
| |
|
| |
| local function formatSurfaceTime_old(surfaceTime,format)
| |
|
| |
|
| format = format or '%-Y-%m-%d %{era} %H:%M:%S' | | format = format or '%-Y-%m-%d %{era} %H:%M:%S' |
|
| |
|
| dateStr = string.format("%04d-%02d-%02d",surfaceTime['year'],surfaceTime['month'],surfaceTime['day'],surfaceTime['hour'],surfaceTime['min'],surfaceTime['sec']) | | dateStr = tostring(surfaceTime['year']).."-"..tostring(surfaceTime['month']).."-"..tostring(surfaceTime['day']).."T"..tostring(surfaceTime['hour'])..":"..tostring(surfaceTime['min'])..":"..tostring(surfaceTime['sec']).."Z" |
| | | |
| if surfaceTime['year'] > 0 then dateStr = "+"..dateStr end | | if dateStr:sub(1) ~= '-' then dateStr = "+"..dateStr end |
|
| |
|
| return Date(dateStr):text(format) | | return Date(dateStr):text(format) |