Modul:DateTime: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
2015-03-16
(update) |
(2015-03-16) |
||
Zeile 1: | Zeile 1: | ||
--[=[ | --[=[ 2015-03-16 | ||
Date and time utilities | Date and time utilities | ||
]=] | ]=] | ||
Zeile 218: | Zeile 218: | ||
end | end | ||
elseif amount == 4 then | elseif amount == 4 then | ||
local s, sep, sx = analyse:match( "^(%d+)([%-%.: | local s, sep, sx = analyse:match( "^(%d+)([%-%.:Ww]?)(.*)$" ) | ||
r.year = tonumber( s ) | r.year = tonumber( s ) | ||
if sep == "-" then | if sep == "-" then | ||
Zeile 248: | Zeile 248: | ||
end | end | ||
elseif sep:lower() == "w" then | elseif sep:lower() == "w" then | ||
if | if sx then | ||
s = | s = sx:match( "^(%d%d?)$" ) | ||
if s then | if s then | ||
r.week = tonumber( s ) | r.week = tonumber( s ) | ||
if r.week < 1 or r.week > 53 then | |||
r = false | |||
end | |||
else | else | ||
r = false | r = false | ||
Zeile 396: | Zeile 399: | ||
return r | return r | ||
end -- Parser.european() | end -- Parser.european() | ||
Parser.isoDate = function ( analyse, assign ) | |||
-- String analysis, retrieve month heading ISO date | |||
-- Parameter: | |||
-- analyse -- string, with heading hyphen | |||
-- assign -- table | |||
-- Returns: | |||
-- 1 -- table, extended if parsed | |||
-- 2 -- stripped string, or false, if invalid text format | |||
local rO, rS | |||
if analyse:match( "^%-%-?[0-9]" ) then | |||
local n, s | |||
rO = assign | |||
rS = analyse:sub( 2 ) | |||
s = rS:match( "^([012][0-9])%-" ) | |||
if s then | |||
n = tonumber( s ) | |||
if n >= 1 and n <= 12 then | |||
rO.month = n | |||
rS = rS:sub( 3 ) | |||
else | |||
rO = false | |||
end | |||
end | |||
if rO then | |||
if rS:byte( 1, 1 ) == 45 then | |||
local suffix | |||
s = rS:match( "^%-([012][0-9])" ) | |||
if s then | |||
n = tonumber( s ) | |||
if n >= 1 and n <= 31 then | |||
rO.dom = n | |||
rS = rS:sub( 4 ) | |||
else | |||
rO = false | |||
end | |||
else | |||
rS:sub( 2 ) | |||
end | |||
else | |||
rO = false | |||
end | |||
if rO then | |||
if #rS > 0 then | |||
if rO.dom then | |||
n = rS:byte( 1, 1 ) | |||
if n == 32 or n == 84 then | |||
rS = rS:sub( 2 ) | |||
else | |||
rO = false | |||
end | |||
else | |||
rO = false | |||
end | |||
end | |||
end | |||
end | |||
else | |||
rO = false | |||
end | |||
if not rO then | |||
rS = false | |||
end | |||
return rO, rS | |||
end -- Parser.isoDate() | |||
Zeile 775: | Zeile 845: | ||
end | end | ||
else | else | ||
r, | local rM, sM = Parser.monthHeading( s, r ) | ||
if r and | if rM then | ||
r = Parser.time( | r = rM | ||
else | |||
r, sM = Parser.isoDate( s, r ) | |||
end | |||
if r and sM ~= "" then | |||
r = Parser.time( sM, r ) | |||
end | end | ||
end | end | ||
Zeile 1.299: | Zeile 1.374: | ||
end | end | ||
if type( template ) == "table" then | if type( template ) == "table" then | ||
local low = ( ask == "ISO" or ask == "ISO-T" ) | |||
r1 = template.spec | r1 = template.spec | ||
if assigned.year then | if assigned.year then | ||
if not assigned.dom then | if not assigned.dom then | ||
r1 = r1:gsub( "[ .]?[ | r1 = r1:gsub( "[ .%-]?[dDjlNwz][ .,%-]*", "" ) | ||
:gsub( "^ ", "" ) | :gsub( "^ ", "" ) | ||
if not assigned.month then | if not assigned.month then | ||
r1 = r1:gsub( "[ .%-]?[ | r1 = r1:gsub( "[ .%-]?[FmMnt][ .%-]*", "" ) | ||
end | end | ||
end | end | ||
Zeile 1.311: | Zeile 1.387: | ||
r1 = r1:gsub( " ?[yY] ?", "" ) | r1 = r1:gsub( " ?[yY] ?", "" ) | ||
if not assigned.dom then | if not assigned.dom then | ||
r1 = r1:gsub( "[ .]?[ | r1 = r1:gsub( "[ .]?[dDjlNwz][ .,%-]*", "" ) | ||
:gsub( "^ ", "" ) | :gsub( "^ ", "" ) | ||
end | end | ||
end | end | ||
if template.lift then | if template.lift and | ||
(assigned.dom or | |||
not (assigned.month or assigned.year or assigned.bc) | |||
) then | |||
local stamp = false | local stamp = false | ||
if assigned.hour then | if assigned.hour then | ||
if assigned.min then | if assigned.min then |