@Deprecated public static String printTimeWithoutTimeZone(TimeZoneKey timeZoneKey, long value) { return TIME_FORMATTER.withZone(getDateTimeZone(timeZoneKey)).print(value); }
/** * Parse a string (optionally containing a zone) as a value of TIMESTAMP WITH TIME ZONE type. * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP WITH TIME ZONE * {@code 2000-01-01T01:23:00 <provided zone>} and {@code "2000-01-01 01:23:00 +01:23"} * is parsed to TIMESTAMP WITH TIME ZONE {@code 2000-01-01T01:23:00.000+01:23}. * * @return stack representation of TIMESTAMP WITH TIME ZONE type */ public static long parseTimestampWithTimeZone(TimeZoneKey timeZoneKey, String timestampWithTimeZone) { DateTime dateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).withOffsetParsed().parseDateTime(timestampWithTimeZone); return packDateTimeWithZone(dateTime); }
public static void assertTimeZone(String zoneId, DateTimeZone dateTimeZone) { long dateTimeWithTimeZone = packDateTimeWithZone(new DateTime(42, dateTimeZone)); assertEquals(packDateTimeWithZone((long) 42, dateTimeZone.toTimeZone().getID()), dateTimeWithTimeZone); DateTimeZone unpackedZone = unpackDateTimeZone(dateTimeWithTimeZone); assertDateTimeZoneEquals(zoneId, unpackedZone); }
public static String printTimestampWithTimeZone(long timestampWithTimeZone) { ISOChronology chronology = unpackChronology(timestampWithTimeZone); long millis = unpackMillisUtc(timestampWithTimeZone); return TIMESTAMP_WITH_TIME_ZONE_FORMATTER.withChronology(chronology).print(millis); }
@Deprecated public static String printTimestampWithoutTimeZone(TimeZoneKey timeZoneKey, long timestamp) { return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).print(timestamp); }
/** * Parse a string containing a zone as a value of TIME WITH TIME ZONE type. * <p> * For example: {@code "01:23:00 +01:23"} is parsed to TIME WITH TIME ZONE * {@code 01:23:00+01:23} and {@code "01:23:00"} is rejected. * * @return stack representation of TIME WITH TIME ZONE type */ public static long parseTimeWithTimeZone(String timeWithTimeZone) { DateTime dateTime = TIME_WITH_TIME_ZONE_FORMATTER.parseDateTime(timeWithTimeZone); return packDateTimeWithZone(dateTime); }
public static String printTimeWithTimeZone(long timeWithTimeZone) { DateTimeZone timeZone = unpackDateTimeZone(timeWithTimeZone); long millis = unpackMillisUtc(timeWithTimeZone); return TIME_WITH_TIME_ZONE_FORMATTER.withZone(timeZone).print(millis); }
@Description("time zone hour of the given timestamp") @ScalarFunction("timezone_hour") @SqlType(StandardTypes.BIGINT) public static long timeZoneHourFromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { return extractZoneOffsetMinutes(timestampWithTimeZone) / 60; }
@ScalarFunction("date") @ScalarOperator(CAST) @SqlType(StandardTypes.DATE) public static long castToDate(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long value) { // round down the current timestamp to days ISOChronology chronology = unpackChronology(value); long date = chronology.dayOfYear().roundFloor(unpackMillisUtc(value)); // date is currently midnight in timezone of the original value // convert to UTC long millis = date + chronology.getZone().getOffset(date); return TimeUnit.MILLISECONDS.toDays(millis); }
public static ISOChronology unpackChronology(long timestampWithTimeZone) { return getChronology(unpackZoneKey(timestampWithTimeZone)); }
/** * Parse a string (optionally containing a zone) as a value of either TIMESTAMP or TIMESTAMP WITH TIME ZONE type. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP {@code 2000-01-01T01:23:00} * and {@code "2000-01-01 01:23:00 +01:23"} is parsed to TIMESTAMP WITH TIME ZONE * {@code 2000-01-01T01:23:00.000+01:23}. * * @return stack representation of TIMESTAMP or TIMESTAMP WITH TIME ZONE type, depending on input */ public static long parseTimestampLiteral(String value) { try { DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value); return packDateTimeWithZone(dateTime); } catch (Exception e) { return TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.parseMillis(value); } }
public static String printTimeWithTimeZone(long timeWithTimeZone) { DateTimeZone timeZone = unpackDateTimeZone(timeWithTimeZone); long millis = unpackMillisUtc(timeWithTimeZone); return TIME_WITH_TIME_ZONE_FORMATTER.withZone(timeZone).print(millis); }
@Description("time zone minute of the given timestamp") @ScalarFunction("timezone_minute") @SqlType(StandardTypes.BIGINT) public static long timeZoneMinuteFromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { return extractZoneOffsetMinutes(timestampWithTimeZone) % 60; }
/** * Parse a string (without a zone) as a value of TIME type, interpreted in {@code timeZoneKey} zone. * * @return stack representation of legacy TIME type */ @Deprecated public static long parseTimeWithoutTimeZone(TimeZoneKey timeZoneKey, String value) { return TIME_FORMATTER.withZone(getDateTimeZone(timeZoneKey)).parseMillis(value); }
/** * Parse a string (optionally containing a zone) as a value of either TIMESTAMP or TIMESTAMP WITH TIME ZONE type. * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone. * * @return stack representation of legacy TIMESTAMP or TIMESTAMP WITH TIME ZONE type, depending on input */ @Deprecated public static long parseTimestampLiteral(TimeZoneKey timeZoneKey, String value) { try { DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value); return packDateTimeWithZone(dateTime); } catch (RuntimeException e) { return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value); } }
@Description("minute of the hour of the given time") @ScalarFunction("minute") @SqlType(StandardTypes.BIGINT) public static long minuteFromTimeWithTimeZone(@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone) { return unpackChronology(timeWithTimeZone).minuteOfHour().get(unpackMillisUtc(timeWithTimeZone)); }
public static void assertTimeZone(String zoneId, DateTimeZone dateTimeZone) { long dateTimeWithTimeZone = packDateTimeWithZone(new DateTime(42, dateTimeZone)); assertEquals(packDateTimeWithZone((long) 42, dateTimeZone.toTimeZone().getID()), dateTimeWithTimeZone); DateTimeZone unpackedZone = unpackDateTimeZone(dateTimeWithTimeZone); assertDateTimeZoneEquals(zoneId, unpackedZone); }
/** * Parse a string (optionally containing a zone) as a value of TIMESTAMP type. * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone. * * @return stack representation of legacy TIMESTAMP type */ @Deprecated public static long parseTimestampWithoutTimeZone(TimeZoneKey timeZoneKey, String value) { return TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value); }
public static long parseTimeWithTimeZone(String timeWithTimeZone) { DateTime dateTime = TIME_WITH_TIME_ZONE_FORMATTER.parseDateTime(timeWithTimeZone); return packDateTimeWithZone(dateTime); }
@Description("time zone hour of the given timestamp") @ScalarFunction("timezone_hour") @SqlType(StandardTypes.BIGINT) public static long timeZoneHourFromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { return extractZoneOffsetMinutes(timestampWithTimeZone) / 60; }