Skip to content

Commit

Permalink
Use non-JVM timezone in TestDateTimeFunctionsBase
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk authored and findepi committed Mar 23, 2018
1 parent 3ad71ef commit 0ee7a18
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.testng.annotations.Test;

import static com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKey;
import static com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.VarcharType.createVarcharType;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;

public class TestDateTimeFunctions
extends TestDateTimeFunctionsBase
Expand Down Expand Up @@ -56,7 +56,7 @@ public void testLocalTime()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "15:45:00.000");
localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "14:30:00.000");
}
}

Expand All @@ -65,6 +65,9 @@ public void testCurrentTime()
throws Exception
{
Session localSession = Session.builder(session)
// we use Asia/Kathmandu here to test the difference in semantic change of current_time
// between legacy and non-legacy timestamp
.setTimeZoneKey(getTimeZoneKey("Asia/Kathmandu"))
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
Expand All @@ -79,7 +82,7 @@ public void testLocalTimestamp()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 15:45:00.000");
localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 14:30:00.000");
}
}

Expand All @@ -90,8 +93,8 @@ public void testCurrentTimestamp()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 15:45:00.000 Asia/Kathmandu");
localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 15:45:00.000 Asia/Kathmandu");
localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul");
localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
public abstract class TestDateTimeFunctionsBase
extends AbstractTestFunctions
{
protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Asia/Kathmandu");
protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Asia/Kabul");
protected static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY);
protected static final DateTimeZone UTC_TIME_ZONE = getDateTimeZone(UTC_KEY);
protected static final DateTimeZone DATE_TIME_ZONE_NUMERICAL = getDateTimeZone(getTimeZoneKey("+05:45"));
protected static final DateTimeZone DATE_TIME_ZONE_NUMERICAL = getDateTimeZone(getTimeZoneKey("+04:30"));
protected static final TimeZoneKey WEIRD_ZONE_KEY = getTimeZoneKey("+07:09");
protected static final DateTimeZone WEIRD_ZONE = getDateTimeZone(WEIRD_ZONE_KEY);

Expand All @@ -100,7 +100,7 @@ public abstract class TestDateTimeFunctionsBase
protected static final DateTime LEGACY_TIMESTAMP = new DateTime(2001, 8, 22, 3, 4, 5, 321, DATE_TIME_ZONE);
protected static final DateTime TIMESTAMP_WITH_NUMERICAL_ZONE = new DateTime(2001, 8, 22, 3, 4, 5, 321, DATE_TIME_ZONE_NUMERICAL);
protected static final String TIMESTAMP_LITERAL = "TIMESTAMP '2001-08-22 03:04:05.321'";
protected static final String TIMESTAMP_ISO8601_STRING = "2001-08-22T03:04:05.321+05:45";
protected static final String TIMESTAMP_ISO8601_STRING = "2001-08-22T03:04:05.321+04:30";
protected static final String TIMESTAMP_ISO8601_STRING_NO_TIME_ZONE = "2001-08-22T03:04:05.321";
protected static final DateTime WEIRD_TIMESTAMP = new DateTime(2001, 8, 22, 3, 4, 5, 321, WEIRD_ZONE);
protected static final String WEIRD_TIMESTAMP_LITERAL = "TIMESTAMP '2001-08-22 03:04:05.321 +07:09'";
Expand Down Expand Up @@ -271,9 +271,9 @@ public void testPartFunctions()
assertFunction("month(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear());
assertFunction("quarter(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear() / 4 + 1);
assertFunction("year(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getYear());
assertFunction("timezone_hour(" + TIMESTAMP_LITERAL + ")", BIGINT, 5L);
assertFunction("timezone_hour(localtimestamp)", BIGINT, 5L);
assertFunction("timezone_hour(current_timestamp)", BIGINT, 5L);
assertFunction("timezone_hour(" + TIMESTAMP_LITERAL + ")", BIGINT, 4L);
assertFunction("timezone_hour(localtimestamp)", BIGINT, 4L);
assertFunction("timezone_hour(current_timestamp)", BIGINT, 4L);

assertFunction("second(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getSecondOfMinute());
assertFunction("minute(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMinuteOfHour());
Expand Down Expand Up @@ -999,8 +999,8 @@ public void testTimeWithTimeZoneAtTimeZone()
TIME_WITH_TIME_ZONE,
new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 4, 15, 0, 0, UTC_TIME_ZONE).getMillis(), TimeZoneKey.UTC_KEY));

// Noop on Asia/Kathmandu
assertFunction("at_timezone(TIME '10:00 Asia/Kathmandu', 'Asia/Kathmandu')",
// Noop on Asia/Kabul
assertFunction("at_timezone(TIME '10:00 Asia/Kabul', 'Asia/Kabul')",
TIME_WITH_TIME_ZONE,
new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 10, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.testng.annotations.Test;

import static com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKey;
import static com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.facebook.presto.spi.type.VarcharType.createVarcharType;
Expand All @@ -44,7 +45,7 @@ public void toIso8601ReturnsTimezoneForTimestampWithoutTimeZone()
@Test
public void testFormatDateCanImplicitlyAddTimeZoneToTimestampLiteral()
{
assertFunction("format_datetime(" + TIMESTAMP_LITERAL + ", 'YYYY/MM/dd HH:mm ZZZZ')", VARCHAR, "2001/08/22 03:04 Asia/Kathmandu");
assertFunction("format_datetime(" + TIMESTAMP_LITERAL + ", 'YYYY/MM/dd HH:mm ZZZZ')", VARCHAR, "2001/08/22 03:04 Asia/Kabul");
}

@Test
Expand All @@ -57,7 +58,7 @@ public void testLocalTime()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "15:30:00.000");
localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "14:30:00.000");
}
}

Expand All @@ -67,7 +68,9 @@ public void testCurrentTime()
{
Session localSession = testSessionBuilder()
.setSystemProperty("legacy_timestamp", "true")
.setTimeZoneKey(TIME_ZONE_KEY)
// we use Asia/Kathmandu here to test the difference in semantic change of current_time
// between legacy and non-legacy timestamp
.setTimeZoneKey(getTimeZoneKey("Asia/Kathmandu"))
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
Expand All @@ -84,7 +87,7 @@ public void testLocalTimestamp()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 15:45:00.000");
localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 14:30:00.000");
}
}

Expand All @@ -97,8 +100,8 @@ public void testCurrentTimestamp()
.setStartTime(new DateTime(2017, 3, 1, 10, 0, 0, 0, DateTimeZone.UTC).getMillis())
.build();
try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) {
localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 15:45:00.000 Asia/Kathmandu");
localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 15:45:00.000 Asia/Kathmandu");
localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul");
localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul");
}
}
}

0 comments on commit 0ee7a18

Please sign in to comment.