Skip to content

Commit aab0500

Browse files
committed
Enable more specs for core Time methods
1 parent 96e10ff commit aab0500

File tree

3 files changed

+108
-9
lines changed

3 files changed

+108
-9
lines changed

opal/corelib/time.rb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def +(other)
121121

122122
other = Opal.coerce_to other, Integer, :to_int
123123

124-
`new Date(self.getTime() + (other * 1000))`
124+
%x{
125+
var result = new Date(self.getTime() + (other * 1000));
126+
result.tz_offset = self.tz_offset;
127+
return result;
128+
}
125129
end
126130

127131
def -(other)
@@ -130,7 +134,11 @@ def -(other)
130134
else
131135
other = Opal.coerce_to other, Integer, :to_int
132136

133-
`new Date(self.getTime() - (other * 1000))`
137+
%x{
138+
var result = new Date(self.getTime() - (other * 1000));
139+
result.tz_offset = self.tz_offset;
140+
return result;
141+
}
134142
end
135143
end
136144

@@ -171,13 +179,11 @@ def hour
171179
end
172180

173181
def inspect
174-
%x{
175-
if (self.tz_offset == 0) {
176-
return #{strftime '%Y-%m-%d %H:%M:%S UTC'};
177-
} else {
178-
return #{strftime '%Y-%m-%d %H:%M:%S %z'};
179-
}
180-
}
182+
if utc?
183+
strftime '%Y-%m-%d %H:%M:%S UTC'
184+
else
185+
strftime '%Y-%m-%d %H:%M:%S %z'
186+
end
181187
end
182188

183189
alias mday day
@@ -492,6 +498,10 @@ def utc?
492498
`self.tz_offset == 0`
493499
end
494500

501+
def utc_offset
502+
`self.getTimezoneOffset() * -60`
503+
end
504+
495505
def wday
496506
`self.getDay()`
497507
end

spec/opal/filters/bugs/time.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
11
opal_filter "Time" do
2+
fails "Time.gm ignores fractional seconds if a passed fractional number of microseconds"
3+
fails "Time.gm ignores fractional seconds if a passed whole number of microseconds"
4+
fails "Time.gm handles fractional microseconds as a Rational"
5+
fails "Time.gm handles fractional microseconds as a Float"
6+
fails "Time.gm handles microseconds"
7+
fails "Time.gm handles float arguments"
8+
fails "Time.gm handles string arguments"
9+
fails "Time.gm returns subclass instances"
10+
fails "Time.gm raises ArgumentError when given 11 arguments"
11+
fails "Time.gm raises ArgumentError when given 9 arguments"
12+
fails "Time.gm handles fractional seconds as a Rational"
13+
fails "Time.gm handles fractional seconds as a Float"
14+
fails "Time.gm coerces the second with #to_int"
15+
fails "Time.gm coerces the minute with #to_int"
16+
fails "Time.gm coerces the hour with #to_int"
17+
fails "Time.gm coerces the day with #to_int"
18+
fails "Time.gm coerces the month with #to_int"
19+
fails "Time.gm coerces the month with #to_str"
20+
fails "Time.gm handles a String month given as a short month name"
21+
fails "Time.gm coerces the year with #to_int"
22+
fails "Time.gm accepts nil month, day, hour, minute, and second"
23+
fails "Time.gm creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)"
24+
fails "Time.gm creates a time based on given values, interpreted as UTC (GMT)"
25+
26+
fails "Time.local ignores fractional seconds if a passed fractional number of microseconds"
27+
fails "Time.local ignores fractional seconds if a passed whole number of microseconds"
28+
fails "Time.local handles fractional microseconds as a Rational"
29+
fails "Time.local handles fractional microseconds as a Float"
30+
fails "Time.local handles microseconds"
31+
fails "Time.local returns subclass instances"
32+
fails "Time.local handles fractional seconds as a Rational"
33+
fails "Time.local handles fractional seconds as a Float"
34+
fails "Time.local coerces the month with #to_str"
35+
fails "Time.local handles a String month given as a short month name"
36+
fails "Time.local creates the correct time just after dst change"
37+
fails "Time.local creates the correct time just before dst change"
38+
fails "Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone"
39+
fails "Time.local respects rare old timezones"
40+
fails "Time.local creates a time based on given values, interpreted in the local time zone"
41+
42+
fails "Time#- returns a time with the same fixed offset as self"
43+
fails "Time#- maintains subseconds precision"
44+
fails "Time#- maintains nanoseconds precision"
45+
fails "Time#- maintains microseconds precision"
46+
fails "Time#- maintains precision"
47+
fails "Time#- tracks nanoseconds"
48+
fails "Time#- tracks microseconds"
49+
fails "Time#- tracks microseconds"
50+
fails "Time#- accepts arguments that can be coerced into Rational"
51+
fails "Time#- understands negative subtractions"
52+
253
fails "Time.mktime respects rare old timezones"
354
fails "Time.mktime creates a time based on given values, interpreted in the local time zone"
455
fails "Time.mktime creates the correct time just before dst change"
@@ -12,9 +63,23 @@
1263
fails "Time.mktime handles a String month given as a short month name"
1364
fails "Time.mktime returns subclass instances"
1465

66+
fails "Time#eql? returns false if self and other have differing fractional microseconds"
67+
1568
fails "Time.inspect formats the local time following the pattern 'yyyy-MM-dd HH:mm:ss Z'"
1669
fails "Time.inspect formats the fixed offset time following the pattern 'yyyy-MM-dd HH:mm:ss +/-HHMM'"
1770

71+
fails "Time#+ maintains subseconds precision"
72+
fails "Time#+ maintains nanoseconds precision"
73+
fails "Time#+ maintains microseconds precision"
74+
fails "Time#+ maintains precision"
75+
fails "Time#+ tracks nanoseconds"
76+
fails "Time#+ tracks microseconds"
77+
fails "Time#+ returns a time with the same fixed offset as self"
78+
fails "Time#+ accepts arguments that can be coerced into Rational"
79+
fails "Time#+ increments the time by the specified amount as rational numbers"
80+
fails "Time#+ adds a negative Float"
81+
fails "Time#+ is a commutative operator"
82+
1883
fails "Time#strftime supports week of year format with %U and %W"
1984

2085
fails "Time#to_s formats the local time following the pattern 'yyyy-MM-dd HH:mm:ss Z'"
@@ -44,4 +109,12 @@
44109
fails "Time.utc accepts nil month, day, hour, minute, and second"
45110
fails "Time.utc creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)"
46111
fails "Time.utc creates a time based on given values, interpreted as UTC (GMT)"
112+
113+
fails "Time#utc_offset given negative offset returns a negative offset"
114+
fails "Time#utc_offset given positive offset returns a positive offset"
115+
fails "Time#utc_offset returns offset as Rational"
116+
fails "Time#utc_offset returns the correct offset for New Zealand around daylight savings time change"
117+
fails "Time#utc_offset returns the correct offset for Hawaii around daylight savings time change"
118+
fails "Time#utc_offset returns the correct offset for US Eastern time zone around daylight savings time change"
119+
fails "Time#utc_offset returns the offset in seconds between the timezone of time and UTC"
47120
end

spec/opal/rubyspecs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,36 @@ core/struct/new_spec
323323
core/class/new_spec
324324

325325
core/time/day_spec
326+
core/time/eql_spec
326327
core/time/friday_spec
328+
core/time/gm_spec
327329
core/time/hour_spec
328330
core/time/inspect_spec
331+
core/time/local_spec
332+
core/time/mday_spec
329333
core/time/min_spec
334+
core/time/minus_spec
330335
core/time/mktime_spec
336+
core/time/mon_spec
331337
core/time/monday_spec
332338
core/time/month_spec
339+
# core/time/new_spec - js parse error (xstring in shared/now)
340+
# core/time/now_spec - js parse error (xstring in shared/now)
341+
core/time/plus_spec
333342
core/time/saturday_spec
343+
core/time/sec_spec
334344
core/time/strftime_spec
345+
core/time/sunday_spec
335346
core/time/thursday_spec
347+
core/time/times_spec
348+
core/time/to_i_spec
336349
core/time/to_s_spec
337350
core/time/tuesday_spec
351+
core/time/utc_offset_spec
338352
core/time/utc_spec
353+
core/time/wday_spec
339354
core/time/wednesday_spec
355+
core/time/yday_spec
340356
core/time/year_spec
341357

342358
#core/regexp/escape_spec

0 commit comments

Comments
 (0)