1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
##
# Time ISO Test
assert('Time.new', '15.2.3.3.3') do
Time.new.class == Time
end
assert('Time', '15.2.19') do
Time.class == Class
end
assert('Time.at', '15.2.19.6.1') do
assert_kind_of(Time, Time.at(1300000000.0))
assert_raise(FloatDomainError) { Time.at(Float::NAN) }
assert_raise(FloatDomainError) { Time.at(Float::INFINITY) }
assert_raise(FloatDomainError) { Time.at(-Float::INFINITY) }
assert_raise(FloatDomainError) { Time.at(0, Float::NAN) }
assert_raise(FloatDomainError) { Time.at(0, Float::INFINITY) }
assert_raise(FloatDomainError) { Time.at(0, -Float::INFINITY) }
end
assert('Time.gm', '15.2.19.6.2') do
Time.gm(2012, 12, 23)
end
assert('Time.local', '15.2.19.6.3') do
Time.local(2012, 12, 23)
end
assert('Time.mktime', '15.2.19.6.4') do
Time.mktime(2012, 12, 23)
end
assert('Time.now', '15.2.19.6.5') do
Time.now.class == Time
end
assert('Time.utc', '15.2.19.6.6') do
Time.utc(2012, 12, 23)
end
assert('Time#+', '15.2.19.7.1') do
t1 = Time.at(1300000000.0)
t2 = t1.+(60)
assert_equal(t2.utc.asctime, "Sun Mar 13 07:07:40 UTC 2011")
assert_raise(FloatDomainError) { Time.at(0) + Float::NAN }
assert_raise(FloatDomainError) { Time.at(0) + Float::INFINITY }
assert_raise(FloatDomainError) { Time.at(0) + -Float::INFINITY }
end
assert('Time#-', '15.2.19.7.2') do
t1 = Time.at(1300000000.0)
t2 = t1.-(60)
assert_equal(t2.utc.asctime, "Sun Mar 13 07:05:40 UTC 2011")
assert_raise(FloatDomainError) { Time.at(0) - Float::NAN }
assert_raise(FloatDomainError) { Time.at(0) - Float::INFINITY }
assert_raise(FloatDomainError) { Time.at(0) - -Float::INFINITY }
end
assert('Time#<=>', '15.2.19.7.3') do
t1 = Time.at(1300000000.0)
t2 = Time.at(1400000000.0)
t3 = Time.at(1500000000.0)
t2.<=>(t1) == 1 and
t2.<=>(t2) == 0 and
t2.<=>(t3) == -1 and
t2.<=>(nil) == nil
end
assert('Time#asctime', '15.2.19.7.4') do
Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('Time#ctime', '15.2.19.7.5') do
Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('Time#day', '15.2.19.7.6') do
Time.gm(2012, 12, 23).day == 23
end
assert('Time#dst?', '15.2.19.7.7') do
not Time.gm(2012, 12, 23).utc.dst?
end
assert('Time#getgm', '15.2.19.7.8') do
Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('Time#getlocal', '15.2.19.7.9') do
t1 = Time.at(1300000000.0)
t2 = Time.at(1300000000.0)
t3 = t1.getlocal
t1 == t3 and t3 == t2.getlocal
end
assert('Time#getutc', '15.2.19.7.10') do
Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('Time#gmt?', '15.2.19.7.11') do
Time.at(1300000000.0).utc.gmt?
end
# ATM not implemented
# assert('Time#gmt_offset', '15.2.19.7.12') do
assert('Time#gmtime', '15.2.19.7.13') do
Time.at(1300000000.0).gmtime
end
# ATM not implemented
# assert('Time#gmtoff', '15.2.19.7.14') do
assert('Time#hour', '15.2.19.7.15') do
Time.gm(2012, 12, 23, 7, 6).hour == 7
end
# ATM doesn't really work
# assert('Time#initialize', '15.2.19.7.16') do
assert('Time#initialize_copy', '15.2.19.7.17') do
time_tmp_2 = Time.at(7.0e6)
time_tmp_2.clone == time_tmp_2
end
assert('Time#localtime', '15.2.19.7.18') do
t1 = Time.at(1300000000.0)
t2 = Time.at(1300000000.0)
t1.localtime
t1 == t2.getlocal
end
assert('Time#mday', '15.2.19.7.19') do
Time.gm(2012, 12, 23).mday == 23
end
assert('Time#min', '15.2.19.7.20') do
Time.gm(2012, 12, 23, 7, 6).min == 6
end
assert('Time#mon', '15.2.19.7.21') do
Time.gm(2012, 12, 23).mon == 12
end
assert('Time#month', '15.2.19.7.22') do
Time.gm(2012, 12, 23).month == 12
end
assert('Times#sec', '15.2.19.7.23') do
Time.gm(2012, 12, 23, 7, 6, 40).sec == 40
end
assert('Time#to_f', '15.2.19.7.24') do
Time.at(1300000000.0).to_f == 1300000000.0
end
assert('Time#to_i', '15.2.19.7.25') do
Time.at(1300000000.0).to_i == 1300000000
end
assert('Time#usec', '15.2.19.7.26') do
Time.at(1300000000.0).usec == 0
end
assert('Time#utc', '15.2.19.7.27') do
Time.at(1300000000.0).utc
end
assert('Time#utc?', '15.2.19.7.28') do
Time.at(1300000000.0).utc.utc?
end
# ATM not implemented
# assert('Time#utc_offset', '15.2.19.7.29') do
assert('Time#wday', '15.2.19.7.30') do
Time.gm(2012, 12, 23).wday == 0
end
assert('Time#yday', '15.2.19.7.31') do
Time.gm(2012, 12, 23).yday == 358
end
assert('Time#year', '15.2.19.7.32') do
Time.gm(2012, 12, 23).year == 2012
end
assert('Time#zone', '15.2.19.7.33') do
Time.at(1300000000.0).utc.zone == 'UTC'
end
# Not ISO specified
assert('Time#to_s') do
Time.at(1300000000.0).utc.to_s == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('Time#inspect') do
Time.at(1300000000.0).utc.inspect == "Sun Mar 13 07:06:40 UTC 2011"
end
assert('day of week methods') do
t = Time.gm(2012, 12, 24)
assert_false t.sunday?
assert_true t.monday?
assert_false t.tuesday?
assert_false t.wednesday?
assert_false t.thursday?
assert_false t.friday?
assert_false t.saturday?
end
assert('2000 times 500us make a second') do
t = Time.utc 2015
2000.times do
t += 0.0005
end
t.usec == 0
end
|