]> gitweb.factorcode.org Git - factor.git/commitdiff
Add rfc3339>timestamp word
authorSlava Pestov <slava@factorcode.org>
Sat, 8 Dec 2007 22:18:09 +0000 (17:18 -0500)
committerSlava Pestov <slava@factorcode.org>
Sat, 8 Dec 2007 22:18:09 +0000 (17:18 -0500)
extra/calendar/calendar.factor

index c255e0a78eaa53b0a749315cc3f23b7e090d4648..55d632d245248081ba33248085d7ec9a4d8d0629 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 
 USING: arrays hashtables io io.streams.string kernel math
-math.vectors math.functions math.parser
-namespaces sequences strings tuples system ;
+math.vectors math.functions math.parser namespaces sequences
+strings tuples system debugger ;
 IN: calendar
 
 TUPLE: timestamp year month day hour minute second gmt-offset ;
@@ -316,7 +316,28 @@ M: timestamp <=> ( ts1 ts2 -- n )
 : timestamp>rfc3339 ( timestamp -- str )
     >gmt [
         (timestamp>rfc3339)
-     ] string-out ;
+    ] string-out ;
+
+: expect read1 assert= ;
+
+: (rfc3339>timestamp) ( -- timestamp )
+    4 read string>number ! year
+    CHAR: - expect
+    2 read string>number ! month
+    CHAR: - expect
+    2 read string>number ! day
+    CHAR: T expect
+    2 read string>number ! hour
+    CHAR: : expect
+    2 read string>number ! minute
+    CHAR: : expect
+    2 read string>number ! second
+    0 <timestamp> ;
+
+: rfc3339>timestamp ( str -- timestamp )
+    [
+        (rfc3339>timestamp)
+    ] string-in ;
 
 : file-time-string ( timestamp -- string )
     [