From: daurnimator Date: Thu, 15 Aug 2013 22:15:47 +0000 (-0400) Subject: src/timetable: Normalise out of range months X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/a74ef4ee5f93ac14d3ee03bf70a78d6a192e351f?hp=552dae748576124266ac25f05a5d9b1d142cd69c src/timetable: Normalise out of range months --- diff --git a/spec/timetable_spec.lua b/spec/timetable_spec.lua index 38ded15..9a16af5 100644 --- a/spec/timetable_spec.lua +++ b/spec/timetable_spec.lua @@ -49,5 +49,9 @@ describe ( "Time table library" , function ( ) assert.same ( native_timestamp ( y,m,1 ) , timetable.timestamp(y,m,1,0,0,0) ) end end - end) + end ) + + it ( "Out of range month is normalised" , function ( ) + assert.same ( { timetable.normalise(2013,0,1,0,0,0) } , { 2012,12,1,0,0,0 } ) + end ) end ) diff --git a/src/timetable.lua b/src/timetable.lua index bacc58c..aef8ca4 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -21,6 +21,7 @@ local function year_length ( y ) end local function month_length ( m , y ) + m = ( m - 1 ) % 12 + 1 if m == 2 then return is_leap ( y ) and 29 or 28 else