Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Time.new working.
  • Loading branch information
chrisseaton committed Feb 15, 2015
1 parent 7252d05 commit d474788
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/time/local_tags.txt
@@ -1,11 +1,6 @@
fails:Time.local creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.local creates the correct time just before dst change
fails:Time.local creates the correct time just after dst change
fails:Time.local handles a String second
fails:Time.local coerces the second with #to_int
fails:Time.local interprets all numerals as base 10
fails:Time.local handles fractional seconds as a Float
fails:Time.local handles fractional seconds as a Rational
fails:Time.local handles string arguments
fails:Time.local handles float arguments
fails:Time.local handles microseconds
Expand Down
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/time/mktime_tags.txt
@@ -1,11 +1,6 @@
fails:Time.mktime creates a time based on given C-style gmtime arguments, interpreted in the local time zone
fails:Time.mktime creates the correct time just before dst change
fails:Time.mktime creates the correct time just after dst change
fails:Time.mktime handles a String second
fails:Time.mktime coerces the second with #to_int
fails:Time.mktime interprets all numerals as base 10
fails:Time.mktime handles fractional seconds as a Float
fails:Time.mktime handles fractional seconds as a Rational
fails:Time.mktime handles string arguments
fails:Time.mktime handles float arguments
fails:Time.mktime handles microseconds
Expand Down
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/time/new_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/time/strftime_tags.txt
@@ -1,7 +1,5 @@
fails:Time#strftime returns the fractional seconds digits, default is 9 digits (nanosecond) with %N
fails:Time#strftime with %L formats the milliseconds of a second
fails:Time#strftime with %N formats the nanoseconds of of the second with %N
fails:Time#strftime with %N formats the milliseconds of of the second with %3N
fails:Time#strftime with %N formats the microseconds of of the second with %6N
fails:Time#strftime with %N formats the nanoseconds of of the second with %9N
fails:Time#strftime with %N formats the picoseconds of of the second with %12N
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/time/usec_tags.txt
Expand Up @@ -5,5 +5,4 @@ fails:Time#usec returns 0 for a Time constructed with an Float number of microse
fails:Time#usec returns the microseconds part of a Time constructed with a Rational number of seconds
fails:Time#usec returns the microseconds part of a Time constructed with an Rational number of microseconds > 1
fails:Time#usec returns 0 for a Time constructed with an Rational number of microseconds < 1
fails:Time#usec returns the microseconds for time created by Time#local
fails:Time#usec returns 0 for a Time constructed with a whole number of seconds
Expand Up @@ -211,6 +211,13 @@ public RubyTime timeSFromArray(RubyClass timeClass, int sec, int min, int hour,
return timeSFromArray(timeClass, sec, min, hour, mday, month, year, 0, isdst, fromutc, utcoffset);
}

@Specialization
public RubyTime timeSFromArray(RubyClass timeClass, long sec, int min, int hour, int mday, int month, int year,
int nsec, int isdst, boolean fromutc, Object utcoffset) {
// TODO CS 15-Feb-15 that cast
return timeSFromArray(timeClass, (int) sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset);
}

@Specialization
public RubyTime timeSFromArray(RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year,
long nsec, int isdst, boolean fromutc, Object utcoffset) {
Expand All @@ -230,27 +237,41 @@ public RubyTime timeSFromArray(RubyClass timeClass, int sec, int min, int hour,
}

if (isdst == -1 && !fromutc && utcoffset instanceof Integer) {
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, DateTimeZone.forOffsetMillis(((int) utcoffset) * 1_000));
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, DateTimeZone.forOffsetMillis(((int) utcoffset) * 1_000));
return new RubyTime(timeClass, dateTime, utcoffset);
} else if (isdst == -1 && !fromutc && utcoffset instanceof Long) {
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, DateTimeZone.forOffsetMillis((int) ((long) utcoffset) * 1_000));
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, DateTimeZone.forOffsetMillis((int) ((long) utcoffset) * 1_000));
return new RubyTime(timeClass, dateTime, utcoffset);
} else if (isdst == -1 && !fromutc && utcoffset instanceof RubyBasicObject && isRational((RubyBasicObject) utcoffset)) {
// TODO CS 15-Feb-15 debug send and cast
final int millis = cast(DebugOperations.send(getContext(), utcoffset, "_offset_to_milliseconds", null));
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, DateTimeZone.forOffsetMillis(millis));
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, DateTimeZone.forOffsetMillis(millis));
return new RubyTime(timeClass, dateTime, utcoffset);
} else if (isdst == -1 && !fromutc && utcoffset == getContext().getCoreLibrary().getNilObject()) {
// TODO CS 14-Feb-15 uses debug send
final DateTimeZone zone = org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(),
DebugOperations.send(getContext(), getContext().getCoreLibrary().getENV(), "[]", null, getContext().makeString("TZ")).toString());
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, zone);
final DateTime dateTime = new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, zone);
return new RubyTime(timeClass, dateTime, null);
} else {
throw new UnsupportedOperationException(String.format("%s %s %s %s", isdst, fromutc, utcoffset, utcoffset.getClass()));
}
}

@Specialization
public RubyTime timeSFromArray(RubyClass timeClass, RubyBasicObject sec, int min, int hour, int mday, int month, int year,
RubyNilClass nsec, int isdst, boolean fromutc, Object utcoffset) {
return null;
}

@Specialization
public RubyTime timeSFromArray(RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year,
RubyNilClass nsec, int isdst, boolean fromutc, Object utcoffset) {
final int secondsWhole = (int) sec;
final int nanosecondsFractional = (int) ((sec * 1_000_000_000) - (secondsWhole * 1_000_000_000));
return timeSFromArray(timeClass, secondsWhole, min, hour, mday, month, year, nanosecondsFractional, isdst, fromutc, utcoffset);
}

private int cast(Object value) {
if (value instanceof Integer) {
return (int) value;
Expand Down

0 comments on commit d474788

Please sign in to comment.