/** * A hash code for this {@code WeekFields}. * * @return a suitable hash code */ @Override public int hashCode() { return firstDayOfWeek.ordinal() * 7 + minimalDays; }
/** * Gets the day-of-week {@code int} value. * <p> * The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday). * See {@link WeekFields#dayOfWeek} for localized week-numbering. * * @return the day-of-week, from 1 (Monday) to 7 (Sunday) */ public int getValue() { return ordinal() + 1; }
/** * A hash code for this {@code WeekFields}. * * @return a suitable hash code */ @Override public int hashCode() { return firstDayOfWeek.ordinal() * 7 + minimalDays; }
/** * Gets the day-of-week {@code int} value. * <p> * The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday). * See {@link WeekFields#dayOfWeek} for localized week-numbering. * * @return the day-of-week, from 1 (Monday) to 7 (Sunday) */ public int getValue() { return ordinal() + 1; }
/** * Returns the day-of-week that is the specified number of days after this one. * <p> * The calculation rolls around the end of the week from Sunday to Monday. * The specified period may be negative. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, positive or negative * @return the resulting day-of-week, not null */ public DayOfWeek plus(long days) { int amount = (int) (days % 7); return ENUMS[(ordinal() + (amount + 7)) % 7]; }
/** * Returns the day-of-week that is the specified number of days after this one. * <p> * The calculation rolls around the end of the week from Sunday to Monday. * The specified period may be negative. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, positive or negative * @return the resulting day-of-week, not null */ public DayOfWeek plus(long days) { int amount = (int) (days % 7); return ENUMS[(ordinal() + (amount + 7)) % 7]; }
private static int getWeekBasedYear(LocalDate date) { int year = date.getYear(); int doy = date.getDayOfYear(); if (doy <= 3) { int dow = date.getDayOfWeek().ordinal(); if (doy - dow < -2) { year--; } } else if (doy >= 363) { int dow = date.getDayOfWeek().ordinal(); doy = doy - 363 - (date.isLeapYear() ? 1 : 0); if (doy - dow >= 0) { year++; } } return year; } }
private static int getWeekBasedYear(LocalDate date) { int year = date.getYear(); int doy = date.getDayOfYear(); if (doy <= 3) { int dow = date.getDayOfWeek().ordinal(); if (doy - dow < -2) { year--; } } else if (doy >= 363) { int dow = date.getDayOfWeek().ordinal(); doy = doy - 363 - (date.isLeapYear() ? 1 : 0); if (doy - dow >= 0) { year++; } } return year; } }
/** * Returns a suitable hash code. * * @return the hash code */ @Override public int hashCode() { int hash = ((time.toSecondOfDay() + adjustDays) << 15) + (month.ordinal() << 11) + ((dom + 32) << 5) + ((dow == null ? 7 : dow.ordinal()) << 2) + (timeDefinition.ordinal()); return hash ^ standardOffset.hashCode() ^ offsetBefore.hashCode() ^ offsetAfter.hashCode(); }
/** * Returns a suitable hash code. * * @return the hash code */ @Override public int hashCode() { int hash = ((time.toSecondOfDay() + adjustDays) << 15) + (month.ordinal() << 11) + ((dom + 32) << 5) + ((dow == null ? 7 : dow.ordinal()) << 2) + (timeDefinition.ordinal()); return hash ^ standardOffset.hashCode() ^ offsetBefore.hashCode() ^ offsetAfter.hashCode(); }
private static int getWeek(LocalDate date) { int dow0 = date.getDayOfWeek().ordinal(); int doy0 = date.getDayOfYear() - 1; int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero) int alignedWeek = doyThu0 / 7; int firstThuDoy0 = doyThu0 - (alignedWeek * 7); int firstMonDoy0 = firstThuDoy0 - 3; if (firstMonDoy0 < -3) { firstMonDoy0 += 7; } if (doy0 < firstMonDoy0) { return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum(); } int week = ((doy0 - firstMonDoy0) / 7) + 1; if (week == 53) { if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) { week = 1; } } return week; }
private static int getWeek(LocalDate date) { int dow0 = date.getDayOfWeek().ordinal(); int doy0 = date.getDayOfYear() - 1; int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero) int alignedWeek = doyThu0 / 7; int firstThuDoy0 = doyThu0 - (alignedWeek * 7); int firstMonDoy0 = firstThuDoy0 - 3; if (firstMonDoy0 < -3) { firstMonDoy0 += 7; } if (doy0 < firstMonDoy0) { return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum(); } int week = ((doy0 - firstMonDoy0) / 7) + 1; if (week == 53) { if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) { week = 1; } } return week; }