Skip to content

Commit 6d03e02

Browse files
committed
convert Temporal.PlainTime asTime(), and test
1 parent 1ba33cc commit 6d03e02

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/interop/TemporalInteropToJavaTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,17 @@ public void testInstant() {
116116
// public void testPlainDate() {
117117
// }
118118

119-
// TODO
120-
// @Test
121-
// public void testPlainTime() {
122-
// }
119+
@Test
120+
public void testPlainTime() {
121+
try (Context ctx = getJSContext()) {
122+
Value val = ctx.eval(ID, "new Temporal.PlainTime(12, 34, 56, 987, 654, 321);");
123+
LocalTime lt = val.asTime();
124+
Assert.assertEquals(12, lt.getHour());
125+
Assert.assertEquals(34, lt.getMinute());
126+
Assert.assertEquals(56, lt.getSecond());
127+
Assert.assertEquals(987_654_321L, lt.getNano());
128+
}
129+
}
123130

124131
// TODO
125132
// @Test

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/temporal/JSTemporalPlainTimeObject.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@
4040
*/
4141
package com.oracle.truffle.js.runtime.builtins.temporal;
4242

43+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
44+
import com.oracle.truffle.api.interop.InteropLibrary;
45+
import com.oracle.truffle.api.library.ExportLibrary;
46+
import com.oracle.truffle.api.library.ExportMessage;
4347
import com.oracle.truffle.api.object.Shape;
4448
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
4549
import com.oracle.truffle.js.runtime.objects.JSNonProxyObject;
4650

51+
import java.time.LocalTime;
52+
53+
@ExportLibrary(InteropLibrary.class)
4754
public class JSTemporalPlainTimeObject extends JSNonProxyObject implements TemporalTime {
4855

4956
// all values guaranteed to fit into int
@@ -102,4 +109,18 @@ public int getNanosecond() {
102109
public JSDynamicObject getCalendar() {
103110
return calendar;
104111
}
112+
113+
@ExportMessage
114+
@SuppressWarnings("static-method")
115+
final boolean isTime() {
116+
return true;
117+
}
118+
119+
@ExportMessage
120+
@TruffleBoundary
121+
final LocalTime asTime() {
122+
int ns = millisecond * 1_000_000 + microsecond * 1_000 + nanosecond;
123+
LocalTime lt = LocalTime.of(hour, minute, second, ns);
124+
return lt;
125+
}
105126
}

0 commit comments

Comments
 (0)