public int getHours() { return localDateTime.getHour(); }
/** * Returns true if both datetime are in the same year, month, day of month and hour, false otherwise. * * @param actual the actual datetime. expected not be null * @param other the other datetime. expected not be null * @return true if both datetime are in the same year, month, day of month and hour, false otherwise. */ private static boolean areEqualIgnoringMinutes(LocalDateTime actual, LocalDateTime other) { return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour(); }
/** * Returns true if both datetime are in the same year, month, day of month and hour, false otherwise. * * @param actual the actual datetime. expected not be null * @param other the other datetime. expected not be null * @return true if both datetime are in the same year, month, day of month and hour, false otherwise. */ private static boolean areEqualIgnoringMinutes(LocalDateTime actual, LocalDateTime other) { return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour(); }
public static int time(LocalDateTime localDateTime) { return time(localDateTime.getHour(), localDateTime.getMinute(), 0); }
sb.append(String.format("at %d:%02d", endTime.getHour(), endTime.getMinute())); return sb.toString();
LocalDateTime now = LocalDateTime.now(); int year = now.getYear(); int month = now.getMonthValue(); int day = now.getDayOfMonth(); int hour = now.getHour(); int minute = now.getMinute(); int second = now.getSecond(); int millis = now.get(ChronoField.MILLI_OF_SECOND); // Note: no direct getter available. System.out.printf("%d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, millis);
private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeNumber(value.getYear()); g.writeNumber(value.getMonthValue()); g.writeNumber(value.getDayOfMonth()); g.writeNumber(value.getHour()); g.writeNumber(value.getMinute()); final int secs = value.getSecond(); final int nanos = value.getNano(); if ((secs > 0) || (nanos > 0)) { g.writeNumber(secs); if (nanos > 0) { if (useNanoseconds(provider)) { g.writeNumber(nanos); } else { g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND)); } } } }
public static long getMillisecondOfDay(long packedLocalDateTime) { LocalDateTime localDateTime = PackedLocalDateTime.asLocalDateTime(packedLocalDateTime); long total = (long) localDateTime.get(ChronoField.MILLI_OF_SECOND); total += localDateTime.getSecond() * 1000; total += localDateTime.getMinute() * 60 * 1000; total += localDateTime.getHour() * 60 * 60 * 1000; return total; }
if (text.length() == 23) { LocalDateTime localDateTime = LocalDateTime.parse(text); localDate = LocalTime.of(localDateTime.getHour(), localDateTime.getMinute(), localDateTime.getSecond(), localDateTime.getNano()); } else {
public boolean pauseExists(Timeslot other, int pauseInMinutes) { if (this.overlapsTime(other)) { return false; } if (!this.isOnSameDayAs(other)) { return true; } if (this.startsAfter(other)) { // TODO use Duration.between(a, b).toMinutes() return (this.getStartDateTime().getHour() * 60 + this.getStartDateTime().getMinute()) - (other.getEndDateTime().getHour() * 60 + other.getEndDateTime().getMinute()) >= pauseInMinutes; } else { // TODO use Duration.between(a, b).toMinutes() return (other.getStartDateTime().getHour() * 60 + other.getStartDateTime().getMinute()) - (this.getEndDateTime().getHour() * 60 + this.getEndDateTime().getMinute()) >= pauseInMinutes; } }
private static String dateFormatterForLogs(LocalDateTime dateTime) { String dateString = "["; dateString += dateTime.getDayOfMonth() + "_"; dateString += dateTime.getMonthValue() + "_"; dateString += dateTime.getYear() + "_"; dateString += dateTime.getHour() + ":"; dateString += dateTime.getMinute() + ":"; dateString += dateTime.getSecond(); dateString += "] "; return dateString; }
@Test public void testGetHour() { LocalDateTime now = LocalDateTime.now(); assertEquals(now.getHour(), getHour(pack(now))); }
@Override public Date unmarshal(String date) throws Exception { final LocalDateTime now = LocalDateTime.now(); final DateTimeFormatter parser = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATE_TIME_FORMAT) .parseDefaulting(ChronoField.YEAR, now.getYear()) .parseDefaulting(ChronoField.MONTH_OF_YEAR, now.getMonthValue()) .parseDefaulting(ChronoField.DAY_OF_MONTH, now.getDayOfMonth()) .parseDefaulting(ChronoField.HOUR_OF_DAY, now.getHour()) .parseDefaulting(ChronoField.MINUTE_OF_HOUR, now.getMinute()) .parseDefaulting(ChronoField.SECOND_OF_MINUTE, now.getSecond()) .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0) .toFormatter(Locale.US); final LocalDateTime parsedDateTime = LocalDateTime.parse(date, parser); return Date.from(parsedDateTime.toInstant(ZONE_ID.getRules().getOffset(now))); }
@Test public void testAsLocalDateTime() { LocalDateTime dateTime = LocalDateTime.now(); long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime()); LocalDateTime upacked = asLocalDateTime(packed); assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear()); assertEquals(dateTime.getHour(), upacked.getHour()); assertEquals(dateTime.getMinute(), upacked.getMinute()); assertEquals(dateTime.getSecond(), upacked.getSecond()); }
@SuppressWarnings("deprecation") @Test public void shouldReturnLocalDateTimeInstanceWhenConvertingUtilTimeToLocalDateTime() { LocalDateTime now = LocalDateTime.now(); java.util.Date date = new java.util.Date(now.getYear()-1900,now.getMonthValue()-1,now.getDayOfMonth(), now.getHour(),now.getMinute(),now.getSecond()); // 0 nanos! assertThat(Conversions.toLocalDateTime(date)).isEqualTo(now.withNano(0)); }
private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeNumber(value.getYear()); g.writeNumber(value.getMonthValue()); g.writeNumber(value.getDayOfMonth()); g.writeNumber(value.getHour()); g.writeNumber(value.getMinute()); final int secs = value.getSecond(); final int nanos = value.getNano(); if ((secs > 0) || (nanos > 0)) { g.writeNumber(secs); if (nanos > 0) { if (useNanoseconds(provider)) { g.writeNumber(nanos); } else { g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND)); } } } }
case HOURS: if (24 % time == 0) { t = t.plusHours(time - t.getHour() % time); } else { t = t.plusHours(1);
assertNotNull(foo.timestamp2); assertEquals(2010, foo.timestamp2.getYear()); assertEquals(1, foo.timestamp2.getHour()); assertEquals(2, foo.timestamp2.getMinute()); assertNotNull(foo.clob); assertEquals(108, foo.timestamp.getYear()); assertEquals(2010, foo.timestamp2.getYear()); assertEquals(20, foo.timestamp2.getHour()); assertEquals(20, foo.timestamp2.getMinute()); assertEquals(4, foo.clob.length());
@Test void testSet() { JulianDate jdt = JulianDate.of(2008, 12, 20, 10, 44, 55, 0); JulianDate jdt2 = JulianDate.of(jdt.integer - 1, jdt.fraction); assertEquals(jdt.toLocalDateTime().getYear(), jdt2.toLocalDateTime().getYear()); assertEquals(jdt.toLocalDateTime().getMonth(), jdt2.toLocalDateTime().getMonth()); assertEquals(jdt.toLocalDateTime().getDayOfMonth() - 1, jdt2.toLocalDateTime().getDayOfMonth()); assertEquals(jdt.toLocalDateTime().getHour(), jdt2.toLocalDateTime().getHour()); assertEquals(jdt.toLocalDateTime().getMinute(), jdt2.toLocalDateTime().getMinute()); assertEquals(jdt.toLocalDateTime().getSecond(), jdt2.toLocalDateTime().getSecond(), 0.0001); }
@Test public void testConvertMillisSinceEpoch() { long millis = 1503952123189L; LongColumn dc = LongColumn.create("test"); dc.append(millis); DateTimeColumn column2 = dc.asDateTimes(ZoneOffset.UTC); assertEquals(1, column2.size()); assertEquals(2017, column2.get(0).getYear()); assertEquals(8, column2.get(0).getMonthValue()); assertEquals(28, column2.get(0).getDayOfMonth()); assertEquals(20, column2.get(0).getHour()); long[] millisArr = column2.asEpochMillisArray(); assertEquals(1, millisArr.length); assertEquals(millis, millisArr[0]); }