Skip to content

Commit

Permalink
[core] Fix TypeUtils test with local datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
atallahade committed Feb 10, 2025
1 parent 323f66d commit 668c353
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
Expand All @@ -36,11 +38,24 @@
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.TimeZone;

import static org.assertj.core.api.Assertions.assertThat;

/** Test for {@link TypeUtils}. */
public class TypeUtilsTest {
private static TimeZone originalTimeZone;

@BeforeAll
public static void setUp() {
originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));
}

@AfterAll
public static void tearDown() {
TimeZone.setDefault(originalTimeZone);
}

@Test
public void testCastFromString() {
Expand Down Expand Up @@ -210,7 +225,11 @@ public void testLocalZonedTimestampCastFromString() {
String value = "2017-12-12 09:30:00";
Object result = TypeUtils.castFromString(value, DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE());
Timestamp expected =
Timestamp.fromLocalDateTime(LocalDateTime.parse("2017-12-12T09:30:00"));
Timestamp.fromEpochMillis(
LocalDateTime.parse("2017-12-12T09:30:00")
.atZone(TimeZone.getTimeZone("Asia/Tokyo").toZoneId())
.toEpochSecond()
* 1000);
assertThat(result).isEqualTo(expected);
}

Expand Down

0 comments on commit 668c353

Please sign in to comment.