Skip to content

Commit

Permalink
[Truffle] Basics of using Java 8 date and time APIs instead of using …
Browse files Browse the repository at this point in the history
…Joda.
  • Loading branch information
chrisseaton committed Oct 9, 2016
1 parent c64bb15 commit 54f7713
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 102 deletions.
Expand Up @@ -14,13 +14,14 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.utilities.CyclicAssumption;
import org.joda.time.DateTimeZone;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.time.TimeNodes.TimeZoneParser;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;

import java.time.ZoneId;

public abstract class GetTimeZoneNode extends RubyNode {

protected static final CyclicAssumption TZ_UNCHANGED = new CyclicAssumption("ENV['TZ'] is unmodified");
Expand All @@ -31,21 +32,21 @@ public static void invalidateTZ() {

@Child SnippetNode snippetNode = new SnippetNode();

public abstract DateTimeZone executeGetTimeZone(VirtualFrame frame);
public abstract ZoneId executeGetTimeZone(VirtualFrame frame);

@Specialization(assumptions = "TZ_UNCHANGED.getAssumption()")
public DateTimeZone getTimeZone(VirtualFrame frame,
@Cached("getTimeZone(frame)") DateTimeZone zone) {
public ZoneId getTimeZone(VirtualFrame frame,
@Cached("getTimeZone(frame)") ZoneId zone) {
return zone;
}

protected DateTimeZone getTimeZone(VirtualFrame frame) {
protected ZoneId getTimeZone(VirtualFrame frame) {
Object tz = snippetNode.execute(frame, "ENV['TZ']");

// TODO CS 4-May-15 not sure how TZ ends up being nil

if (tz == nil()) {
return DateTimeZone.getDefault();
return ZoneId.systemDefault();
} else if (RubyGuards.isRubyString(tz)) {
return TimeZoneParser.parse(this, StringOperations.getString((DynamicObject) tz));
} else {
Expand Down
Expand Up @@ -12,30 +12,27 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.object.dsl.Layout;
import org.joda.time.DateTime;
import org.jruby.truffle.core.basicobject.BasicObjectLayout;

import java.time.ZonedDateTime;

@Layout
public interface TimeLayout extends BasicObjectLayout {

DynamicObjectFactory createTimeShape(DynamicObject logicalClass,
DynamicObject metaClass);

DynamicObject createTime(DynamicObjectFactory factory,
DateTime dateTime,
long nSec,
ZonedDateTime dateTime,
Object zone,
Object offset,
boolean relativeOffset,
boolean isUtc);

boolean isTime(DynamicObject object);

DateTime getDateTime(DynamicObject object);
void setDateTime(DynamicObject object, DateTime value);

long getNSec(DynamicObject object);
void setNSec(DynamicObject object, long value);
ZonedDateTime getDateTime(DynamicObject object);
void setDateTime(DynamicObject object, ZonedDateTime value);

Object getOffset(DynamicObject object);
void setOffset(DynamicObject object, Object value);
Expand Down

0 comments on commit 54f7713

Please sign in to comment.