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 Nov 11, 2016
1 parent ff193c4 commit e3ad5ab
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 104 deletions.
4 changes: 2 additions & 2 deletions lib/pom.xml
Expand Up @@ -313,7 +313,7 @@ DO NOT MODIFIY - GENERATED CODE
<plugin>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-maven-plugin</artifactId>
<version>0.1.16</version>
<version>0.1.15</version>
<executions>
<execution>
<id>install_gems</id>
Expand Down Expand Up @@ -364,7 +364,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.16</version>
<version>0.1.15</version>
</dependency>
</dependencies>
</plugin>
Expand Down
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

1 comment on commit e3ad5ab

@kares
Copy link
Member

@kares kares commented on e3ad5ab Nov 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very najs, wish classic could migrate as well!

Please sign in to comment.