Always do a leap year check when adding timestamps

release
Doug Coleman 2010-03-20 18:38:23 -05:00
parent e7487bfe98
commit 077e5dea2a
2 changed files with 17 additions and 7 deletions

View File

@ -176,3 +176,13 @@ IN: calendar.tests
[ t ] [ 1356998399 unix-time>timestamp 2013 <year-gmt> 1 seconds time- = ] unit-test [ t ] [ 1356998399 unix-time>timestamp 2013 <year-gmt> 1 seconds time- = ] unit-test
[ t ] [ 1500000000 random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test [ t ] [ 1500000000 random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test
[ t ] [
2009 1 29 <date> 1 months time+
2009 3 1 <date> =
] unit-test
[ t ] [
2008 1 29 <date> 1 months time+
2008 2 29 <date> =
] unit-test

View File

@ -99,12 +99,12 @@ CONSTANT: day-abbreviations3
: day-abbreviation3 ( n -- string ) : day-abbreviation3 ( n -- string )
day-abbreviations3 nth ; inline day-abbreviations3 nth ; inline
: average-month ( -- ratio ) 30+5/12 ; inline CONSTANT: average-month 30+5/12
: months-per-year ( -- integer ) 12 ; inline CONSTANT: months-per-year 12
: days-per-year ( -- ratio ) 3652425/10000 ; inline CONSTANT: days-per-year 3652425/10000
: hours-per-year ( -- ratio ) 876582/100 ; inline CONSTANT: hours-per-year 876582/100
: minutes-per-year ( -- ratio ) 5259492/10 ; inline CONSTANT: minutes-per-year 5259492/10
: seconds-per-year ( -- integer ) 31556952 ; inline CONSTANT: seconds-per-year 31556952
:: julian-day-number ( year month day -- n ) :: julian-day-number ( year month day -- n )
#! Returns a composite date number #! Returns a composite date number
@ -200,7 +200,7 @@ GENERIC: +second ( timestamp x -- timestamp )
[ 3 >>month 1 >>day ] when ; [ 3 >>month 1 >>day ] when ;
M: integer +year ( timestamp n -- timestamp ) 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 ) M: real +year ( timestamp n -- timestamp )
[ float>whole-part swapd days-per-year * +day swap +year ] unless-zero ; [ float>whole-part swapd days-per-year * +day swap +year ] unless-zero ;