Skip to content

Commit b24f7e8

Browse files
committed
Add Time#asctime/#ctime with specs
1 parent aab0500 commit b24f7e8

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

opal/corelib/time.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def ==(other)
150150
`#{to_f} === #{other.to_f}`
151151
end
152152

153+
def asctime
154+
strftime '%a %b %e %H:%M:%S %Y'
155+
end
156+
157+
alias ctime asctime
158+
153159
def day
154160
`self.getDate()`
155161
end
@@ -236,6 +242,10 @@ def zone
236242
}
237243
end
238244

245+
def gmt?
246+
`self.tz_offset == 0`
247+
end
248+
239249
def gmt_offset
240250
`-self.getTimezoneOffset() * 60`
241251
end
@@ -494,9 +504,7 @@ def tuesday?
494504
`self.getDay() === 2`
495505
end
496506

497-
def utc?
498-
`self.tz_offset == 0`
499-
end
507+
alias utc? gmt?
500508

501509
def utc_offset
502510
`self.getTimezoneOffset() * -60`

spec/opal/filters/bugs/time.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
fails "Time.gm creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)"
2424
fails "Time.gm creates a time based on given values, interpreted as UTC (GMT)"
2525

26+
fails "Time#gmt_offset given negative offset returns a negative offset"
27+
fails "Time#gmt_offset given positive offset returns a positive offset"
28+
fails "Time#gmt_offset returns offset as Rational"
29+
fails "Time#gmt_offset returns the correct offset for New Zealand around daylight savings time change"
30+
fails "Time#gmt_offset returns the correct offset for Hawaii around daylight savings time change"
31+
fails "Time#gmt_offset returns the correct offset for US Eastern time zone around daylight savings time change"
32+
fails "Time#gmt_offset returns the offset in seconds between the timezone of time and UTC"
33+
2634
fails "Time.local ignores fractional seconds if a passed fractional number of microseconds"
2735
fails "Time.local ignores fractional seconds if a passed whole number of microseconds"
2836
fails "Time.local handles fractional microseconds as a Rational"

spec/opal/rubyspecs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,13 @@ core/struct/new_spec
322322

323323
core/class/new_spec
324324

325+
core/time/asctime_spec
326+
core/time/ctime_spec
325327
core/time/day_spec
326328
core/time/eql_spec
327329
core/time/friday_spec
328330
core/time/gm_spec
331+
core/time/gmt_offset_spec
329332
core/time/hour_spec
330333
core/time/inspect_spec
331334
core/time/local_spec

0 commit comments

Comments
 (0)