Skip to content

Commit

Permalink
Fix timestamp related Teradata Function product-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fiedukow authored and findepi committed Mar 23, 2018
1 parent e30ed62 commit 3ad71ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
package com.facebook.presto.tests.teradata;

import io.prestodb.tempto.ProductTest;
import org.joda.time.DateTimeZone;
import org.testng.annotations.Test;

import java.sql.Date;
import java.sql.Timestamp;

import static com.facebook.presto.tests.TestGroups.FUNCTIONS;
import static com.facebook.presto.tests.utils.QueryExecutors.onPresto;
import static io.prestodb.tempto.assertions.QueryAssert.Row.row;
import static io.prestodb.tempto.assertions.QueryAssert.assertThat;
import static io.prestodb.tempto.util.DateTimeUtils.parseTimestampInLocalTime;

public class TestTeradataFunctions
extends ProductTest
Expand Down Expand Up @@ -52,7 +53,7 @@ public void testToDate()
public void testToTimestamp()
{
assertThat(onPresto().executeQuery("SELECT to_timestamp('1988/04/08;02:03:04','yyyy/mm/dd;hh24:mi:ss')"))
.contains(row(Timestamp.valueOf("1988-04-08 02:03:04.0")));
.contains(row(parseTimestampInLocalTime("1988-04-08 02:03:04.0", DateTimeZone.forID("Asia/Kathmandu"))));
}

@Test(groups = FUNCTIONS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.facebook.presto.spi.type.DateTimeEncoding.unpackMillisUtc;
import static com.facebook.presto.spi.type.DateTimeEncoding.unpackZoneKey;
import static com.facebook.presto.spi.type.TimeZoneKey.MAX_TIME_ZONE_KEY;
import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY;
import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKeys;
import static com.facebook.presto.teradata.functions.dateformat.DateFormatParser.createDateTimeFormatter;
import static com.google.common.base.Throwables.throwIfInstanceOf;
Expand Down Expand Up @@ -111,8 +112,12 @@ public static long toTimestamp(

private static long parseMillis(ConnectorSession session, Slice dateTime, Slice formatString)
{
TimeZoneKey timeZoneKey = UTC_KEY;
if (session.isLegacyTimestamp()) {
timeZoneKey = session.getTimeZoneKey();
}
DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString)
.withChronology(CHRONOLOGIES[session.getTimeZoneKey().getKey()])
.withChronology(CHRONOLOGIES[timeZoneKey.getKey()])
.withLocale(session.getLocale());

try {
Expand Down

0 comments on commit 3ad71ef

Please sign in to comment.