Skip to content

Instantly share code, notes, and snippets.

@losipiuk
Created November 27, 2017 15:12
Show Gist options
  • Save losipiuk/a02aa96330a3f9d3304feaec90fae029 to your computer and use it in GitHub Desktop.
Save losipiuk/a02aa96330a3f9d3304feaec90fae029 to your computer and use it in GitHub Desktop.
@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