Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.type;
 
 
 
 import static com.facebook.presto.metadata.OperatorType.ADD;
 import static com.facebook.presto.metadata.OperatorType.SUBTRACT;
 import static com.facebook.presto.spi.type.DateTimeEncoding.unpackMillisUtc;
 import static com.facebook.presto.spi.type.DateTimeEncoding.updateMillisUtc;
 import static com.facebook.presto.util.DateTimeZoneIndex.getChronology;
 import static com.facebook.presto.util.DateTimeZoneIndex.unpackChronology;
 
 public final class DateTimeOperators
 {
     private static final DateTimeField MILLIS_OF_DAY = ISOChronology.getInstanceUTC().millisOfDay();
     private static final DateTimeField MONTH_OF_YEAR_UTC = ISOChronology.getInstanceUTC().monthOfYear();
 
     private DateTimeOperators()
     {
     }
 
     @ScalarOperator()
     public static long datePlusIntervalDayToSecond(@SqlType(.long left, @SqlType(.long right)
     {
         if (.get(right) != 0) {
             throw new IllegalArgumentException("Can not add hour, minutes or seconds to a Date");
         }
         return left + ..toDays(right);
     }
 
     @ScalarOperator()
     public static long intervalDayToSecondPlusDate(@SqlType(.long left, @SqlType(.long right)
     {
         if (.get(left) != 0) {
             throw new IllegalArgumentException("Can not add hour, minutes or seconds to a Date");
         }
         return ..toDays(left) + right;
     }
 
     @ScalarOperator()
     public static long timePlusIntervalDayToSecond(ConnectorSession session, @SqlType(.long left, @SqlType(.long right)
     {
         return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right);
     }
 
     @ScalarOperator()
     public static long intervalDayToSecondPlusTime(ConnectorSession session, @SqlType(.long left, @SqlType(.long right)
     {
         return modulo24Hour(getChronology(session.getTimeZoneKey()), left + right);
     }
 
     @ScalarOperator()
     {
         return updateMillisUtc((longmodulo24Hour(unpackChronology(left), unpackMillisUtc(left) + right), left);
     }
 
     @ScalarOperator()
     {
         return updateMillisUtc((longmodulo24Hour(unpackChronology(right), left + unpackMillisUtc(right)), right);
     }
 
     @ScalarOperator()
     public static long timestampPlusIntervalDayToSecond(@SqlType(.long left, @SqlType(.long right)
     {
         return left + right;
     }
 
     @ScalarOperator()
     public static long intervalDayToSecondPlusTimestamp(@SqlType(.long left, @SqlType(.long right)
     {
         return left + right;
    }
    {
        return updateMillisUtc(unpackMillisUtc(left) + rightleft);
    }
    {
        return updateMillisUtc(left + unpackMillisUtc(right), right);
    }
    public static long datePlusIntervalYearToMonth(@SqlType(.long left, @SqlType(.long right)
    {
        long millis = .add(..toMillis(left), right);
        return ..toDays(millis);
    }
    public static long intervalYearToMonthPlusDate(@SqlType(.long left, @SqlType(.long right)
    {
        long millis = .add(..toMillis(right), left);
        return ..toDays(millis);
    }
    public static long timePlusIntervalYearToMonth(@SqlType(.long left, @SqlType(.long right)
    {
        return left;
    }
    public static long intervalYearToMonthPlusTime(@SqlType(.long left, @SqlType(.long right)
    {
        return right;
    }
    {
        return left;
    }
    {
        return right;
    }
    {
        return getChronology(session.getTimeZoneKey()).monthOfYear().add(leftright);
    }
    {
        return getChronology(session.getTimeZoneKey()).monthOfYear().add(rightleft);
    }
    {
        return updateMillisUtc(unpackChronology(left).monthOfYear().add(unpackMillisUtc(left), right), left);
    }
    {
        return updateMillisUtc(unpackChronology(right).monthOfYear().add(unpackMillisUtc(right), left), right);
    }
    public static long dateMinusIntervalDayToSecond(@SqlType(.long left, @SqlType(.long right)
    {
        if (.get(right) != 0) {
            throw new IllegalArgumentException("Can not subtract hour, minutes or seconds from a Date");
        }
        return left - ..toDays(right);
    }
    public static long timeMinusIntervalDayToSecond(ConnectorSession session, @SqlType(.long left, @SqlType(.long right)
    {
        return modulo24Hour(getChronology(session.getTimeZoneKey()), left - right);
    }
    {
        return updateMillisUtc((longmodulo24Hour(unpackChronology(left), unpackMillisUtc(left) - right), left);
    }
    {
        return left - right;
    }
    {
        return updateMillisUtc(unpackMillisUtc(left) - rightleft);
    }
    public static long dateMinusIntervalYearToMonth(ConnectorSession session, @SqlType(.long left, @SqlType(.long right)
    {
        long millis = .add(..toMillis(left), -right);
        return ..toDays(millis);
    }
    public static long timeMinusIntervalYearToMonth(@SqlType(.long left, @SqlType(.long right)
    {
        return left;
    }
    {
        return left;
    }
    {
        return getChronology(session.getTimeZoneKey()).monthOfYear().add(left, -right);
    }
    {
        long dateTimeWithTimeZone = unpackChronology(left).monthOfYear().add(unpackMillisUtc(left), -right);
        return updateMillisUtc(dateTimeWithTimeZoneleft);
    }
    public static int modulo24Hour(ISOChronology chronologylong millis)
    {
        return chronology.millisOfDay().get(millis) - chronology.getZone().getOffset(millis);
    }
New to GrepCode? Check out our FAQ X