/** * Parses a {@code YearMonth} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static YearMonth parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new YearMonth(date.getYear(), date.getMonthOfYear()); }
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }
/** * Parses a {@code YearMonth} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static YearMonth parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new YearMonth(date.getYear(), date.getMonthOfYear()); }
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }
/** * Returns a copy of this datetime with the specified date, retaining the time fields. * <p> * If the time is invalid on the new date due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param date the local date * @return a copy of this datetime with a different date * @throws IllegalArgumentException if the time-of-day is invalid for the date * @throws NullPointerException if the date is null */ public DateTime withDate(LocalDate date) { return withDate( date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); }
/** * Returns a copy of this datetime with the specified date, retaining the time fields. * <p> * If the time is invalid on the new date due to the time-zone, the time will be adjusted. * <p> * This instance is immutable and unaffected by this method call. * * @param date the local date * @return a copy of this datetime with a different date * @throws IllegalArgumentException if the time-of-day is invalid for the date * @throws NullPointerException if the date is null */ public DateTime withDate(LocalDate date) { return withDate( date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); }
new LocalDate(2001, month, day).plusDays(1)); advance = (day != -1 && dayOfWeek != 0); month = date.getMonthOfYear(); day = date.getDayOfMonth(); if (dayOfWeek != 0) {
/** * Converts this LocalDate to a full datetime at midnight using the * specified time zone. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This method uses the chronology from this instance plus the time zone * specified. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to use, null means default zone * @return this date as a datetime at midnight * @deprecated Use {@link #toDateTimeAtStartOfDay(DateTimeZone)} which won't throw an exception */ @Deprecated public DateTime toDateTimeAtMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateTime(getYear(), getMonthOfYear(), getDayOfMonth(), 0, 0, 0, 0, chrono); }
public Date toDate() { int dom = getDayOfMonth(); Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom); LocalDate check = LocalDate.fromDateFields(date); if (check.isBefore(this)) {
/** * Converts this LocalDate to a full datetime at midnight using the * specified time zone. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This method uses the chronology from this instance plus the time zone * specified. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to use, null means default zone * @return this date as a datetime at midnight * @deprecated Use {@link #toDateTimeAtStartOfDay(DateTimeZone)} which won't throw an exception */ @Deprecated public DateTime toDateTimeAtMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateTime(getYear(), getMonthOfYear(), getDayOfMonth(), 0, 0, 0, 0, chrono); }
@Override public void write(Kryo kryo, Output output, LocalDate localDate) { output.writeInt(localDate.getYear()); output.writeInt(localDate.getMonthOfYear()); output.writeInt(localDate.getDayOfMonth()); final Chronology chronology = localDate.getChronology(); if (chronology != null && chronology != ISOChronology.getInstanceUTC()) { throw new RuntimeException("Unsupported chronology: " + chronology); } }
public Date toDate() { int dom = getDayOfMonth(); Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom); LocalDate check = LocalDate.fromDateFields(date); if (check.isBefore(this)) {
/** * Wraps the other servicesRunning whose parameter is an OBA ServiceDate. * Joda LocalDate is a similar class. */ public BitSet servicesRunning (LocalDate date) { return servicesRunning(new ServiceDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth())); }
@VisibleForTesting DateTime getEffectiveDateForNewBCD(final int bcd, @Nullable final LocalDate effectiveFromDate, final InternalCallContext internalCallContext) { if (internalCallContext.getAccountRecordId() == null) { throw new IllegalStateException("Need to have a valid context with accountRecordId"); } // Today as seen by this account final LocalDate startDate = effectiveFromDate != null ? effectiveFromDate : internalCallContext.toLocalDate(internalCallContext.getCreatedDate()); // We want to compute a LocalDate in account TZ which maps to the provided 'bcd' and then compute an effectiveDate for when that BCD_CHANGE event needs to be triggered // // There is a bit of complexity to make sure the date we chose exists (e.g: a BCD of 31 in a february month would not make sense). final int currentDay = startDate.getDayOfMonth(); final int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue(); final LocalDate requestedDate; if (bcd < currentDay) { final LocalDate startDatePlusOneMonth = startDate.plusMonths(1); final int lastDayOfNextMonth = startDatePlusOneMonth.dayOfMonth().getMaximumValue(); final int originalBCDORLastDayOfMonth = bcd <= lastDayOfNextMonth ? bcd : lastDayOfNextMonth; requestedDate = new LocalDate(startDatePlusOneMonth.getYear(), startDatePlusOneMonth.getMonthOfYear(), originalBCDORLastDayOfMonth); } else if (bcd == currentDay && effectiveFromDate == null) { // will default to immediate event requestedDate = null; } else if (bcd <= lastDayOfMonth) { requestedDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), bcd); } else /* bcd > lastDayOfMonth && bcd > currentDay */ { requestedDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), lastDayOfMonth); } return requestedDate == null ? internalCallContext.getCreatedDate() : internalCallContext.toUTCDateTime(requestedDate); }
/** * Converts this LocalDate to a DateMidnight. * <p> * As from v1.5, you are recommended to avoid DateMidnight and use * {@link #toDateTimeAtStartOfDay()} instead because of the exception * detailed below. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the DateMidnight in, null means default zone * @return the DateMidnight instance * @deprecated DateMidnight is deprecated */ @Deprecated public DateMidnight toDateMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono); }
/** * Converts this LocalDate to a DateMidnight. * <p> * As from v1.5, you are recommended to avoid DateMidnight and use * {@link #toDateTimeAtStartOfDay()} instead because of the exception * detailed below. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the DateMidnight in, null means default zone * @return the DateMidnight instance * @deprecated DateMidnight is deprecated */ @Deprecated public DateMidnight toDateMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono); }
public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay, final BillingPeriod billingPeriod) { // billingCycleDay alignment only makes sense for month based BillingPeriod (MONTHLY, QUARTERLY, BIANNUAL, ANNUAL) final boolean isMonthBased = (billingPeriod.getPeriod().getMonths() | billingPeriod.getPeriod().getYears()) > 0; if (!isMonthBased) { return proposedDate; } final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue(); int proposedBillCycleDate = proposedDate.getDayOfMonth(); if (proposedBillCycleDate < billingCycleDay) { if (billingCycleDay <= lastDayOfMonth) { proposedBillCycleDate = billingCycleDay; } else { proposedBillCycleDate = lastDayOfMonth; } } return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate, proposedDate.getChronology()); }
getYear(), getMonthOfYear(), getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), chrono);
@Override public void write(Kryo kryo, Output output, LocalDate object) { output.writeInt(object.getYear()); output.writeInt(object.getMonthOfYear()); output.writeInt(object.getDayOfMonth()); }
getYear(), getMonthOfYear(), getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), chrono);