Skip to content

Commit

Permalink
Merge pull request #687 from atambo/time_coerce_to_int
Browse files Browse the repository at this point in the history
Time methods should coerce the day, hour, minute, or second with #to_int
  • Loading branch information
headius committed May 1, 2013
2 parents 86080d9 + 3b47685 commit cfa3dc4
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 38 deletions.
4 changes: 0 additions & 4 deletions spec/tags/1.8/ruby/core/time/gm_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/1.8/ruby/core/time/local_tags.txt
@@ -1,9 +1,5 @@
fails:Time.local creates a time based on given values, interpreted in the local time zone
fails:Time.local respects rare old timezones
fails:Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.local coerces the day with #to_int
fails:Time.local coerces the hour with #to_int
fails:Time.local coerces the minute with #to_int
fails:Time.local coerces the second with #to_int
fails:Time.local creates the correct time just before dst change
fails:Time.local creates the correct time just after dst change
4 changes: 0 additions & 4 deletions spec/tags/1.8/ruby/core/time/mktime_tags.txt
@@ -1,9 +1,5 @@
fails:Time.mktime creates a time based on given values, interpreted in the local time zone
fails:Time.mktime respects rare old timezones
fails:Time.mktime creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.mktime coerces the day with #to_int
fails:Time.mktime coerces the hour with #to_int
fails:Time.mktime coerces the minute with #to_int
fails:Time.mktime coerces the second with #to_int
fails:Time.mktime creates the correct time just before dst change
fails:Time.mktime creates the correct time just after dst change
4 changes: 0 additions & 4 deletions spec/tags/1.8/ruby/core/time/utc_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/time/gm_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/time/local_tags.txt
@@ -1,9 +1,5 @@
fails:Time.local creates a time based on given values, interpreted in the local time zone
fails:Time.local respects rare old timezones
fails:Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.local coerces the day with #to_int
fails:Time.local coerces the hour with #to_int
fails:Time.local coerces the minute with #to_int
fails:Time.local coerces the second with #to_int
fails:Time.local creates the correct time just before dst change
fails:Time.local creates the correct time just after dst change
4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/time/mktime_tags.txt
@@ -1,9 +1,5 @@
fails:Time.mktime creates a time based on given values, interpreted in the local time zone
fails:Time.mktime respects rare old timezones
fails:Time.mktime creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.mktime coerces the day with #to_int
fails:Time.mktime coerces the hour with #to_int
fails:Time.mktime coerces the minute with #to_int
fails:Time.mktime coerces the second with #to_int
fails:Time.mktime creates the correct time just before dst change
fails:Time.mktime creates the correct time just after dst change
4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/time/new_tags.txt
@@ -1,9 +1,5 @@
fails:Time.new creates a time based on given values, interpreted in the local time zone
fails:Time.new respects rare old timezones
fails:Time.new coerces the day with #to_int
fails:Time.new coerces the hour with #to_int
fails:Time.new coerces the minute with #to_int
fails:Time.new coerces the second with #to_int
fails:Time.new with a utc_offset argument returns a Time with a UTC offset of the specified number of Rational seconds
fails:Time.new with a utc_offset argument returns a local Time if the argument is nil
fails:Time.new with a utc_offset argument raises ArgumentError if the String argument is not in an ASCII-compatible encoding
Expand Down
4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/time/utc_tags.txt

This file was deleted.

9 changes: 7 additions & 2 deletions src/org/jruby/RubyTime.java
Expand Up @@ -1267,8 +1267,13 @@ private static RubyTime createTime(IRubyObject recv, IRubyObject[] args, boolean
for (int i = 0; int_args.length >= i + 2; i++) {
if (!args[i + 2].isNil()) {
if (!(args[i + 2] instanceof RubyNumeric)) {
args[i + 2] = args[i + 2].callMethod(
runtime.getCurrentContext(), "to_i");
if (args[i + 2].respondsTo("to_int")) {
args[i + 2] = args[i + 2].callMethod(
runtime.getCurrentContext(), "to_int");
} else {
args[i + 2] = args[i + 2].callMethod(
runtime.getCurrentContext(), "to_i");
}
}

long value = RubyNumeric.num2long(args[i + 2]);
Expand Down

0 comments on commit cfa3dc4

Please sign in to comment.