Skip to content

Commit

Permalink
Add Time#asctime/#ctime with specs
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Dec 9, 2013
1 parent aab0500 commit b24f7e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions opal/corelib/time.rb
Expand Up @@ -150,6 +150,12 @@ def ==(other)
`#{to_f} === #{other.to_f}`
end

def asctime
strftime '%a %b %e %H:%M:%S %Y'
end

alias ctime asctime

def day
`self.getDate()`
end
Expand Down Expand Up @@ -236,6 +242,10 @@ def zone
}
end

def gmt?
`self.tz_offset == 0`
end

def gmt_offset
`-self.getTimezoneOffset() * 60`
end
Expand Down Expand Up @@ -494,9 +504,7 @@ def tuesday?
`self.getDay() === 2`
end

def utc?
`self.tz_offset == 0`
end
alias utc? gmt?

def utc_offset
`self.getTimezoneOffset() * -60`
Expand Down
8 changes: 8 additions & 0 deletions spec/opal/filters/bugs/time.rb
Expand Up @@ -23,6 +23,14 @@
fails "Time.gm creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)"
fails "Time.gm creates a time based on given values, interpreted as UTC (GMT)"

fails "Time#gmt_offset given negative offset returns a negative offset"
fails "Time#gmt_offset given positive offset returns a positive offset"
fails "Time#gmt_offset returns offset as Rational"
fails "Time#gmt_offset returns the correct offset for New Zealand around daylight savings time change"
fails "Time#gmt_offset returns the correct offset for Hawaii around daylight savings time change"
fails "Time#gmt_offset returns the correct offset for US Eastern time zone around daylight savings time change"
fails "Time#gmt_offset returns the offset in seconds between the timezone of time and UTC"

fails "Time.local ignores fractional seconds if a passed fractional number of microseconds"
fails "Time.local ignores fractional seconds if a passed whole number of microseconds"
fails "Time.local handles fractional microseconds as a Rational"
Expand Down
3 changes: 3 additions & 0 deletions spec/opal/rubyspecs
Expand Up @@ -322,10 +322,13 @@ core/struct/new_spec

core/class/new_spec

core/time/asctime_spec
core/time/ctime_spec
core/time/day_spec
core/time/eql_spec
core/time/friday_spec
core/time/gm_spec
core/time/gmt_offset_spec
core/time/hour_spec
core/time/inspect_spec
core/time/local_spec
Expand Down

0 comments on commit b24f7e8

Please sign in to comment.