Skip to content

Commit

Permalink
Fix Date.kt:
Browse files Browse the repository at this point in the history
- Use an Instant internally, as LocalDateTime is lossy in the case of a DST change
- Copied the parser from Android JRE.
- Lots of fixes / adjustments

Enable j2kt in the DateTimeTestSuite

PiperOrigin-RevId: 588012812
  • Loading branch information
stefanhaustein authored and copybara-github committed Dec 5, 2023
1 parent edbfe8a commit ed7b450
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions jre/javatests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ j2kt_native_library(
srcs = [
"com/google/j2cl/jre/BigDecimalSuite.java",
"com/google/j2cl/jre/BigIntegerSuite.java",
"com/google/j2cl/jre/DateTimeSuite.java",
"com/google/j2cl/jre/EmulSuite.java",
"com/google/j2cl/jre/java/util/ComparatorTest.java",
"com/google/j2cl/jre/java/util/DateTest.java",
"com/google/j2cl/jre/java/util/EmulTestBase.java",
"com/google/j2cl/jre/java/util/ObjectsTest.java",
"com/google/j2cl/jre/java/util/RandomTest.java",
Expand All @@ -66,6 +68,7 @@ j2kt_native_library(
"com/google/j2cl/jre/java/math/*.java",
"com/google/j2cl/jre/java/nio/charset/*.java",
"com/google/j2cl/jre/java/security/*.java",
"com/google/j2cl/jre/java/sql/*.java",
]),
deps = [
"//jre/java:javaemul_internal_annotations-j2kt-native",
Expand Down Expand Up @@ -151,6 +154,7 @@ j2cl_multi_test(

j2cl_multi_test(
name = "DateTimeSuite",
enable_kt_native = True,
test_class = "com.google.j2cl.jre.DateTimeSuite",
deps = [":emul_tests_lib"],
)
Expand Down
6 changes: 5 additions & 1 deletion jre/javatests/com/google/j2cl/jre/java/sql/SqlTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.j2cl.jre.java.sql;

import com.google.j2cl.jre.testing.J2ktIncompatible;
import java.sql.Time;
import junit.framework.TestCase;

Expand Down Expand Up @@ -79,14 +80,17 @@ public void testUnimplementedFunctions() {
}
}

public void testParse() {
@J2ktIncompatible // Not nullable according to Jspecify
public void testParseNull() {
try {
Time.parse(null);
fail("Should have thrown exception");
} catch (IllegalArgumentException e) {
// Expected
}
}

public void testParse() {
try {
Time.parse("");
} catch (IllegalArgumentException e) {
Expand Down
8 changes: 6 additions & 2 deletions jre/javatests/com/google/j2cl/jre/java/util/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.j2cl.jre.java.util;

import com.google.j2cl.jre.testing.J2ktIncompatible;
import com.google.j2cl.jre.testing.TestUtils;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -358,15 +359,18 @@ public void testInvalidDateForMonth() {
assertEquals(dateWithThirtyDays.getDate(), newDayNum - numDaysInOldMonth);
}

/** Testing for public static long java.util.Date.parse(java.lang.String). */
public void testParse() {
@J2ktIncompatible // Not nullable according to Jspecify
public void testParseNull() {
try {
Date.parse(null);
fail("Should have thrown exception");
} catch (IllegalArgumentException e) {
// Expected
}
}

/** Testing for public static long java.util.Date.parse(java.lang.String). */
public void testParse() {
try {
Date.parse("");
} catch (IllegalArgumentException e) {
Expand Down

0 comments on commit ed7b450

Please sign in to comment.