Skip to content

Commit

Permalink
Enable more specs for core Time methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Dec 9, 2013
1 parent 96e10ff commit aab0500
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 9 deletions.
28 changes: 19 additions & 9 deletions opal/corelib/time.rb
Expand Up @@ -121,7 +121,11 @@ def +(other)

other = Opal.coerce_to other, Integer, :to_int

`new Date(self.getTime() + (other * 1000))`
%x{
var result = new Date(self.getTime() + (other * 1000));
result.tz_offset = self.tz_offset;
return result;
}
end

def -(other)
Expand All @@ -130,7 +134,11 @@ def -(other)
else
other = Opal.coerce_to other, Integer, :to_int

`new Date(self.getTime() - (other * 1000))`
%x{
var result = new Date(self.getTime() - (other * 1000));
result.tz_offset = self.tz_offset;
return result;
}
end
end

Expand Down Expand Up @@ -171,13 +179,11 @@ def hour
end

def inspect
%x{
if (self.tz_offset == 0) {
return #{strftime '%Y-%m-%d %H:%M:%S UTC'};
} else {
return #{strftime '%Y-%m-%d %H:%M:%S %z'};
}
}
if utc?
strftime '%Y-%m-%d %H:%M:%S UTC'
else
strftime '%Y-%m-%d %H:%M:%S %z'
end
end

alias mday day
Expand Down Expand Up @@ -492,6 +498,10 @@ def utc?
`self.tz_offset == 0`
end

def utc_offset
`self.getTimezoneOffset() * -60`
end

def wday
`self.getDay()`
end
Expand Down
73 changes: 73 additions & 0 deletions spec/opal/filters/bugs/time.rb
@@ -1,4 +1,55 @@
opal_filter "Time" do
fails "Time.gm ignores fractional seconds if a passed fractional number of microseconds"
fails "Time.gm ignores fractional seconds if a passed whole number of microseconds"
fails "Time.gm handles fractional microseconds as a Rational"
fails "Time.gm handles fractional microseconds as a Float"
fails "Time.gm handles microseconds"
fails "Time.gm handles float arguments"
fails "Time.gm handles string arguments"
fails "Time.gm returns subclass instances"
fails "Time.gm raises ArgumentError when given 11 arguments"
fails "Time.gm raises ArgumentError when given 9 arguments"
fails "Time.gm handles fractional seconds as a Rational"
fails "Time.gm handles fractional seconds as a Float"
fails "Time.gm coerces the second with #to_int"
fails "Time.gm coerces the minute with #to_int"
fails "Time.gm coerces the hour with #to_int"
fails "Time.gm coerces the day with #to_int"
fails "Time.gm coerces the month with #to_int"
fails "Time.gm coerces the month with #to_str"
fails "Time.gm handles a String month given as a short month name"
fails "Time.gm coerces the year with #to_int"
fails "Time.gm accepts nil month, day, hour, minute, and second"
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.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"
fails "Time.local handles fractional microseconds as a Float"
fails "Time.local handles microseconds"
fails "Time.local returns subclass instances"
fails "Time.local handles fractional seconds as a Rational"
fails "Time.local handles fractional seconds as a Float"
fails "Time.local coerces the month with #to_str"
fails "Time.local handles a String month given as a short month name"
fails "Time.local creates the correct time just after dst change"
fails "Time.local creates the correct time just before dst change"
fails "Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone"
fails "Time.local respects rare old timezones"
fails "Time.local creates a time based on given values, interpreted in the local time zone"

fails "Time#- returns a time with the same fixed offset as self"
fails "Time#- maintains subseconds precision"
fails "Time#- maintains nanoseconds precision"
fails "Time#- maintains microseconds precision"
fails "Time#- maintains precision"
fails "Time#- tracks nanoseconds"
fails "Time#- tracks microseconds"
fails "Time#- tracks microseconds"
fails "Time#- accepts arguments that can be coerced into Rational"
fails "Time#- understands negative subtractions"

fails "Time.mktime respects rare old timezones"
fails "Time.mktime creates a time based on given values, interpreted in the local time zone"
fails "Time.mktime creates the correct time just before dst change"
Expand All @@ -12,9 +63,23 @@
fails "Time.mktime handles a String month given as a short month name"
fails "Time.mktime returns subclass instances"

fails "Time#eql? returns false if self and other have differing fractional microseconds"

fails "Time.inspect formats the local time following the pattern 'yyyy-MM-dd HH:mm:ss Z'"
fails "Time.inspect formats the fixed offset time following the pattern 'yyyy-MM-dd HH:mm:ss +/-HHMM'"

fails "Time#+ maintains subseconds precision"
fails "Time#+ maintains nanoseconds precision"
fails "Time#+ maintains microseconds precision"
fails "Time#+ maintains precision"
fails "Time#+ tracks nanoseconds"
fails "Time#+ tracks microseconds"
fails "Time#+ returns a time with the same fixed offset as self"
fails "Time#+ accepts arguments that can be coerced into Rational"
fails "Time#+ increments the time by the specified amount as rational numbers"
fails "Time#+ adds a negative Float"
fails "Time#+ is a commutative operator"

fails "Time#strftime supports week of year format with %U and %W"

fails "Time#to_s formats the local time following the pattern 'yyyy-MM-dd HH:mm:ss Z'"
Expand Down Expand Up @@ -44,4 +109,12 @@
fails "Time.utc accepts nil month, day, hour, minute, and second"
fails "Time.utc creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)"
fails "Time.utc creates a time based on given values, interpreted as UTC (GMT)"

fails "Time#utc_offset given negative offset returns a negative offset"
fails "Time#utc_offset given positive offset returns a positive offset"
fails "Time#utc_offset returns offset as Rational"
fails "Time#utc_offset returns the correct offset for New Zealand around daylight savings time change"
fails "Time#utc_offset returns the correct offset for Hawaii around daylight savings time change"
fails "Time#utc_offset returns the correct offset for US Eastern time zone around daylight savings time change"
fails "Time#utc_offset returns the offset in seconds between the timezone of time and UTC"
end
16 changes: 16 additions & 0 deletions spec/opal/rubyspecs
Expand Up @@ -323,20 +323,36 @@ core/struct/new_spec
core/class/new_spec

core/time/day_spec
core/time/eql_spec
core/time/friday_spec
core/time/gm_spec
core/time/hour_spec
core/time/inspect_spec
core/time/local_spec
core/time/mday_spec
core/time/min_spec
core/time/minus_spec
core/time/mktime_spec
core/time/mon_spec
core/time/monday_spec
core/time/month_spec
# core/time/new_spec - js parse error (xstring in shared/now)
# core/time/now_spec - js parse error (xstring in shared/now)
core/time/plus_spec
core/time/saturday_spec
core/time/sec_spec
core/time/strftime_spec
core/time/sunday_spec
core/time/thursday_spec
core/time/times_spec
core/time/to_i_spec
core/time/to_s_spec
core/time/tuesday_spec
core/time/utc_offset_spec
core/time/utc_spec
core/time/wday_spec
core/time/wednesday_spec
core/time/yday_spec
core/time/year_spec

#core/regexp/escape_spec
Expand Down

0 comments on commit aab0500

Please sign in to comment.