Refine search
private static Map<String, Object> ingestTimeFields(DateTime ingestTime) { return ImmutableMap.<String, Object>builder() .put("ingest_time", ingestTime.toString()) .put("ingest_time_epoch", ingestTime.getMillis()) .put("ingest_time_second", ingestTime.getSecondOfMinute()) .put("ingest_time_minute", ingestTime.getMinuteOfHour()) .put("ingest_time_hour", ingestTime.getHourOfDay()) .put("ingest_time_day", ingestTime.getDayOfMonth()) .put("ingest_time_month", ingestTime.getMonthOfYear()) .put("ingest_time_year", ingestTime.getYear()) .build(); }
startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth());
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(_dateColumn).toString(); DateTime date = _dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else { partition.put(PARTITION_COLUMN_PREFIX, _prefix); } } if (_withColumnNames) { partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear()); partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth()); } else { partition.put(PARTITION_COLUMN_YEAR, date.getYear()); partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth()); } return partition; } }
/** * Returns a copy of this datetime with the specified time, retaining the date fields. * <p> * If the time is already the time passed in, then <code>this</code> is returned. * <p> * To set a single field use the properties, for example: * <pre> * DateTime set = dt.hourOfDay().setCopy(6); * </pre> * <p> * If the new time is invalid due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param hourOfDay the hour of the day * @param minuteOfHour the minute of the hour * @param secondOfMinute the second of the minute * @param millisOfSecond the millisecond of the second * @return a copy of this datetime with a different time * @throws IllegalArgumentException if any value if invalid */ public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) { Chronology chrono = getChronology(); long localInstant = chrono.withUTC().getDateTimeMillis( getYear(), getMonthOfYear(), getDayOfMonth(), hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); return withMillis(chrono.getZone().convertLocalToUTC(localInstant, false, getMillis())); }
/** * Returns a copy of this datetime with the specified time, retaining the date fields. * <p> * If the time is already the time passed in, then <code>this</code> is returned. * <p> * To set a single field use the properties, for example: * <pre> * DateTime set = dt.hourOfDay().setCopy(6); * </pre> * <p> * If the new time is invalid due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param hourOfDay the hour of the day * @param minuteOfHour the minute of the hour * @param secondOfMinute the second of the minute * @param millisOfSecond the millisecond of the second * @return a copy of this datetime with a different time * @throws IllegalArgumentException if any value if invalid */ public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) { Chronology chrono = getChronology(); long localInstant = chrono.withUTC().getDateTimeMillis( getYear(), getMonthOfYear(), getDayOfMonth(), hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); return withMillis(chrono.getZone().convertLocalToUTC(localInstant, false, getMillis())); }
@Test public void testYearAndMonthDayFormat() { String day = "01"; String month = "08"; int year = 2011; DateTime date = parseDateFromPostgres(year + "-" + month + day, "YYYY-MMDD"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == Integer.parseInt(month) && date.getYear() == year); }
@Test public void testDateDayMonthYearFormat() { String day = "01"; String month = "08"; int year = 2011; DateTime date = parseDateFromPostgres(year + "-" + month + "-" + day, "YYYY-MM-DD"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == Integer.parseInt(month) && date.getYear() == year); }
@Test public void testYearMonthDayFormat() { String day = "01"; String month = "08"; int year = 2011; DateTime date = parseDateFromPostgres(year + "" + month + day, "YYYYMMDD"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == Integer.parseInt(month) && date.getYear() == year); }
@Test public void testDateYearMonthDayFormat() { String day = "05"; String month = "Dec"; int year = 2000; DateTime date = parseDateFromPostgres(day + " " + month + " " + year, "DD Mon YYYY"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == 12 && date.getYear() == year); }
@Test public void testYearMonthNameDayFormat() { String day = "30"; String month = "Nov"; int year = 2000; DateTime date = parseDateFromPostgres(year + "" + month + day, "YYYYMonDD"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == 11 && date.getYear() == year); }
@Test public void testDateMonthDayYearFormat() { int day = 1; int month = 8; int year = 2011; DateTime date = parseDateFromPostgres(month + "/" + day + "/" + year, "MM/DD/YYYY"); Assert.assertTrue(date.getDayOfMonth() == day && date.getMonthOfYear() == month && date.getYear() == year); }
@Test public void testDateDayOfYearYearFormat() { String day = "01"; int year = 2011; DateTime date = parseDateFromPostgres(day + "/" + year, "ddd/YYYY"); Assert.assertTrue(date.getDayOfMonth() == 1 && date.getMonthOfYear() == 1 && date.getYear() == year); }
@Test public void testDateYearMonthNameFormat() { String month = "JUN"; int year = 2000; DateTime date = parseDateFromPostgres(year + " " + month, "YYYY MON"); Assert.assertTrue(date.getMonthOfYear() == 6 && date.getYear() == year); }
@Test public void testDateTimeHoursMinutesSecondsFormat() { String day = "24"; String month = "June"; int year = 2010; int hours = 10; int minutes = 12; DateTime date = parseDateFromPostgres(year + "" + day + month + hours + ":" + minutes + "am", "YYYYDDFMMonthHH12:MIam"); Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) && date.getMonthOfYear() == 6 && date.getYear() == year && date.getHourOfDay() == hours && date.getMinuteOfHour() == minutes); }
return Date.of(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); default: throw new BackendException("Unexpected HCat type " + type + " for value " + pigObj
public DateTime getMidnight() { DateTime time = new DateTime(zone); return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), 0, 0, 0, 0, zone); }
assertFunction("extract(doy FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getDayOfYear()); assertFunction("extract(week FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getWeekOfWeekyear()); assertFunction("extract(month FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear()); assertFunction("extract(quarter FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear() / 4 + 1); assertFunction("extract(year FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getYear()); assertFunction("extract(doy FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getDayOfYear()); assertFunction("extract(week FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getWeekOfWeekyear()); assertFunction("extract(month FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMonthOfYear()); assertFunction("extract(quarter FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMonthOfYear() / 4 + 1); assertFunction("extract(year FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getYear()); assertFunction("extract(timezone_minute FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, 9L); assertFunction("extract(timezone_hour FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, 7L);
public DateTime getCurrentHour() { DateTime time = new DateTime(zone); return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), 0, 0, 0, zone); } }
private int[] getYearAndMonth(int position) { int date[] = new int[2]; DateTime time = new DateTime(); time = time.plusMonths(position - mMonthCount / 2); date[0] = time.getYear(); date[1] = time.getMonthOfYear() - 1; return date; }
new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), now.getHourOfDay(), 30, 0, TZ);