All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 local new_timetable = require "luatz.timetable".new
3 --- Parse an RFC 3339 datetime at the given position
4 -- Returns a time table and the `tz_offset`
5 -- Return value is not normalised (this preserves a leap second)
6 -- If the timestamp is only partial (i.e. missing "Z" or time offset) then `tz_offset` will be nil
7 -- TODO: Validate components are within their boundarys (e.g. 1 <= month <= 12)
8 local function rfc_3339 ( str , init )
9 local year , month , day , hour , min , sec , patt_end = str:match ( "^(%d%d%d%d)%-(%d%d)%-(%d%d)[Tt](%d%d%.?%d*):(%d%d):(%d%d)()" , init ) -- luacheck: ignore 631
11 return nil, "Invalid RFC 3339 timestamp"
13 year = tonumber ( year )
14 month = tonumber ( month )
15 day = tonumber ( day )
16 hour = tonumber ( hour )
17 min = tonumber ( min )
18 sec = tonumber ( sec )
20 local tt = new_timetable ( year , month , day , hour , min , sec )
23 if str:match ("^[Zz]" , patt_end ) then
26 local hour_offset , min_offset = str:match ( "^([+-]%d%d):(%d%d)" , patt_end )
28 tz_offset = tonumber ( hour_offset ) * 3600 + tonumber ( min_offset ) * 60
29 else -- luacheck: ignore 542
30 -- Invalid RFC 3339 timestamp offset (should be Z or (+/-)hour:min)
31 -- tz_offset will be nil