public int getMinutes() { return localDateTime.getMinute(); }
/** * Returns true if both datetime are in the same year, month, day of month, hour and minute, 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, hour and minute, false otherwise. */ private static boolean areEqualIgnoringSeconds(LocalDateTime actual, LocalDateTime other) { return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute(); }
/** * Returns true if both datetime are in the same year, month, day of month, hour and minute, 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, hour and minute, false otherwise. */ private static boolean areEqualIgnoringSeconds(LocalDateTime actual, LocalDateTime other) { return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute(); }
public static int time(LocalDateTime localDateTime) { return time(localDateTime.getHour(), localDateTime.getMinute(), 0); }
public void incrementNotificationCounter(String status){ em.incrementAggregateCounters( null,null,null,"counters.notifications."+notification.getUuid()+"."+status,1 ); LocalDateTime localDateTime = LocalDateTime.now(); StringBuilder currentDate = new StringBuilder( ); currentDate.append( "counters.notifications.aggregate."+status+"." ); currentDate.append( localDateTime.getYear()+"." ); currentDate.append( localDateTime.getMonth()+"." ); currentDate.append( localDateTime.getDayOfMonth()+"." ); currentDate.append( localDateTime.getMinute() ); em.incrementAggregateCounters( null,null,null,currentDate.toString(),1 ); }
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 testGetMinute() { LocalDateTime now = LocalDateTime.now(); assertEquals(now.getMinute(), getMinute(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 MINUTES: if (60 % time == 0) { t = t.plusMinutes(time - t.getMinute() % time); } else { t = t.plusMinutes(1);
assertEquals(2010, foo.timestamp2.getYear()); assertEquals(1, foo.timestamp2.getHour()); assertEquals(2, foo.timestamp2.getMinute()); assertNotNull(foo.clob); assertEquals(4, foo.clob.length()); assertEquals(2010, foo.timestamp2.getYear()); assertEquals(20, foo.timestamp2.getHour()); assertEquals(20, foo.timestamp2.getMinute()); assertEquals(4, foo.clob.length()); assertEquals("W173", foo.clob.getSubString(1, 4));
@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); }