Editing Module:D'ni Time/surface

From Guild of Archivists
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

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 = string.format("%04d-%02d-%02dT%02d:%02d:%02dZ",surfaceTime['year'],surfaceTime['month'],surfaceTime['day'],surfaceTime['hour'],surfaceTime['min'],surfaceTime['sec'])
    
    
   if surfaceTime['year'] > 0 then dateStr = "+"..dateStr end
   if dateStr:sub(1) ~= '-' then dateStr = "+"..dateStr end
 
return dateStr
  return Date(dateStr):text(format)
--  return Date(dateStr):text(format)


end
end
Please note that all contributions to Guild of Archivists may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see GoArch:Copyrights for details). Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: