protected boolean isValidDate(Chronology chrono, LocalDate date) { try { if (date != null) { chrono.date(date); } return true; } catch (DateTimeException ex) { return false; } } }
private String formatMonth(YearMonth yearMonth) { try { Chronology chrono = getPrimaryChronology(); ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1)); return monthFormatter.withLocale(getLocale()).withChronology(chrono).format(cDate); } catch (DateTimeException ex) { // Date is out of range. return ""; } }
private String formatYear(YearMonth yearMonth) { try { Chronology chrono = getPrimaryChronology(); ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1)); return yearFormatter.withLocale(getLocale()) .withChronology(chrono) .withDecimalStyle(DecimalStyle.of(getLocale())) .format(cDate); } catch (DateTimeException ex) { // Date is out of range. return ""; } }
ChronoLocalDate cDate = chrono.date(date); String cellText = dayCellFormatter.withLocale(locale) .withChronology(chrono)
/** * Creates the date within the provided chronology. * * @param year a int. * @param month a int. * @param day a int. * @param chronology the chronology to use * @return date the {@link LocalDate} */ public ChronoLocalDate create(int year, int month, int day, Chronology chronology) { return chronology.date(year, month, day); }
@Override // override with covariant return type public ThaiBuddhistDate date(Era era, int yearOfEra, int month, int dayOfMonth) { return (ThaiBuddhistDate) super.date(era, yearOfEra, month, dayOfMonth); }
protected boolean isValidDate(Chronology chrono, LocalDate date) { try { if (date != null) { chrono.date(date); } return true; } catch (DateTimeException ex) { return false; } } }
@Override // override with covariant return type public HijrahDate date(Era era, int yearOfEra, int month, int dayOfMonth) { return (HijrahDate) super.date(era, yearOfEra, month, dayOfMonth); }
@Override // override with covariant return type public MinguoDate date(Era era, int yearOfEra, int month, int dayOfMonth) { return (MinguoDate) super.date(era, yearOfEra, month, dayOfMonth); }
/** * Formats a date according to the locale and formatting options of this {@code DateTimeFormat} object. * @param date the JavaScript object to convert * @return the dated formated */ String format(final Date date) { TemporalAccessor zonedDateTime = date.toInstant().atZone(ZoneId.systemDefault()); if (chronology_ != null) { zonedDateTime = chronology_.date(zonedDateTime); } return formatter_.format(zonedDateTime); } }
/** * Formats a date according to the locale and formatting options of this {@code DateTimeFormat} object. * @param date the JavaScript object to convert * @return the dated formated */ String format(final Date date) { TemporalAccessor zonedDateTime = date.toInstant().atZone(ZoneId.systemDefault()); if (chronology_ != null) { zonedDateTime = chronology_.date(zonedDateTime); } return formatter_.format(zonedDateTime); } }
/** * Obtains a local date in this chronology from the era, year-of-era, * month-of-year and day-of-month fields. * * @param era the era of the correct type for the chronology, not null * @param yearOfEra the chronology year-of-era * @param month the chronology month-of-year * @param dayOfMonth the chronology day-of-month * @return the local date in this chronology, not null * @throws DateTimeException if unable to create the date * @throws ClassCastException if the {@code era} is not of the correct type for the chronology */ public ChronoLocalDate date(Era era, int yearOfEra, int month, int dayOfMonth) { return date(prolepticYear(era, yearOfEra), month, dayOfMonth); }
/** * Obtains the current local date in this chronology from the specified clock. * <p> * This will query the specified clock to obtain the current date - today. * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current local date, not null * @throws DateTimeException if unable to create the date */ public ChronoLocalDate dateNow(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); return date(LocalDate.now(clock)); }
@Override long getValue(DateTimePrintContext context, long value) { long absValue = Math.abs(value); int baseValue = this.baseValue; if (baseDate != null) { Chronology chrono = Chronology.from(context.getTemporal()); baseValue = chrono.date(baseDate).get(field); } if (value >= baseValue && value < baseValue + EXCEED_POINTS[minWidth]) { return absValue % EXCEED_POINTS[minWidth]; } return absValue % EXCEED_POINTS[maxWidth]; }
@Override public ChronoLocalDate resolve( Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) { long value = fieldValues.remove(this); LocalDate date; if (resolverStyle == ResolverStyle.LENIENT) { int year = Math.toIntExact(value / 10000); int moy = (int) ((value % 10000) / 100); long dom = value % 100; date = LocalDate.of(year, 1, 1).plusMonths(moy - 1).plusDays(dom - 1); } else { date = toDate(value); } Chronology chrono = Chronology.from(partialTemporal); return chrono.date(date); }
private String formatMonth(YearMonth yearMonth) { try { Chronology chrono = getPrimaryChronology(); ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1)); return monthFormatter.withLocale(getLocale()).withChronology(chrono).format(cDate); } catch (DateTimeException ex) { // Date is out of range. return ""; } }
@Override public long until(Temporal endExclusive, TemporalUnit unit) { ChronoLocalDate end = getChronology().date(endExclusive); if (unit instanceof ChronoUnit) { return LocalDate.from(this).until(end, unit); // TODO: this is wrong } return unit.between(this, end); }
private String formatYear(YearMonth yearMonth) { try { Chronology chrono = getPrimaryChronology(); ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1)); return yearFormatter.withLocale(getLocale()) .withChronology(chrono) .withDecimalStyle(DecimalStyle.of(getLocale())) .format(cDate); } catch (DateTimeException ex) { // Date is out of range. return ""; } }
private ValueRange rangeWOWBY(TemporalAccessor temporal) { int sow = weekDef.getFirstDayOfWeek().getValue(); int isoDow = temporal.get(DAY_OF_WEEK); int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1; long woy = localizedWeekOfYear(temporal, dow); if (woy == 0) { return rangeWOWBY(Chronology.from(temporal).date(temporal).minus(2, ChronoUnit.WEEKS)); } int offset = startOfWeekOffset(temporal.get(DAY_OF_YEAR), dow); int year = temporal.get(YEAR); int yearLen = Year.isLeap(year) ? 366 : 365; int weekIndexOfFirstWeekNextYear = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek()); if (woy >= weekIndexOfFirstWeekNextYear) { return rangeWOWBY(Chronology.from(temporal).date(temporal).plus(2, ChronoUnit.WEEKS)); } return ValueRange.of(1, weekIndexOfFirstWeekNextYear - 1); }
private int localizedWOWBY(TemporalAccessor temporal) { int sow = weekDef.getFirstDayOfWeek().getValue(); int isoDow = temporal.get(DAY_OF_WEEK); int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1; long woy = localizedWeekOfYear(temporal, dow); if (woy == 0) { ChronoLocalDate previous = Chronology.from(temporal).date(temporal).minus(1, ChronoUnit.WEEKS); return (int) localizedWeekOfYear(previous, dow) + 1; } else if (woy >= 53) { int offset = startOfWeekOffset(temporal.get(DAY_OF_YEAR), dow); int year = temporal.get(YEAR); int yearLen = Year.isLeap(year) ? 366 : 365; int weekIndexOfFirstWeekNextYear = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek()); if (woy >= weekIndexOfFirstWeekNextYear) { return (int) (woy - (weekIndexOfFirstWeekNextYear - 1)); } } return (int) woy; }