From a74ef4ee5f93ac14d3ee03bf70a78d6a192e351f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 15 Aug 2013 18:15:47 -0400 Subject: [PATCH] src/timetable: Normalise out of range months --- spec/timetable_spec.lua | 6 +++++- src/timetable.lua | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) 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 -- 2.39.5