use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKJapaneseChronology method test_chrono_byLocale_oldJP_variant.
@Test
public void test_chrono_byLocale_oldJP_variant() {
Chronology test = Chronology.ofLocale(new Locale("ja", "JP", "JP"));
Assert.assertEquals(test.getId(), "Japanese");
Assert.assertEquals(test, JapaneseChronology.INSTANCE);
}
use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TestIsoChronology method test_chrono_byName.
//-----------------------------------------------------------------------
// Chronology.ofName("ISO") Lookup by name
//-----------------------------------------------------------------------
@Test
public void test_chrono_byName() {
Chronology c = IsoChronology.INSTANCE;
Chronology test = Chronology.of("ISO");
Assert.assertNotNull(test, "The ISO calendar could not be found byName");
Assert.assertEquals(test.getId(), "ISO", "ID mismatch");
Assert.assertEquals(test.getCalendarType(), "iso8601", "Type mismatch");
Assert.assertEquals(test, c);
}
use of java.time.chrono.Chronology in project Bytecoder by mirkosertic.
the class Period method validateChrono.
/**
* Validates that the temporal has the correct chronology.
*/
private void validateChrono(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
}
}
use of java.time.chrono.Chronology in project Bytecoder by mirkosertic.
the class DateTimePrintContext method adjust.
private static TemporalAccessor adjust(final TemporalAccessor temporal, DateTimeFormatter formatter) {
// normal case first (early return is an optimization)
Chronology overrideChrono = formatter.getChronology();
ZoneId overrideZone = formatter.getZone();
if (overrideChrono == null && overrideZone == null) {
return temporal;
}
// ensure minimal change (early return is an optimization)
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
ZoneId temporalZone = temporal.query(TemporalQueries.zoneId());
if (Objects.equals(overrideChrono, temporalChrono)) {
overrideChrono = null;
}
if (Objects.equals(overrideZone, temporalZone)) {
overrideZone = null;
}
if (overrideChrono == null && overrideZone == null) {
return temporal;
}
// make adjustment
final Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono);
if (overrideZone != null) {
// if have zone and instant, calculation is simple, defaulting chrono if necessary
if (temporal.isSupported(INSTANT_SECONDS)) {
Chronology chrono = Objects.requireNonNullElse(effectiveChrono, IsoChronology.INSTANCE);
return chrono.zonedDateTime(Instant.from(temporal), overrideZone);
}
// block changing zone on OffsetTime, and similar problem cases
if (overrideZone.normalized() instanceof ZoneOffset && temporal.isSupported(OFFSET_SECONDS) && temporal.get(OFFSET_SECONDS) != overrideZone.getRules().getOffset(Instant.EPOCH).getTotalSeconds()) {
throw new DateTimeException("Unable to apply override zone '" + overrideZone + "' because the temporal object being formatted has a different offset but" + " does not represent an instant: " + temporal);
}
}
final ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
final ChronoLocalDate effectiveDate;
if (overrideChrono != null) {
if (temporal.isSupported(EPOCH_DAY)) {
effectiveDate = effectiveChrono.date(temporal);
} else {
// check for date fields other than epoch-day, ignoring case of converting null to ISO
if (!(overrideChrono == IsoChronology.INSTANCE && temporalChrono == null)) {
for (ChronoField f : ChronoField.values()) {
if (f.isDateBased() && temporal.isSupported(f)) {
throw new DateTimeException("Unable to apply override chronology '" + overrideChrono + "' because the temporal object being formatted contains date fields but" + " does not represent a whole date: " + temporal);
}
}
}
effectiveDate = null;
}
} else {
effectiveDate = null;
}
// this better handles map-like underlying temporal instances
return new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
if (effectiveDate != null && field.isDateBased()) {
return effectiveDate.isSupported(field);
}
return temporal.isSupported(field);
}
@Override
public ValueRange range(TemporalField field) {
if (effectiveDate != null && field.isDateBased()) {
return effectiveDate.range(field);
}
return temporal.range(field);
}
@Override
public long getLong(TemporalField field) {
if (effectiveDate != null && field.isDateBased()) {
return effectiveDate.getLong(field);
}
return temporal.getLong(field);
}
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
return (R) effectiveChrono;
}
if (query == TemporalQueries.zoneId()) {
return (R) effectiveZone;
}
if (query == TemporalQueries.precision()) {
return temporal.query(query);
}
return query.queryFrom(this);
}
@Override
public String toString() {
return temporal + (effectiveChrono != null ? " with chronology " + effectiveChrono : "") + (effectiveZone != null ? " with zone " + effectiveZone : "");
}
};
}
use of java.time.chrono.Chronology in project JFoenix by jfoenixadmin.
the class JFXDatePickerContent method updateDayCells.
private void updateDayCells() {
Locale locale = getLocale();
Chronology chrono = getPrimaryChronology();
// get the index of the first day of the month
int firstDayOfWeek = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue();
int firstOfMonthIndex = selectedYearMonth.get().atDay(1).getDayOfWeek().getValue() - firstDayOfWeek;
firstOfMonthIndex += firstOfMonthIndex < 0 ? daysPerWeek : 0;
YearMonth currentYearMonth = selectedYearMonth.get();
int daysInCurMonth = -1;
for (int i = 0; i < 6 * daysPerWeek; i++) {
DateCell dayCell = dayCells.get(i);
dayCell.getStyleClass().setAll("cell", "date-cell", "day-cell");
dayCell.setPrefSize(40, 42);
dayCell.setDisable(false);
dayCell.setStyle(null);
dayCell.setGraphic(null);
dayCell.setTooltip(null);
dayCell.setTextFill(DEFAULT_COLOR);
dayCell.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
try {
if (daysInCurMonth == -1) {
daysInCurMonth = currentYearMonth.lengthOfMonth();
}
int dayIndex = i - firstOfMonthIndex + 1;
LocalDate date = currentYearMonth.atDay(dayIndex);
dayCellDates[i] = date;
// if it's today
if (date.equals(LocalDate.now())) {
dayCell.setTextFill(this.datePicker.getDefaultColor());
dayCell.getStyleClass().add("today");
}
// if it's the current selected value
if (date.equals(datePicker.getValue())) {
dayCell.getStyleClass().add("selected");
dayCell.setTextFill(Color.WHITE);
dayCell.setBackground(new Background(new BackgroundFill(this.datePicker.getDefaultColor(), new CornerRadii(40), Insets.EMPTY)));
}
ChronoLocalDate cDate = chrono.date(date);
String cellText = dayCellFormatter.withLocale(locale).withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale)).format(cDate);
dayCell.setText(cellText);
if (i < firstOfMonthIndex) {
dayCell.getStyleClass().add("previous-month");
dayCell.setText("");
} else if (i >= firstOfMonthIndex + daysInCurMonth) {
dayCell.getStyleClass().add("next-month");
dayCell.setText("");
}
// update cell item
dayCell.updateItem(date, false);
} catch (DateTimeException ex) {
// Disable day cell if its date is out of range
dayCell.setText("");
dayCell.setDisable(true);
}
}
}
Aggregations