diff --git a/basis/calendar/calendar-tests.factor b/basis/calendar/calendar-tests.factor index 2490b87c37..3f52b4d2e7 100644 --- a/basis/calendar/calendar-tests.factor +++ b/basis/calendar/calendar-tests.factor @@ -176,3 +176,13 @@ IN: calendar.tests [ t ] [ 1356998399 unix-time>timestamp 2013 1 seconds time- = ] unit-test [ t ] [ 1500000000 random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test + +[ t ] [ + 2009 1 29 1 months time+ + 2009 3 1 = +] unit-test + +[ t ] [ + 2008 1 29 1 months time+ + 2008 2 29 = +] unit-test diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index cd87701aa9..8758b8198b 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -99,12 +99,12 @@ CONSTANT: day-abbreviations3 : day-abbreviation3 ( n -- string ) day-abbreviations3 nth ; inline -: average-month ( -- ratio ) 30+5/12 ; inline -: months-per-year ( -- integer ) 12 ; inline -: days-per-year ( -- ratio ) 3652425/10000 ; inline -: hours-per-year ( -- ratio ) 876582/100 ; inline -: minutes-per-year ( -- ratio ) 5259492/10 ; inline -: seconds-per-year ( -- integer ) 31556952 ; inline +CONSTANT: average-month 30+5/12 +CONSTANT: months-per-year 12 +CONSTANT: days-per-year 3652425/10000 +CONSTANT: hours-per-year 876582/100 +CONSTANT: minutes-per-year 5259492/10 +CONSTANT: seconds-per-year 31556952 :: julian-day-number ( year month day -- n ) #! Returns a composite date number @@ -200,7 +200,7 @@ GENERIC: +second ( timestamp x -- timestamp ) [ 3 >>month 1 >>day ] when ; M: integer +year ( timestamp n -- timestamp ) - [ [ + ] curry change-year adjust-leap-year ] unless-zero ; + [ + ] curry change-year adjust-leap-year ; M: real +year ( timestamp n -- timestamp ) [ float>whole-part swapd days-per-year * +day swap +year ] unless-zero ;