Created
November 27, 2017 15:12
-
-
Save losipiuk/a02aa96330a3f9d3304feaec90fae029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Description("current time with time zone") | |
@ScalarFunction | |
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) | |
public static long currentTime(ConnectorSession session) | |
{ | |
// We do all calculation in UTC, as session.getStartTime() is in UTC | |
// and we need to have UTC millis for packDateTimeWithZone | |
long millis = UTC_CHRONOLOGY.millisOfDay().get(session.getStartTime()); | |
if (!session.isLegacyTimestamp()) { | |
// However, those UTC millis are pointing to the correct UTC timestamp | |
// Our TIME WITH TIME ZONE representation does use UTC 1970-01-01 representation | |
// So we have to hack here in order to get valid representation | |
// of TIME WITH TIME ZONE | |
millis -= valueToSessionTimeZoneOffsetDiff(session.getStartTime(), getDateTimeZone(session.getTimeZoneKey())); | |
} | |
return packDateTimeWithZone(millis, session.getTimeZoneKey()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment