@Override public LocalDate convert(DateTime source) { return source.toLocalDate(); } }
@Override public LocalDate convert(DateTime source) { return source.toLocalDate(); } }
DateTime first = ...; DateTime second = ...; LocalDate firstDate = first.toLocalDate(); LocalDate secondDate = second.toLocalDate(); return firstDate.compareTo(secondDate);
@Override public LocalDate convert(DateTime source) { return source.toLocalDate(); } });
// 5am on the 20th to 1pm on the 21st, October 2013, Brazil DateTimeZone BRAZIL = DateTimeZone.forID("America/Sao_Paulo"); DateTime start = new DateTime(2013, 10, 20, 5, 0, 0, BRAZIL); DateTime end = new DateTime(2013, 10, 21, 13, 0, 0, BRAZIL); System.out.println(daysBetween(start.withTimeAtStartOfDay(), end.withTimeAtStartOfDay()).getDays()); // prints 0 System.out.println(daysBetween(start.toLocalDate(), end.toLocalDate()).getDays()); // prints 1
public static String formatToYesterdayOrToday(String date) { DateTime dateTime = DateTimeFormat.forPattern("EEE hh:mma MMM d, yyyy").parseDateTime(date); DateTime today = new DateTime(); DateTime yesterday = today.minusDays(1); DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("hh:mma"); if (dateTime.toLocalDate().equals(today.toLocalDate())) { return "Today " + timeFormatter.print(dateTime); } else if (dateTime.toLocalDate().equals(yesterday.toLocalDate())) { return "Yesterday " + timeFormatter.print(dateTime); } else { return date; } }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
@Description("current date") @ScalarFunction @SqlType(StandardTypes.DATE) public static long currentDate(ConnectorSession session) { ISOChronology chronology = getChronology(session.getTimeZoneKey()); // It is ok for this method to use the Object interfaces because it is constant folded during // plan optimization LocalDate currentDate = new DateTime(session.getStartTime(), chronology).toLocalDate(); return Days.daysBetween(new LocalDate(1970, 1, 1), currentDate).getDays(); }
@Override public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // We'll accept either long (timestamp) or array: if (jp.isExpectedStartArrayToken()) { jp.nextToken(); // VALUE_NUMBER_INT int year = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int month = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int day = jp.getIntValue(); if (jp.nextToken() != JsonToken.END_ARRAY) { throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after LocalDate ints"); } return new LocalDate(year, month, day); } switch (jp.getCurrentToken()) { case VALUE_NUMBER_INT: return new LocalDate(jp.getLongValue()); case VALUE_STRING: DateTime local = parseLocal(jp); if (local == null) { return null; } return local.toLocalDate(); } throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "expected JSON Array, String or Number"); } }
bundle.getExternalKey(), specifiers, init.toLocalDate(), false);
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
@Override public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // We'll accept either long (timestamp) or array: if (jp.isExpectedStartArrayToken()) { jp.nextToken(); // VALUE_NUMBER_INT int year = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int month = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int day = jp.getIntValue(); if (jp.nextToken() != JsonToken.END_ARRAY) { throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after LocalDate ints"); } return new LocalDate(year, month, day); } switch (jp.getCurrentToken()) { case VALUE_NUMBER_INT: return new LocalDate(jp.getLongValue()); case VALUE_STRING: DateTime local = parseLocal(jp); if (local == null) { return null; } return local.toLocalDate(); } throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "expected JSON Array, String or Number"); } }
private Map<String,Set<String>> findTransactionsWithinPeriod(LeaveCalendarDocumentHeader aDoc, CalendarEntry payCalendarEntry) { Map<String,Set<String>> allMessages = new HashMap<String,Set<String>>(); allMessages.put("actionMessages", new HashSet<String>()); allMessages.put("infoMessages", new HashSet<String>()); allMessages.put("warningMessages", new HashSet<String>()); if(aDoc != null) { allMessages = LeaveCalendarValidationUtil.validatePendingTransactions(aDoc.getPrincipalId(), payCalendarEntry.getBeginPeriodFullDateTime().toLocalDate(), payCalendarEntry.getEndPeriodFullDateTime().toLocalDate()); } return allMessages; }
public OrderRealizationDay find(final DateTime orderStartDateTime, final int startingFrom, final boolean isFirstDay, final List<Shift> shifts) { OrderRealizationDay firstWorkingDay = findFirstWorkingDayFrom(orderStartDateTime.toLocalDate(), startingFrom, shifts); if (isFirstDay) { return tryResolveFirstDay(firstWorkingDay, orderStartDateTime).or(firstWorkingDay); } return firstWorkingDay; }
public List<DateTimeRange> getShiftWorkDateTimes(final Entity productionLine, final Shift shift, DateTime dateOfDay) { List<TimeRange> shiftWorkTime = Lists.newArrayList(); List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList(); if (shift.worksAt(dateOfDay.dayOfWeek().get())) { shiftWorkTime = shift.findWorkTimeAt(dateOfDay.toLocalDate()); } for (TimeRange range : shiftWorkTime) { shiftWorkDateTime.add(new DateTimeRange(dateOfDay, range)); } shiftWorkDateTime = manageExceptions(shiftWorkDateTime, productionLine, shift, dateOfDay.toDate()); return shiftWorkDateTime; }
public static DeviationsReportCriteria forDates(final DateTime fromDate, final Optional<DateTime> maybeToDate) { checkArguments(fromDate, maybeToDate); LocalDate fromLocalDate = fromDate.toLocalDate(); Optional<LocalDate> maybeToLocalDate = maybeToDate.transform(new Function<DateTime, LocalDate>() { @Override public LocalDate apply(final DateTime input) { return input.toLocalDate(); } }); return fromLocalDates(fromLocalDate, maybeToLocalDate); }
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); }
private void calculateMaxCarryOverForLeavePlan(String documentId, String principalId, CalendarEntry calendarEntry, String leavePlan, LocalDate asOfDate) { List<? extends AccrualCategoryContract> accrualCategories = getAccrualCategoryService().getActiveAccrualCategoriesForLeavePlan(leavePlan, asOfDate); for (AccrualCategoryContract accrualCategory : accrualCategories) { BigDecimal adjustmentAmount = getAccrualCategoryCarryOverAdjustment(accrualCategory.getAccrualCategory(), principalId, calendarEntry, asOfDate); if (adjustmentAmount.compareTo(BigDecimal.ZERO) > 0) { LocalDate LeaveDate = calendarEntry.getEndPeriodFullDateTime().toLocalDate().minusDays(1); addAdjustmentLeaveBlock(documentId, principalId, LeaveDate, accrualCategory, adjustmentAmount.negate()); } } }
private InvoiceItemModelDao buildCBAItem(final InvoiceModelDao invoice, final BigDecimal amount, final InternalCallContext context) { return new InvoiceItemModelDao(new CreditBalanceAdjInvoiceItem(invoice.getId(), invoice.getAccountId(), context.getCreatedDate().toLocalDate(), amount.negate(), invoice.getCurrency())); } }