]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar.parser,robots: hhmm>timestamp -> hhmm>duration
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 4 Jan 2017 08:10:15 +0000 (09:10 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 4 Jan 2017 08:10:15 +0000 (09:10 +0100)
Better to parse it as a duration because it is not a valid timestamp.

basis/calendar/parser/parser-tests.factor
basis/calendar/parser/parser.factor
extra/robots/robots-tests.factor
extra/robots/robots.factor

index 66f8596accabea91f39262d16d12a327ff9262f5..9596cc4e6a981e5fbe03cba6835bed4a8d745f8b 100644 (file)
@@ -44,6 +44,13 @@ IN: calendar.parser.tests
     time- 1 seconds before?
 ] unit-test
 
+! hhmm>duration
+{
+    T{ duration { hour 10 } { minute 20 } }
+} [
+    "1020" hhmm>duration
+] unit-test
+
 ! parse-rfc822-gmt-offset
 { T{ duration f 0 0 0 0 0 0 } } [
     "GMT" parse-rfc822-gmt-offset
index 5ef80f2c6296d2a10c60be03bd4a59c8b4f42559..03398f97735f18557fc886ab55929b16930b2313 100644 (file)
@@ -27,11 +27,6 @@ ERROR: invalid-timestamp-format ;
 
 : read-sp ( -- token ) " " read-token ;
 
-: hhmm>timestamp ( hhmm -- timestamp )
-    [
-        0 0 0 read-00 read-00 0 instant <timestamp>
-    ] with-string-reader ;
-
 : signed-gmt-offset ( dt ch -- dt' )
     { { CHAR: + [ 1 ] } { CHAR: - [ -1 ] } } case time* ;
 
@@ -181,3 +176,7 @@ MACRO: attempt-all-quots ( quots -- quot )
 
 : ymd>timestamp ( str -- timestamp )
     [ (ymd>timestamp) ] with-string-reader ;
+
+! Duration parsing
+: hhmm>duration ( hhmm -- duration )
+    [ instant read-00 >>hour read-00 >>minute ] with-string-reader ;
index 418c20da168637e14b07df2c96499d6ce7501440..9b40916f93698f1d2b2a2d0115323d376dddcdb5 100644 (file)
@@ -26,8 +26,8 @@ IN: robots.tests
             }
             { visit-time
                 {
-                    T{ timestamp { hour 2 } }
-                    T{ timestamp { hour 5 } }
+                    T{ duration { hour 2 } }
+                    T{ duration { hour 5 } }
                 }
             }
             { request-rate 1 }
index f1f93b8f44a11b2b6642268ccea5b6e3e5d99c34..dc5db2c00c5248e72fb86eea56eab7e9226d5138 100644 (file)
@@ -63,7 +63,7 @@ visit-time request-rate crawl-delay unknowns ;
         { "crawl-delay" [ string>number >>crawl-delay ] }
         { "request-rate" [ string>number >>request-rate ] }
         {
-            "visit-time" [ "-" split1 [ hhmm>timestamp ] bi@ 2array
+            "visit-time" [ "-" split1 [ hhmm>duration ] bi@ 2array
             >>visit-time
         ] }
         [ pick unknowns>> push-at ]