calendar.parser: invalid date checking for the parsing words

char-rename
Björn Lindqvist 2017-01-05 13:31:59 +01:00
parent 4c097a396a
commit 6b29a50cd4
2 changed files with 52 additions and 31 deletions

View File

@ -44,6 +44,25 @@ IN: calendar.parser.tests
time- 1 seconds before?
] unit-test
! cookie-string>timestamp-1
{ "20160203102022" } [
"Friday, 03-Feb-2016 10:20:22 GMT" cookie-string>timestamp-1
timestamp>mdtm
] unit-test
[ "Friday, 03-Feb-2016 24:20:22 GMT" cookie-string>timestamp-1 ]
[ not-in-interval? ] must-fail-with
[ "Friday, 33-Feb-2016 12:20:22 GMT" cookie-string>timestamp-1 ]
[ not-in-interval? ] must-fail-with
! cookie-string>timestamp-2
{ "19980903102022" } [
"Friday Sep 3 10:20:22 1998 GMT" cookie-string>timestamp-2 timestamp>mdtm
] unit-test
[ "Friday Sep 3 10:60:22 1998 GMT" cookie-string>timestamp-2 ]
[ not-in-interval? ] must-fail-with
! hhmm>duration
{
T{ duration { hour 10 } { minute 20 } }
@ -161,3 +180,9 @@ IN: calendar.parser.tests
"Tue, 22 Apr 2008 14:36:12 GMT "
rfc822>timestamp timestamp>rfc822
] unit-test
[ "Tue, 99 Apr 2008 14:36:12 GMT" rfc822>timestamp ]
[ not-in-interval? ] must-fail-with
[ "Wed, 29 Feb 2017 10:20:30 GMT" rfc822>timestamp ]
[ not-in-interval? ] must-fail-with

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs calendar calendar.english combinators
continuations io io.streams.string kernel macros math math.functions
math.parser sequences ;
continuations generalizations io io.streams.string kernel macros math
math.functions math.parser sequences ;
IN: calendar.parser
: read-00 ( -- n ) 2 read string>number ;
@ -94,17 +94,19 @@ CONSTANT: rfc822-named-zones H{
]
} cond ;
: read-hh:mm:ss ( -- hh mm ss )
":" read-token checked-number
":" read-token checked-number
read-sp checked-number ;
: (rfc822>timestamp) ( -- timestamp )
timestamp new
"," read-token day-abbreviations3 member? check-timestamp drop
read1 CHAR: \s assert=
read-sp checked-number >>day
read-sp month-abbreviations index 1 + check-timestamp >>month
read-sp checked-number >>year
":" read-token checked-number >>hour
":" read-token checked-number >>minute
read-sp checked-number >>second
" " read-until drop parse-rfc822-gmt-offset >>gmt-offset ;
read-sp checked-number
read-sp month-abbreviations index 1 + check-timestamp
read-sp checked-number -rot swap
read-hh:mm:ss
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
: rfc822>timestamp ( str -- timestamp )
[ (rfc822>timestamp) ] with-string-reader ;
@ -114,30 +116,24 @@ CONSTANT: rfc822-named-zones H{
check-timestamp drop ;
: (cookie-string>timestamp-1) ( -- timestamp )
timestamp new
"," read-token check-day-name
read1 CHAR: \s assert=
"-" read-token checked-number >>day
"-" read-token month-abbreviations index 1 + check-timestamp >>month
read-sp checked-number >>year
":" read-token checked-number >>hour
":" read-token checked-number >>minute
read-sp checked-number >>second
readln parse-rfc822-gmt-offset >>gmt-offset ;
"-" read-token checked-number
"-" read-token month-abbreviations index 1 + check-timestamp
read-sp checked-number -rot swap
read-hh:mm:ss
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
: cookie-string>timestamp-1 ( str -- timestamp )
[ (cookie-string>timestamp-1) ] with-string-reader ;
: (cookie-string>timestamp-2) ( -- timestamp )
timestamp new
read-sp check-day-name
read-sp month-abbreviations index 1 + check-timestamp >>month
read-sp checked-number >>day
":" read-token checked-number >>hour
":" read-token checked-number >>minute
read-sp checked-number >>second
read-sp checked-number >>year
readln parse-rfc822-gmt-offset >>gmt-offset ;
read-sp month-abbreviations index 1 + check-timestamp
read-sp checked-number
read-hh:mm:ss
[ read-sp checked-number ] 5 ndip
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
: cookie-string>timestamp-2 ( str -- timestamp )
[ (cookie-string>timestamp-2) ] with-string-reader ;