private LocalDate calcNextFriday(LocalDate d) { return d.with(TemporalAdjusters.next(DayOfWeek.FRIDAY)); }
private static LocalDate localWeekDate( int year, int week, int dayOfWeek ) { LocalDate weekOne = LocalDate.of( year, 1, 4 ); // the fourth is guaranteed to be in week 1 by definition LocalDate withWeek = weekOne.with( IsoFields.WEEK_OF_WEEK_BASED_YEAR, week ); // the implementation of WEEK_OF_WEEK_BASED_YEAR uses addition to adjust the date, this means that it accepts // week 53 of years that don't have 53 weeks, so we have to guard for this: if ( week == 53 && withWeek.get( IsoFields.WEEK_BASED_YEAR ) != year ) { throw new InvalidValuesArgumentException( String.format( "Year %d does not contain %d weeks.", year, week ) ); } return withWeek.with( ChronoField.DAY_OF_WEEK, dayOfWeek ); }
return value.with( Neo4JTemporalField.YEAR_OF_MILLENNIUM, 0 ); return value.with( Neo4JTemporalField.YEAR_OF_CENTURY, 0 ); return value.with( Neo4JTemporalField.YEAR_OF_DECADE, 0 ); return value.with( TemporalAdjusters.firstDayOfYear() ); return value.with( IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1 ).with( ChronoField.DAY_OF_WEEK, 1 ); return value.with( IsoFields.DAY_OF_QUARTER, 1 ); return value.with( TemporalAdjusters.firstDayOfMonth() ); return value.with( TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY ) );
/** * 得到传入日期,周起始时间. * 这个方法定义:周一为一个星期开始的第一天 * * @param date 日期 * @return 返回一周的第一天 */ public static LocalDate getWeekStart(final LocalDate date) { return date.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); }
/** * 得到month的终止时间点.. * * @param date 日期 * @return 传入的日期当月的结束日期 */ public static LocalDate getMonthEnd(final LocalDate date) { return date.with(TemporalAdjusters.lastDayOfMonth()); }
/** * 得到当前年起始时间. * * @param date 日期 * @return 传入的日期当年的开始日期 */ public static LocalDate getYearStart(final LocalDate date) { return date.with(TemporalAdjusters.firstDayOfYear()); }
/** * 得到当前周截止时间. * 这个方法定义:周日为一个星期开始的最后一天 * * @param date 日期 * @return 返回一周的最后一天 */ public static LocalDate getWeekEnd(final LocalDate date) { return date.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); }
/** * 得到当月起始时间. * * @param date 日期 * @return 传入的日期当月的开始日期 */ public static LocalDate getMonthStart(final LocalDate date) { return date.with(TemporalAdjusters.firstDayOfMonth()); }
/** * 得到当前年最后一天. * * @param date 日期 * @return 传入的日期当年的结束日期 */ public static LocalDate getYearEnd(final LocalDate date) { return date.with(TemporalAdjusters.lastDayOfYear()); }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Date}, which contains a date but no time or * timezone information. * * @param date the date value; may not be null * @param zoneId the timezone identifier or offset where the date is defined * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the ISO 8601 formatted string */ public static String toIsoString(java.sql.Date date, ZoneId zoneId, TemporalAdjuster adjuster) { LocalDate localDate = date.toLocalDate(); if (adjuster != null) { localDate = localDate.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, zoneId); return zdt.format(FORMATTER); }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Date}, which contains a date but no time or * timezone information. * * @param date the date value * @param zoneId the timezone identifier or offset where the date is defined * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the ISO 8601 formatted string */ public static String toIsoString(java.sql.Date date, ZoneId zoneId, TemporalAdjuster adjuster) { LocalDate localDate = date.toLocalDate(); if (adjuster != null) { localDate = localDate.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, zoneId); return zdt.format(FORMATTER); }
@Override public DateValue buildInternal() { LocalDate result; if ( fields.containsKey( TemporalFields.date ) ) { result = getDateOf( fields.get( TemporalFields.date ) ); } else if ( fields.containsKey( TemporalFields.week ) ) { // Be sure to be in the start of the week based year (which can be later than 1st Jan) result = DEFAULT_CALENDER_DATE .with( IsoFields.WEEK_BASED_YEAR, safeCastIntegral( TemporalFields.year.name(), fields.get( TemporalFields.year ), TemporalFields.year.defaultValue ) ) .with( IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1 ) .with( ChronoField.DAY_OF_WEEK, 1 ); } else { result = DEFAULT_CALENDER_DATE; } result = assignAllFields( result ); return date( result ); }
/** * 上月最后一天. * * @return 日期 */ public static LocalDate getPreviousMonthLastDay() { return LocalDate.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()); }
/** * 上月第一天. * * @return 日期 */ public static LocalDate getPreviousMonthFirstDay() { return LocalDate.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth()); }
private static LocalDate localQuarterDate( int year, int quarter, int dayOfQuarter ) { // special handling for the range of Q1 and Q2, since they are shorter than Q3 and Q4 if ( quarter == 2 && dayOfQuarter == 92 ) { throw new InvalidValuesArgumentException( "Quarter 2 only has 91 days." ); } // instantiate the yearDate now, because we use it to know if it is a leap year LocalDate yearDate = LocalDate.ofYearDay( year, dayOfQuarter ); // guess on the day if ( quarter == 1 && dayOfQuarter > 90 && (!yearDate.isLeapYear() || dayOfQuarter == 92) ) { throw new InvalidValuesArgumentException( String.format( "Quarter 1 of %d only has %d days.", year, yearDate.isLeapYear() ? 91 : 90 ) ); } return yearDate .with( IsoFields.QUARTER_OF_YEAR, quarter ) .with( IsoFields.DAY_OF_QUARTER, dayOfQuarter ); }
/** * 取得季度最后一天. * * @param date 日期 * @return 传入的日期当季的结束日期 */ public static LocalDate getSeasonEnd(final LocalDate date) { return getSeasonDate(date)[2].with(TemporalAdjusters.lastDayOfMonth()); }
/** * Get the number of epoch days of the given {@link java.time.LocalDateTime}, {@link java.time.LocalDate}, * {@link java.time.LocalTime}, {@link java.util.Date}, {@link java.sql.Date}, {@link java.sql.Time}, or * {@link java.sql.Timestamp}, ignoring any time portions of the supplied value. * * @param value the local or SQL date, time, or timestamp value; may not be null * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the number of days past epoch * @throws IllegalArgumentException if the value is not an instance of the acceptable types */ public static int toEpochDay(Object value, TemporalAdjuster adjuster) { LocalDate date = Conversions.toLocalDate(value); if (adjuster != null) { date = date.with(adjuster); } return (int)date.toEpochDay(); }
if (date.equals(startDate) || date.getDayOfMonth() == 1) { nextHeaderCell(MONTH_FORMATTER.format(date)); LocalDate startNextMonthDate = date.with(TemporalAdjusters.firstDayOfNextMonth()); if (endDate.compareTo(startNextMonthDate) < 0) { startNextMonthDate = endDate;