calendar.format: rfc3339, don't drop seconds decimals

db4
Jon Harper 2014-07-01 23:42:25 +02:00 committed by John Benediktsson
parent 85f5075c83
commit 484ddae159
2 changed files with 11 additions and 0 deletions

View File

@ -95,6 +95,8 @@ IN: calendar.format.tests
}
] [ "2013-04-23T13:50:24" rfc3339>timestamp ] unit-test
{ "2001-12-14T21:59:43.1-05:00" } [ "2001-12-14T21:59:43.1-05:00" rfc3339>timestamp timestamp>rfc3339 ] unit-test
[
T{ timestamp
{ year 2001 }

View File

@ -133,9 +133,18 @@ M: timestamp year. ( timestamp -- )
{ +gt+ [ "+" write (write-rfc3339-gmt-offset) ] }
} case ;
! Should be enough for anyone, allows to not do a fancy
! algorithm to detect infinite decimals (e.g 1/3)
CONSTANT: rfc3339-precision 5
: write-rfc3339-seconds ( timestamp -- )
second>> 1 mod rfc3339-precision 10^ * round >integer
number>string rfc3339-precision CHAR: 0 pad-head
[ CHAR: 0 = ] trim-tail [ "." write write ] unless-empty ;
: (timestamp>rfc3339) ( timestamp -- )
{
YYYY "-" MM "-" DD "T" hh ":" mm ":" ss
write-rfc3339-seconds
[ gmt-offset>> write-rfc3339-gmt-offset ]
} formatted ;