]> gitweb.factorcode.org Git - factor.git/blob - basis/calendar/format/format-tests.factor
b1598df2fe12eb780984d379647ef8408c7ebf5d
[factor.git] / basis / calendar / format / format-tests.factor
1 USING: calendar.format calendar kernel math tools.test
2 io.streams.string accessors io math.order sequences ;
3 IN: calendar.format.tests
4
5 [ 0 ] [
6     "Z" [ read1 read-rfc3339-gmt-offset ] with-string-reader duration>hours
7 ] unit-test
8
9 [ 1 ] [
10     "+01" [ read1 read-rfc3339-gmt-offset ] with-string-reader duration>hours
11 ] unit-test
12
13 [ -1 ] [
14     "-01" [ read1 read-rfc3339-gmt-offset ] with-string-reader duration>hours
15 ] unit-test
16
17 [ -1-1/2 ] [
18     "-01:30" [ read1 read-rfc3339-gmt-offset ] with-string-reader duration>hours
19 ] unit-test
20
21 [ 1+1/2 ] [
22     "+01:30" [ read1 read-rfc3339-gmt-offset ] with-string-reader duration>hours
23 ] unit-test
24
25 [ ] [ now timestamp>rfc3339 drop ] unit-test
26 [ ] [ now timestamp>rfc822 drop ] unit-test
27
28 [ 8/1000 -4 ] [
29     "2008-04-19T04:56:00.008-04:00" rfc3339>timestamp
30     [ second>> ] [ gmt-offset>> hour>> ] bi
31 ] unit-test
32
33 [ T{ duration f 0 0 0 0 0 0 } ] [
34     "GMT" parse-rfc822-gmt-offset
35 ] unit-test
36
37 [ T{ duration f 0 0 0 -5 0 0 } ] [
38     "-0500" parse-rfc822-gmt-offset
39 ] unit-test
40
41 [ T{ timestamp f 2008 4 22 14 36 12 T{ duration f 0 0 0 0 0 0 } } ] [
42     "Tue, 22 Apr 2008 14:36:12 GMT" rfc822>timestamp
43 ] unit-test
44
45 [ t ] [ now dup timestamp>rfc822 rfc822>timestamp time- 1 seconds before? ] unit-test
46
47 [ t ] [ now dup timestamp>cookie-string cookie-string>timestamp time- 1 seconds before? ] unit-test
48
49 [ "Sun, 4 May 2008 07:00:00" ] [
50     "Sun May 04 07:00:00 2008 GMT" cookie-string>timestamp
51     timestamp>string
52 ] unit-test
53
54 [ "20080504070000" ] [
55     "Sun May 04 07:00:00 2008 GMT" cookie-string>timestamp
56     timestamp>mdtm
57 ] unit-test
58
59 [
60     T{ timestamp f
61         2008
62         5
63         26
64         0
65         37
66         42+2469/20000
67         T{ duration f 0 0 0 -5 0 0 }
68     }
69 ] [ "2008-05-26T00:37:42.12345-05:00" rfc3339>timestamp ] unit-test
70
71 [
72     T{ timestamp
73         { year 2008 }
74         { month 10 }
75         { day 2 }
76         { hour 23 }
77         { minute 59 }
78         { second 59 }
79         { gmt-offset T{ duration f 0 0 0 0 0 0 } }
80     }
81 ] [ "Thursday, 02-Oct-2008 23:59:59 GMT" cookie-string>timestamp ] unit-test
82
83
84 [ ]
85 [ { 2008 2009 } [ year. ] each ] unit-test
86
87 [
88     T{ timestamp
89         { year 2013 }
90         { month 4 }
91         { day 23 }
92         { hour 13 }
93         { minute 50 }
94         { second 24 }
95     }
96 ] [ "2013-04-23T13:50:24" rfc3339>timestamp ] unit-test
97
98 { "2001-12-14T21:59:43.100000-05:00" } [ "2001-12-14T21:59:43.1-05:00" rfc3339>timestamp timestamp>rfc3339 ] unit-test
99
100 [
101     T{ timestamp
102         { year 2001 }
103         { month 12 }
104         { day 15 }
105         { hour 02 }
106         { minute 59 }
107         { second 43+1/10 }
108     }
109 ] [ "2001-12-15 02:59:43.1Z" rfc3339>timestamp ] unit-test
110
111 [
112     T{ timestamp
113         { year 2001 }
114         { month 12 }
115         { day 15 }
116         { hour 02 }
117         { minute 59 }
118         { second 43+1/10 }
119     }
120 ] [ "2001-12-15 02:59:43.1Z" rfc3339>timestamp ] unit-test