private static DateTime getDayBucket(DateTime observationTime) { return observationTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
private DateTime parseDateTime(final String scheduleDate, final String scheduleTime) { // scheduleTime: 12,00,pm,PDT final String[] parts = scheduleTime.split(",", -1); int hour = Integer.parseInt(parts[0]); final int minutes = Integer.parseInt(parts[1]); final boolean isPm = parts[2].equalsIgnoreCase("pm"); final DateTimeZone timezone = parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); // scheduleDate: 02/10/2013 DateTime day = null; if (scheduleDate == null || scheduleDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); } else { day = DateTimeFormat.forPattern("MM/dd/yyyy") .withZone(timezone).parseDateTime(scheduleDate); } hour %= 12; if (isPm) { hour += 12; } final DateTime firstSchedTime = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0); return firstSchedTime; }
case MINUTES: _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter .print(dateTime.withMinuteOfHour((dateTime.getMinuteOfHour() / sz) * sz).minuteOfHour().roundFloorCopy()); break; case HOURS:
case SECONDS: dt = dt.withHourOfDay(0); dt = dt.withMinuteOfHour(0); dt = dt.withSecondOfMinute(0); default:
DateTime dt = new DateTime(1385577373517L, DateTimeZone.UTC); // Prints 2013-11-27T18:36:13.517Z System.out.println(dt); // Prints 2013-11-27T18:36:00.000Z (Floor rounded to a minute) System.out.println(dt.minuteOfDay().roundFloorCopy()); // Prints 2013-11-27T18:30:00.000Z (Rounded to custom minute Window) int windowMinutes = 10; System.out.println( dt.withMinuteOfHour((dt.getMinuteOfHour() / windowMinutes) * windowMinutes) .minuteOfDay().roundFloorCopy() );
private DateTime extractAndUpdateTime(DateTime inputDateTime) { DateTime resultDateTime = inputDateTime.withSecondOfMinute(0).withMillisOfSecond(0); if (dateTime.equals("") || dateTime.contains("now")) return resultDateTime; int hour = 0; int minute = 0; Pattern p = Pattern.compile("(\\d{1,2}):(\\d{2})([a|p]m)?(.*)"); Matcher m = p.matcher(dateTime); if (m.matches()) { hour = Integer.parseInt(m.group(1)); minute = Integer.parseInt(m.group(2)); String middayModifier = m.group(3); if (middayModifier != null && middayModifier.equals("pm")) hour = (hour + 12) % 24; dateTime = m.group(4); } if (dateTime.contains("noon")) { hour = 12; dateTime = dateTime.replace("noon", ""); } else if (dateTime.contains("teatime")) { hour = 16; dateTime = dateTime.replace("teatime", ""); } else if (dateTime.contains("midnight")) dateTime = dateTime.replace("midnight", ""); return resultDateTime.withHourOfDay(hour).withMinuteOfHour(minute); }
assertFunction("date_trunc('minute', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session)); result = result.withMinuteOfHour(0); assertFunction("date_trunc('hour', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session)); assertFunction("date_trunc('minute', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result)); result = result.withMinuteOfHour(0); assertFunction("date_trunc('hour', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
@Test public void testHourMinuteKeywords() { String noonTimestamp = "noon"; String teatimeTimestamp = "teatime"; String midnightTimestamp = "midnight"; Assert.assertEquals(DateTimeParser.parse(noonTimestamp), referenceDateTime().withHourOfDay(12).withMinuteOfHour(0)); Assert.assertEquals(DateTimeParser.parse(teatimeTimestamp), referenceDateTime().withHourOfDay(16).withMinuteOfHour(0)); Assert.assertEquals(DateTimeParser.parse(midnightTimestamp), referenceDateTime().withHourOfDay(0).withMinuteOfHour(0)); }
private static DateTime referenceDateTime() { return new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
@Test public void testRegularHourMinute() { String hourMinuteTimestamp = "12:24"; String hourMinuteWithAm = "9:13am"; String hourMinuteWithPm = "09:13pm"; Assert.assertEquals(DateTimeParser.parse(hourMinuteTimestamp), referenceDateTime().withHourOfDay(12).withMinuteOfHour(24)); Assert.assertEquals(DateTimeParser.parse(hourMinuteWithAm), referenceDateTime().withHourOfDay(9).withMinuteOfHour(13)); Assert.assertEquals(DateTimeParser.parse(hourMinuteWithPm), referenceDateTime().withHourOfDay(21).withMinuteOfHour(13)); }
@Test public void testComplexFormats() { testFormat("12:24 yesterday", nowDateTime().minusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 tomorrow", nowDateTime().plusDays(1).withHourOfDay(12).withMinuteOfHour(24)); testFormat("12:24 today", nowDateTime().withHourOfDay(12).withMinuteOfHour(24)); testFormat("noon 12/30/2014", nowDateTime().withDate(2014, 12, 30).withHourOfDay(12).withMinuteOfHour(0)); int currentYear = referenceDateTime().getYear(); testFormat("15:45 12/30/14", new DateTime(2014, 12, 30, 15, 45, 0, 0)); testFormat("teatime 12/30/2014", new DateTime(2014, 12, 30, 16, 0, 0, 0)); testFormat("midnight Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0)); testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0)); testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0)); }
@Override public LongLongPair startEnd(long time) { DateTime dt = new DateTime(time); DateTime start = dt.withMinuteOfHour(0); DateTime end = dt.plus(hourPeriod).withMinuteOfHour(0); return LongLongPair.pair(start.getMillis(), end.getMillis()); } },MINUTE {
@Override public long applyAsLong(long operand) { return new DateTime(operand,tz).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).getMillis(); } }
public static Intent createNewEventIntent(DateTimeZone timeZone) { DateTime beginTime = new DateTime(timeZone).plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); DateTime endTime = beginTime.plusHours(1); return new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getMillis()); } }
private Interval extractSearchInterval(final Entity contextEntity) { Date from = contextEntity.getDateField(BalanceContextFields.FROM_DATE); Date to = contextEntity.getDateField(BalanceContextFields.TO_DATE); DateTime toMidnight = new DateTime(to).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return new Interval(new DateTime(from), toMidnight); }
/** * Parse the to date query param. */ private DateTime parseFromDate(String fromDate) { // Default to the last 30 days DateTime defaultFrom = new DateTime().withZone(DateTimeZone.UTC).minusDays(30).withHourOfDay(0) .withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); return parseDate(fromDate, defaultFrom, true); }
private Optional<DateTime> getShiftStartDate(DateTime day, Entity shift) { Shift shiftFirst = new Shift(shift); List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate()); if (ranges.isEmpty()) { return Optional.empty(); } LocalTime startTime = ranges.get(0).getFrom(); DateTime startShitTime = day; startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay()); startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour()); return Optional.of(startShitTime); }
/** * Parse the to date query param. */ private DateTime parseFromDate(String fromDate) { // Default to the last 30 days DateTime defaultFrom = new DateTime().withZone(DateTimeZone.UTC).minusDays(30).withHourOfDay(0) .withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); return parseDate(fromDate, defaultFrom, true); }
private DateTime randomTime(DateTime dateTime, Period period) { return dateTime.withHourOfDay(hours(period)) .withMinuteOfHour(minutes()) .withSecondOfMinute(seconds()); }
@Future @FutureWithYearLimit() public DateTime getStartTime() { return startDate.toDateTime().withHourOfDay(startHourMinute.getHourOfDay()).withMinuteOfHour(startHourMinute.getMinuteOfHour()); }