calendar.parser: invalid date checking for the parsing words
parent
4c097a396a
commit
6b29a50cd4
|
@ -44,6 +44,25 @@ IN: calendar.parser.tests
|
||||||
time- 1 seconds before?
|
time- 1 seconds before?
|
||||||
] unit-test
|
] 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
|
! hhmm>duration
|
||||||
{
|
{
|
||||||
T{ duration { hour 10 } { minute 20 } }
|
T{ duration { hour 10 } { minute 20 } }
|
||||||
|
@ -161,3 +180,9 @@ IN: calendar.parser.tests
|
||||||
"Tue, 22 Apr 2008 14:36:12 GMT "
|
"Tue, 22 Apr 2008 14:36:12 GMT "
|
||||||
rfc822>timestamp timestamp>rfc822
|
rfc822>timestamp timestamp>rfc822
|
||||||
] unit-test
|
] 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
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs calendar calendar.english combinators
|
USING: accessors assocs calendar calendar.english combinators
|
||||||
continuations io io.streams.string kernel macros math math.functions
|
continuations generalizations io io.streams.string kernel macros math
|
||||||
math.parser sequences ;
|
math.functions math.parser sequences ;
|
||||||
IN: calendar.parser
|
IN: calendar.parser
|
||||||
|
|
||||||
: read-00 ( -- n ) 2 read string>number ;
|
: read-00 ( -- n ) 2 read string>number ;
|
||||||
|
@ -94,17 +94,19 @@ CONSTANT: rfc822-named-zones H{
|
||||||
]
|
]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
: read-hh:mm:ss ( -- hh mm ss )
|
||||||
|
":" read-token checked-number
|
||||||
|
":" read-token checked-number
|
||||||
|
read-sp checked-number ;
|
||||||
|
|
||||||
: (rfc822>timestamp) ( -- timestamp )
|
: (rfc822>timestamp) ( -- timestamp )
|
||||||
timestamp new
|
|
||||||
"," read-token day-abbreviations3 member? check-timestamp drop
|
"," read-token day-abbreviations3 member? check-timestamp drop
|
||||||
read1 CHAR: \s assert=
|
read1 CHAR: \s assert=
|
||||||
read-sp checked-number >>day
|
read-sp checked-number
|
||||||
read-sp month-abbreviations index 1 + check-timestamp >>month
|
read-sp month-abbreviations index 1 + check-timestamp
|
||||||
read-sp checked-number >>year
|
read-sp checked-number -rot swap
|
||||||
":" read-token checked-number >>hour
|
read-hh:mm:ss
|
||||||
":" read-token checked-number >>minute
|
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||||
read-sp checked-number >>second
|
|
||||||
" " read-until drop parse-rfc822-gmt-offset >>gmt-offset ;
|
|
||||||
|
|
||||||
: rfc822>timestamp ( str -- timestamp )
|
: rfc822>timestamp ( str -- timestamp )
|
||||||
[ (rfc822>timestamp) ] with-string-reader ;
|
[ (rfc822>timestamp) ] with-string-reader ;
|
||||||
|
@ -114,30 +116,24 @@ CONSTANT: rfc822-named-zones H{
|
||||||
check-timestamp drop ;
|
check-timestamp drop ;
|
||||||
|
|
||||||
: (cookie-string>timestamp-1) ( -- timestamp )
|
: (cookie-string>timestamp-1) ( -- timestamp )
|
||||||
timestamp new
|
|
||||||
"," read-token check-day-name
|
"," read-token check-day-name
|
||||||
read1 CHAR: \s assert=
|
read1 CHAR: \s assert=
|
||||||
"-" read-token checked-number >>day
|
"-" read-token checked-number
|
||||||
"-" read-token month-abbreviations index 1 + check-timestamp >>month
|
"-" read-token month-abbreviations index 1 + check-timestamp
|
||||||
read-sp checked-number >>year
|
read-sp checked-number -rot swap
|
||||||
":" read-token checked-number >>hour
|
read-hh:mm:ss
|
||||||
":" read-token checked-number >>minute
|
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||||
read-sp checked-number >>second
|
|
||||||
readln parse-rfc822-gmt-offset >>gmt-offset ;
|
|
||||||
|
|
||||||
: cookie-string>timestamp-1 ( str -- timestamp )
|
: cookie-string>timestamp-1 ( str -- timestamp )
|
||||||
[ (cookie-string>timestamp-1) ] with-string-reader ;
|
[ (cookie-string>timestamp-1) ] with-string-reader ;
|
||||||
|
|
||||||
: (cookie-string>timestamp-2) ( -- timestamp )
|
: (cookie-string>timestamp-2) ( -- timestamp )
|
||||||
timestamp new
|
|
||||||
read-sp check-day-name
|
read-sp check-day-name
|
||||||
read-sp month-abbreviations index 1 + check-timestamp >>month
|
read-sp month-abbreviations index 1 + check-timestamp
|
||||||
read-sp checked-number >>day
|
read-sp checked-number
|
||||||
":" read-token checked-number >>hour
|
read-hh:mm:ss
|
||||||
":" read-token checked-number >>minute
|
[ read-sp checked-number ] 5 ndip
|
||||||
read-sp checked-number >>second
|
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||||
read-sp checked-number >>year
|
|
||||||
readln parse-rfc822-gmt-offset >>gmt-offset ;
|
|
||||||
|
|
||||||
: cookie-string>timestamp-2 ( str -- timestamp )
|
: cookie-string>timestamp-2 ( str -- timestamp )
|
||||||
[ (cookie-string>timestamp-2) ] with-string-reader ;
|
[ (cookie-string>timestamp-2) ] with-string-reader ;
|
||||||
|
|
Loading…
Reference in New Issue