From: daurnimator Date: Fri, 29 Aug 2014 20:36:10 +0000 (-0400) Subject: Breaking change: Normalise inside of `new_from_timestamp()` X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/94c5a08ebdc03125f84e7fed814a1599c788a09e?pf=etc Breaking change: Normalise inside of `new_from_timestamp()` --- diff --git a/doc/timetable.md b/doc/timetable.md index e3601a4..92c4302 100644 --- a/doc/timetable.md +++ b/doc/timetable.md @@ -28,12 +28,9 @@ Returns a new timetable with the given contents. ## `new_from_timestamp ( timestamp )` -Returns a new timetable given a timestamp in seconds since the unix epoch of +Returns a new (normalised) timetable, given a timestamp in seconds since the unix epoch of 1970-01-01. -`:normalise ( )` should probably be called before use to resolve to the current time and -date. - ## `:clone ( )` diff --git a/examples/date_arithmetic.lua b/examples/date_arithmetic.lua index 3b1126d..d5bd92b 100644 --- a/examples/date_arithmetic.lua +++ b/examples/date_arithmetic.lua @@ -2,7 +2,7 @@ local luatz = require "luatz" -- We do this a few times ==> Convert a timestamp to timetable and normalise local function ts2tt ( ts ) - return luatz.timetable.new_from_timestamp ( ts ):normalise ( ) + return luatz.timetable.new_from_timestamp ( ts ) end -- Get the current time in UTC diff --git a/examples/os_date.lua b/examples/os_date.lua index 0164780..deac08b 100644 --- a/examples/os_date.lua +++ b/examples/os_date.lua @@ -14,7 +14,7 @@ local function os_date ( format_string , timestamp ) else -- Localtime timestamp = get_tz ( ):localise ( timestamp ) end - local tt = new_from_timestamp ( timestamp ):normalise ( ) + local tt = new_from_timestamp ( timestamp ) if format_string == "*t" then return tt else diff --git a/luatz/init.lua b/luatz/init.lua index 8ab7cfc..923e4d6 100644 --- a/luatz/init.lua +++ b/luatz/init.lua @@ -20,7 +20,7 @@ end --- C-like functions _M.gmtime = function ( ts ) - return _M.timetable.new_from_timestamp ( ts ):normalise ( ) + return _M.timetable.new_from_timestamp ( ts ) end _M.localtime = function ( ts ) diff --git a/luatz/timetable.lua b/luatz/timetable.lua index 3e80242..fc89fca 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -227,7 +227,7 @@ local function new_from_timestamp ( ts ) if type ( ts ) ~= "number" then error ( "bad argument #1 to 'new_from_timestamp' (number expected, got " .. type ( ts ) .. ")" , 2 ) end - return new_timetable ( 1970 , 1 , 1 , 0 , 0 , ts ) + return new_timetable ( 1970 , 1 , 1 , 0 , 0 , ts ):normalise ( ) end return {