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 280: Line 280:
   end
   end
   return t, dout
   return t, dout
end
local function preprocessSingleArg(argName)
    -- If the argument exists and isn't blank, add it to the argument table.
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
    if origArgs[argName] and origArgs[argName] ~= '' then
        args[argName] = origArgs[argName]
    end
end
end
   
   
local function parseSurfaceDate(s,fmt)
function parseSurfaceDate(s,fmt)


   if type(s) ~= 'string' or s == '' or s == 'NULL' then
   if type(s) ~= 'string' or s == '' or s == 'NULL' then
Line 304: Line 313:
   error('"'..s..'" does not match:\n'..
   error('"'..s..'" does not match:\n'..
         table.concat(all_errors, '\n'), 2)
         table.concat(all_errors, '\n'), 2)
end
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'
  dateStr = string.format("%04d-%02d-%02d",surfaceTime['year'],surfaceTime['month'],surfaceTime['day'],surfaceTime['hour'],surfaceTime['min'],surfaceTime['sec'])
 
  if surfaceTime['year'] > 0 then dateStr = "+"..dateStr end
  return Date(dateStr):text(format)
end
end


Line 390: Line 324:
   d, dout = parseSurfaceDate(s,fmt)
   d, dout = parseSurfaceDate(s,fmt)
   return dout
   return dout
end
function p.formatSurfaceTime(surfaceTime,format)
  return formatSurfaceTime(surfaceTime,format)
end
end


return p
return p
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: