oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.21k stars 104 forks source link

Value.asTime returns wrong nanosecond field #179

Closed kariya-mitsuru closed 3 years ago

kariya-mitsuru commented 3 years ago

Please see the sample code and its output below.

import java.time.LocalTime;
import org.graalvm.polyglot.Context;

public class Python2JavaTime {
    public static void main(String[] args) {
        try (Context c = Context.newBuilder("python").allowAllAccess(true).build()) {
            LocalTime t = c.eval("python",
                "from datetime import time\n" +
                "t = time(hour=1, minute=2, second=3, microsecond=456789)\n" +
                "print(t)\n" +
                "t\n"
            ).asTime();

            System.out.println(t);
        }
    }
}

GraalPython's output(commit 77321cc8e & CE 20.3.0):

01:02:03.456789
01:02:03.000456789

It should output two 01:02:03.456789.

Note that the datetime.time of Python has a microsecond field but the java.time.LocalTime of Java has a nanosecond field.