use of org.joda.time.chrono.ISOChronology in project presto by prestodb.
the class DateTimeFunctions method addFieldValueTimeWithTimeZone.
@Description("add the specified amount of time to the given time")
@LiteralParameters("x")
@ScalarFunction("date_add")
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE)
public static long addFieldValueTimeWithTimeZone(@SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone) {
ISOChronology chronology = unpackChronology(timeWithTimeZone);
long millis = modulo24Hour(chronology, getTimeField(chronology, unit).add(unpackMillisUtc(timeWithTimeZone), toIntExact(value)));
return updateMillisUtc(millis, timeWithTimeZone);
}
use of org.joda.time.chrono.ISOChronology in project presto by prestodb.
the class DateTimeFunctions method currentDate.
@Description("current date")
@ScalarFunction
@SqlType(StandardTypes.DATE)
public static long currentDate(ConnectorSession session) {
ISOChronology chronology = getChronology(session.getTimeZoneKey());
// It is ok for this method to use the Object interfaces because it is constant folded during
// plan optimization
DateTime currentDateTime = new DateTime(session.getStartTime(), chronology).withTimeAtStartOfDay();
DateTime baseDateTime = new DateTime(1970, 1, 1, 0, 0, chronology).withTimeAtStartOfDay();
return Days.daysBetween(baseDateTime, currentDateTime).getDays();
}
use of org.joda.time.chrono.ISOChronology in project presto by prestodb.
the class DateOperators method castToTimestampWithTimeZone.
@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long castToTimestampWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) {
long utcMillis = TimeUnit.DAYS.toMillis(value);
// date is encoded as milliseconds at midnight in UTC
// convert to midnight if the session timezone
ISOChronology chronology = getChronology(session.getTimeZoneKey());
long millis = utcMillis - chronology.getZone().getOffset(utcMillis);
return packDateTimeWithZone(millis, session.getTimeZoneKey());
}
use of org.joda.time.chrono.ISOChronology in project presto by prestodb.
the class DateOperators method castToTimestamp.
@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP)
public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) {
long utcMillis = TimeUnit.DAYS.toMillis(value);
// date is encoded as milliseconds at midnight in UTC
// convert to midnight if the session timezone
ISOChronology chronology = getChronology(session.getTimeZoneKey());
return utcMillis - chronology.getZone().getOffset(utcMillis);
}
use of org.joda.time.chrono.ISOChronology in project presto by prestodb.
the class TimestampOperators method castToDate.
@ScalarFunction("date")
@ScalarOperator(CAST)
@SqlType(StandardTypes.DATE)
public static long castToDate(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long value) {
// round down the current timestamp to days
ISOChronology chronology = getChronology(session.getTimeZoneKey());
long date = chronology.dayOfYear().roundFloor(value);
// date is currently midnight in timezone of the session
// convert to UTC
long millis = date + chronology.getZone().getOffset(date);
return TimeUnit.MILLISECONDS.toDays(millis);
}
Aggregations