Example #1
0
 @Description("second of the minute of the given time")
 @ScalarFunction("second")
 @SqlType(BigintType.class)
 public static long secondFromTimeWithTimeZone(@SqlType(TimeWithTimeZoneType.class) long time) {
   // Time is effectively UTC so no need for a custom chronology
   return SECOND_OF_MINUTE.get(unpackMillisUtc(time));
 }
Example #2
0
 @Description("second of the minute of the given timestamp")
 @ScalarFunction("second")
 @SqlType(BigintType.class)
 public static long secondFromTimestamp(@SqlType(TimestampType.class) long timestamp) {
   // Time is effectively UTC so no need for a custom chronology
   return SECOND_OF_MINUTE.get(timestamp);
 }
 public int get(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.get(localInstant);
 }
 static int parseDayOfWeek(String str) {
   DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek();
   return field.get(field.set(0, str, Locale.ENGLISH));
 }
 static int parseMonth(String str) {
   DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear();
   return field.get(field.set(0, str, Locale.ENGLISH));
 }
Example #6
0
 @Description("year of the given date")
 @ScalarFunction("year")
 @SqlType(BigintType.class)
 public static long yearFromDate(@SqlType(DateType.class) long date) {
   return YEAR.get(date);
 }
Example #7
0
 @Description("quarter of the year of the given date")
 @ScalarFunction("quarter")
 @SqlType(BigintType.class)
 public static long quarterFromDate(@SqlType(DateType.class) long date) {
   return QUARTER.get(date);
 }
Example #8
0
 @Description("month of the year of the given date")
 @ScalarFunction("month")
 @SqlType(BigintType.class)
 public static long monthFromDate(@SqlType(DateType.class) long date) {
   return MONTH_OF_YEAR.get(date);
 }
Example #9
0
 @Description("week of the year of the given date")
 @ScalarFunction(value = "week", alias = "week_of_year")
 @SqlType(BigintType.class)
 public static long weekFromDate(@SqlType(DateType.class) long date) {
   return WEEK_OF_YEAR.get(date);
 }
Example #10
0
 @Description("day of the year of the given date")
 @ScalarFunction(value = "day_of_year", alias = "doy")
 @SqlType(BigintType.class)
 public static long dayOfYearFromDate(@SqlType(DateType.class) long date) {
   return DAY_OF_YEAR.get(date);
 }
Example #11
0
 @Description("day of the month of the given date")
 @ScalarFunction(value = "day", alias = "day_of_month")
 @SqlType(BigintType.class)
 public static long dayFromDate(@SqlType(DateType.class) long date) {
   return DAY_OF_MONTH.get(date);
 }
Example #12
0
 @Description("day of the week of the given date")
 @ScalarFunction(value = "day_of_week", alias = "dow")
 @SqlType(BigintType.class)
 public static long dayOfWeekFromDate(@SqlType(DateType.class) long date) {
   return DAY_OF_WEEK.get(date);
 }
 /**
  * Get the value of one of the fields of a datetime.
  *
  * <p>This could be used to get a field using a different Chronology. For example:
  *
  * <pre>
  * Instant dt = new Instant();
  * int gjYear = dt.get(Chronology.getCoptic().year());
  * </pre>
  *
  * @param field the DateTimeField to use, not null
  * @return the value
  * @throws IllegalArgumentException if the field is null
  */
 public int get(DateTimeField field) {
   if (field == null) {
     throw new IllegalArgumentException("The DateTimeField must not be null");
   }
   return field.get(getMillis());
 }