/** * Gets the datetime zone as a string, which is simply its ID. * @return the id of the zone */ public String toString() { return getID(); }
private CachedDateTimeZone(DateTimeZone zone) { super(zone.getID()); iZone = zone; }
/** * Gets the datetime zone as a string, which is simply its ID. * @return the id of the zone */ public String toString() { return getID(); }
@Override public void serialize( DateTimeZone dateTimeZone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider ) throws IOException { jsonGenerator.writeString(dateTimeZone.getID()); } }
/** * Gets a hash code compatible with equals. * * @return suitable hashcode */ public int hashCode() { return 57 + getID().hashCode(); }
public void printTo( Appendable appendable, long instant, Chronology chrono, int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException { appendable.append(displayZone != null ? displayZone.getID() : ""); }
/** * Gets a debugging toString. * * @return a debugging string */ public String toString() { String str = "ISOChronology"; DateTimeZone zone = getZone(); if (zone != null) { str = str + '[' + zone.getID() + ']'; } return str; }
/** * Gets a debugging toString. * * @return a debugging string */ public String toString() { String str = "BuddhistChronology"; DateTimeZone zone = getZone(); if (zone != null) { str = str + '[' + zone.getID() + ']'; } return str; }
public static long packDateTimeWithZone(DateTime dateTime) { return DateTimeEncoding.packDateTimeWithZone(dateTime.getMillis(), dateTime.getZone().getID()); }
/** * A debugging string for the chronology. * * @return the debugging string */ public String toString() { return "ZonedChronology[" + getBase() + ", " + getZone().getID() + ']'; }
private void verifyJvmTimeZone() { if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) { throw new PrestoException(HIVE_TIMEZONE_MISMATCH, format( "To write Hive data, your JVM timezone must match the Hive storage timezone. Add -Duser.timezone=%s to your JVM arguments.", timeZone.getID())); } }
@Test public void testFormatDateCanImplicitlyAddTimeZoneToTimestampLiteral() { assertFunction("format_datetime(" + TIMESTAMP_LITERAL + ", 'YYYY/MM/dd HH:mm ZZZZ')", VARCHAR, "2001/08/22 03:04 " + DATE_TIME_ZONE.getID()); }
@Test public void testCastToTimeWithTimeZone() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY)); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, "03:04:05.321 " + DATE_TIME_ZONE.getID()); }
@Test public void testCastToTimestampWithTimeZone() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), DATE_TIME_ZONE.toTimeZone())); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, "2001-01-22 03:04:05.321 " + DATE_TIME_ZONE.getID()); }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }
public static DruidExpression applyTimeExtract( final DruidExpression timeExpression, final TimestampExtractExprMacro.Unit unit, final DateTimeZone timeZone ) { return DruidExpression.fromFunctionCall( "timestamp_extract", ImmutableList.of( timeExpression, DruidExpression.fromExpression(DruidExpression.stringLiteral(unit.name())), DruidExpression.fromExpression(DruidExpression.stringLiteral(timeZone.getID())) ) ); }
@Test public void testCurrentTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } }
@Test public void testCurrentTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } }
private static DruidExpression castDateTimeToChar( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName fromType ) { return DruidExpression.fromFunctionCall( "timestamp_format", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.stringLiteral(dateTimeFormatString(fromType))), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); }
public long set(long instant, int value) { long localInstant = iZone.convertUTCToLocal(instant); localInstant = iField.set(localInstant, value); long result = iZone.convertLocalToUTC(localInstant, false, instant); if (get(result) != value) { IllegalInstantException cause = new IllegalInstantException(localInstant, iZone.getID()); IllegalFieldValueException ex = new IllegalFieldValueException(iField.getType(), Integer.valueOf(value), cause.getMessage()); ex.initCause(cause); throw ex; } return result; }