/** * The inverse of {@link #jodaToCalciteDate(DateTime, DateTimeZone)}. * * @param date Calcite style date * @param timeZone session time zone * * @return joda timestamp, with time zone set to the session time zone */ public static DateTime calciteDateToJoda(final int date, final DateTimeZone timeZone) { return DateTimes.EPOCH.plusDays(date).withZoneRetainFields(timeZone); }
/** * The inverse of {@link #jodaToCalciteTimestamp(DateTime, DateTimeZone)}. * * @param timestamp Calcite style timestamp * @param timeZone session time zone * * @return joda timestamp, with time zone set to the session time zone */ public static DateTime calciteTimestampToJoda(final long timestamp, final DateTimeZone timeZone) { return new DateTime(timestamp, DateTimeZone.UTC).withZoneRetainFields(timeZone); }
/** * Calcite expects "TIMESTAMP" types to be an instant that has the expected local time fields if printed as UTC. * * @param dateTime joda timestamp * @param timeZone session time zone * * @return Calcite style millis */ public static long jodaToCalciteTimestamp(final DateTime dateTime, final DateTimeZone timeZone) { return dateTime.withZone(timeZone).withZoneRetainFields(DateTimeZone.UTC).getMillis(); }
private static long toMillis(ReadableInstant time) { DateTime dateTime = time instanceof DateTime ? (DateTime) time : new DateTime(time); DateTime utcDateTime = dateTime.withZoneRetainFields(DateTimeZone.UTC); return utcDateTime.getMillis(); }
public TimestampWritable evaluate(TimestampWritable t) { if (t == null) { return null; } final long originalTimestamp = t.getTimestamp().getTime(); // default final long originalTimestampUTC = new DateTime(originalTimestamp) .withZoneRetainFields(DateTimeZone.UTC).getMillis(); // default -> utc final long newTimestampUTC = granularity.truncate(originalTimestampUTC); // utc final long newTimestamp = new DateTime(newTimestampUTC, DateTimeZone.UTC) .withZoneRetainFields(DateTimeZone.getDefault()).getMillis(); // utc -> default result.setTime(newTimestamp); return result; }
@JsonCreator public PeriodGranularity( @JsonProperty("period") Period period, @JsonProperty("origin") DateTime origin, @JsonProperty("timeZone") DateTimeZone tz ) { this.period = Preconditions.checkNotNull(period, "period can't be null!"); Preconditions.checkArgument(!Period.ZERO.equals(period), "zero period is not acceptable in QueryGranularity!"); this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz); if (origin == null) { // default to origin in given time zone when aligning multi-period granularities this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone()).getMillis(); this.hasOrigin = false; } else { this.origin = origin.getMillis(); this.hasOrigin = true; } this.isCompound = isCompoundPeriod(period); }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final java.sql.Timestamp value = ((TimestampObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue); final DateTime ts = new DateTime(value.getTime()).withZoneRetainFields(DateTimeZone.UTC); ((NullableTimeStampVector) outputVV).getMutator().setSafe(outputIndex, ts.getMillis()); } }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final java.sql.Date value = ((DateObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue); final DateTime date = new DateTime(value.getTime()).withZoneRetainFields(DateTimeZone.UTC); ((NullableDateVector) outputVV).getMutator().setSafe(outputIndex, date.getMillis()); } }
public PeriodGranularity(Period period, DateTime origin, DateTimeZone tz) { this.period = period; this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz); if (origin == null) { // default to origin in given time zone when aligning multi-period granularities this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone()) .getMillis(); this.hasOrigin = false; } else { this.origin = origin.getMillis(); this.hasOrigin = true; } this.isCompound = isCompoundPeriod(period); }
public PeriodGranularity(Period period, DateTime origin, DateTimeZone tz) { this.period = period; this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz); if (origin == null) { // default to origin in given time zone when aligning multi-period granularities this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone()) .getMillis(); this.hasOrigin = false; } else { this.origin = origin.getMillis(); this.hasOrigin = true; } this.isCompound = isCompoundPeriod(period); }
/** * Calcite expects "DATE" types to be number of days from the epoch to the UTC date matching the local time fields. * * @param dateTime joda timestamp * @param timeZone session time zone * * @return Calcite style date */ public static int jodaToCalciteDate(final DateTime dateTime, final DateTimeZone timeZone) { final DateTime date = dateTime.withZone(timeZone).dayOfMonth().roundFloorCopy(); return Days.daysBetween(DateTimes.EPOCH, date.withZoneRetainFields(DateTimeZone.UTC)).getDays(); }
private DateTime parseDateFromPostgres(String date, String pattern) { String jodaFormat = toJodaFormat(pattern); DateTimeFormatter format = forPattern(jodaFormat).withLocale(Locale.US); return parse(date, format).withZoneRetainFields(DateTimeZone.UTC); } }
/** * Translates "literal" (a TIMESTAMP or DATE literal) to milliseconds since the epoch using the provided * session time zone. * * @param literal TIMESTAMP or DATE literal * @param timeZone session time zone * * @return milliseconds time */ public static DateTime calciteDateTimeLiteralToJoda(final RexNode literal, final DateTimeZone timeZone) { final SqlTypeName typeName = literal.getType().getSqlTypeName(); if (literal.getKind() != SqlKind.LITERAL || (typeName != SqlTypeName.TIMESTAMP && typeName != SqlTypeName.DATE)) { throw new IAE("Expected literal but got[%s]", literal.getKind()); } if (typeName == SqlTypeName.TIMESTAMP) { final TimestampString timestampString = (TimestampString) RexLiteral.value(literal); return CALCITE_TIMESTAMP_PARSER.parse(timestampString.toString()).withZoneRetainFields(timeZone); } else if (typeName == SqlTypeName.DATE) { final DateString dateString = (DateString) RexLiteral.value(literal); return CALCITE_DATE_PARSER.parse(dateString.toString()).withZoneRetainFields(timeZone); } else { throw new IAE("Expected TIMESTAMP or DATE but got[%s]", typeName); } }
DateTime ts = new DateTime(((Timestamp) val).getTime()).withZoneRetainFields(DateTimeZone.UTC); long value = ts.getMillis(); for (int i = start; i < end; i++) { DateTime date = new DateTime(((Date)val).getTime()).withZoneRetainFields(DateTimeZone.UTC); long value = date.getMillis(); for (int i = start; i < end; i++) {
public void eval() { long inputMillis = 0; inputMillis = (long) (left.value * 1000L); out.value = new org.joda.time.DateTime(inputMillis).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis(); } }
public void eval() { long inputMillis = 0; inputMillis = (long) (left.value * 1000L); out.value = new org.joda.time.DateTime(inputMillis).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis(); } }
public void eval() { // Get the input byte[] buf1 = new byte[left.end - left.start]; left.buffer.getBytes(left.start, buf1, 0, left.end - left.start); String input = new String(buf1, com.google.common.base.Charsets.UTF_8); out.value = org.joda.time.DateTime.parse(input, format).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis(); } }
@Override public DateTime fromNonNullValue(String s) { DateTime parsedDateTime = DATE_TIME_PARSER.parseDateTime(s); DateTimeZone correctTimeZone = parsedDateTime.getZone(); DateTime utcDateTime = parsedDateTime.withZoneRetainFields(DateTimeZone.UTC); DateTime correctedDateTime = utcDateTime.withZone(correctTimeZone); return correctedDateTime; }
/** * Converts a string in the form of {@code yyyy-MM-dd'T'HH:mm:ss} to an API * date time in the time zone supplied. */ public T toDateTime(String dateTime, String timeZoneId) { return toDateTime(ISODateTimeFormat.dateHourMinuteSecond().parseDateTime(dateTime) .withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)))); }
private void writeDateTime(long readDateTime, final MapOrListWriterImpl writer, String fieldName, boolean isList) { DateTime date = new DateTime(readDateTime); TimeStampWriter dt; if (isList == false) { dt = writer.map.timeStamp(fieldName); } else { dt = writer.list.timeStamp(); } dt.writeTimeStamp(date.withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis()); }