From 4fa35e868882b70bd4fd542f6137ef168778c9d3 Mon Sep 17 00:00:00 2001 From: Christoph Aschwanden Date: Sun, 12 Feb 2023 08:52:36 +0100 Subject: [PATCH] classlib: fix issue with Date.UTC year Co-authored-by: noblemaster --- .../main/java/org/teavm/classlib/java/util/TDate.java | 2 +- .../java/org/teavm/classlib/java/util/DateTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java b/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java index 80807fb64..e9c14b093 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java @@ -92,7 +92,7 @@ public class TDate implements TComparable { if (PlatformDetector.isLowLevel()) { return initUtcDateLowLevel(year, month, date, hrs, min, sec); } else { - return (long) JSDate.UTC(year, month, date, hrs, min, sec); + return (long) JSDate.UTC(year + 1900, month, date, hrs, min, sec); } } diff --git a/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java b/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java index 90a18879b..e3e16436d 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java @@ -34,4 +34,14 @@ public class DateTest { assertEquals(4, date.getDate()); assertEquals(115, date.getYear()); } + + @SuppressWarnings("deprecation") + @Test + public void setsUTC() { + long epochTime = Date.UTC(2023, 1, 20, 10, 0, 0); + Date date = new Date(epochTime); + assertEquals(2023, date.getYear()); + assertEquals(1, date.getMonth()); + assertEquals(20, date.getDate()); + } }