java.time.chrono.Chronology Java Examples
The following examples show how to use
java.time.chrono.Chronology.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TCKChronoZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedTemporalUnit(czdt2); if (chrono != chrono2) { try { czdt.plus(1, adjuster); Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt + " can not be cast to " + czdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.plus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
Example #2
Source File: TCKChronoZonedDateTime.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badMinusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedTemporalUnit(czdt2); if (chrono != chrono2) { try { czdt.minus(1, adjuster); Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass()); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.minus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
Example #3
Source File: TCKChronoLocalDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDate date = chrono.date(refDate); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDate date2 = chrono2.date(refDate); TemporalAmount adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.plus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDate result = date.plus(adjuster); assertEquals(result, date2, "WithAdjuster failed to replace date"); } } }
Example #4
Source File: TCKChronoLocalDateTime.java From j2objc with Apache License 2.0 | 6 votes |
@Test @UseDataProvider("data_of_calendars") public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : (Chronology[][]) data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalUnit adjuster = new FixedTemporalUnit(cdt2); if (chrono != chrono2) { try { cdt.plus(1, adjuster); Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.plus(1, adjuster); assertEquals("WithAdjuster failed to replace date", result, cdt2); } } }
Example #5
Source File: TCKChronoLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalUnit adjuster = new FixedTemporalUnit(cdt2); if (chrono != chrono2) { try { cdt.plus(1, adjuster); Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.plus(1, adjuster); assertEquals(result, cdt2, "WithAdjuster failed to replace date"); } } }
Example #6
Source File: TCKChronoLocalDate.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badWithAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDate date = chrono.date(refDate); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDate date2 = chrono2.date(refDate); TemporalAdjuster adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.with(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDate result = date.with(adjuster); assertEquals(result, date2, "WithAdjuster failed to replace date"); } } }
Example #7
Source File: TCKChronoLocalDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badMinusAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalAmount adjuster = new FixedAdjuster(cdt2); if (chrono != chrono2) { try { cdt.minus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.minus(adjuster); assertEquals(result, cdt2, "WithAdjuster failed to replace date"); } } }
Example #8
Source File: TCKChronoLocalDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalUnit adjuster = new FixedTemporalUnit(cdt2); if (chrono != chrono2) { try { cdt.plus(1, adjuster); Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.plus(1, adjuster); assertEquals(result, cdt2, "WithAdjuster failed to replace date"); } } }
Example #9
Source File: WeekFields.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Returns the week of week-based-year for the temporal. * The week can be part of the previous year, the current year, * or the next year depending on the week start and minimum number * of days. * @param temporal a date of any chronology * @return the week of the year * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor) */ private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) { int dow = localizedDayOfWeek(temporal); int doy = temporal.get(DAY_OF_YEAR); int offset = startOfWeekOffset(doy, dow); int week = computeWeek(offset, doy); if (week == 0) { // Day is in end of week of previous year // Recompute from the last day of the previous year ChronoLocalDate date = Chronology.from(temporal).date(temporal); date = date.minus(doy, DAYS); // Back down into previous year return localizedWeekOfWeekBasedYear(date); } else if (week > 50) { // If getting close to end of year, use higher precision logic // Check if date of year is in partial week associated with next year ValueRange dayRange = temporal.range(DAY_OF_YEAR); int yearLen = (int)dayRange.getMaximum(); int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek()); if (week >= newYearWeek) { // Overlaps with week of following year; reduce to week in following year week = week - newYearWeek + 1; } } return week; }
Example #10
Source File: TCKChronoZonedDateTime.java From hottub with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}, }; }
Example #11
Source File: TCKChronoPeriod.java From j2objc with Apache License 2.0 | 5 votes |
@Test() @UseDataProvider("data_of_calendars") public void test_isZero_isNegative(Chronology chrono) { ChronoPeriod periodPositive = chrono.period(1, 2, 3); assertEquals(periodPositive.isZero(), false); assertEquals(periodPositive.isNegative(), false); ChronoPeriod periodZero = chrono.period(0, 0, 0); assertEquals(periodZero.isZero(), true); assertEquals(periodZero.isNegative(), false); ChronoPeriod periodNegative = chrono.period(-1, 0, 0); assertEquals(periodNegative.isZero(), false); assertEquals(periodNegative.isNegative(), true); }
Example #12
Source File: DateTimeTextProvider.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Gets the text for the specified chrono, field, locale and style * for the purpose of formatting. * <p> * The text associated with the value is returned. * The null return value should be used if there is no applicable text, or * if the text would be a numeric representation of the value. * * @param chrono the Chronology to get text for, not null * @param field the field to get text for, not null * @param value the field value to get text for, not null * @param style the style to get text for, not null * @param locale the locale to get text for, not null * @return the text for the field value, null if no text found */ public String getText(Chronology chrono, TemporalField field, long value, TextStyle style, Locale locale) { if (chrono == IsoChronology.INSTANCE || !(field instanceof ChronoField)) { return getText(field, value, style, locale); } int fieldIndex; int fieldValue; if (field == ERA) { fieldIndex = Calendar.ERA; if (chrono == JapaneseChronology.INSTANCE) { if (value == -999) { fieldValue = 0; } else { fieldValue = (int) value + 2; } } else { fieldValue = (int) value; } } else if (field == MONTH_OF_YEAR) { fieldIndex = Calendar.MONTH; fieldValue = (int) value - 1; } else if (field == DAY_OF_WEEK) { fieldIndex = Calendar.DAY_OF_WEEK; fieldValue = (int) value + 1; if (fieldValue > 7) { fieldValue = Calendar.SUNDAY; } } else if (field == AMPM_OF_DAY) { fieldIndex = Calendar.AM_PM; fieldValue = (int) value; } else { return null; } return CalendarDataUtility.retrieveJavaTimeFieldValueName( chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale); }
Example #13
Source File: TCKChronology.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Test lookup by calendarType of each chronology. * Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}. */ @Test public void test_ofLocaleByType() { // Test that all available chronologies can be successfully found using ofLocale Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType()); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type"); } }
Example #14
Source File: DateTimeFormatterBuilder.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Gets the formatting pattern for date and time styles for a locale and chronology. * The locale and chronology are used to lookup the locale specific format * for the requested dateStyle and/or timeStyle. * * @param dateStyle the FormatStyle for the date * @param timeStyle the FormatStyle for the time * @param chrono the Chronology, non-null * @param locale the locale, non-null * @return the locale and Chronology specific formatting pattern * @throws IllegalArgumentException if both dateStyle and timeStyle are null */ public static String getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle, Chronology chrono, Locale locale) { Objects.requireNonNull(locale, "locale"); Objects.requireNonNull(chrono, "chrono"); if (dateStyle == null && timeStyle == null) { throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null"); } LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased().getLocaleResources(locale); String pattern = lr.getJavaTimeDateTimePattern( convertStyle(timeStyle), convertStyle(dateStyle), chrono.getCalendarType()); return pattern; }
Example #15
Source File: DateTimeParseContext.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Adds a Consumer<Chronology> to the list of listeners to be notified * if the Chronology changes. * @param listener a Consumer<Chronology> to be called when Chronology changes */ void addChronoChangedListener(Consumer<Chronology> listener) { if (chronoListeners == null) { chronoListeners = new ArrayList<Consumer<Chronology>>(); } chronoListeners.add(listener); }
Example #16
Source File: TCKTestServiceLoader.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_TestServiceLoader() { Chronology chrono = Chronology.of("Coptic"); ChronoLocalDate copticDate = chrono.date(1729, 4, 27); LocalDate ld = LocalDate.from(copticDate); assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate"); }
Example #17
Source File: TCKChronoPeriod.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") public void test_get(Chronology chrono) { ChronoPeriod period = chrono.period(1, 2, 3); assertEquals(period.get(YEARS), 1); assertEquals(period.get(MONTHS), 2); assertEquals(period.get(DAYS), 3); }
Example #18
Source File: TCKChronoPeriod.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") public void test_equals_equal(Chronology chrono) { ChronoPeriod a1 = chrono.period(1, 2, 3); ChronoPeriod a2 = chrono.period(1, 2, 3); assertEquals(a1, a1); assertEquals(a1, a2); assertEquals(a2, a1); assertEquals(a2, a2); assertEquals(a1.hashCode(), a2.hashCode()); }
Example #19
Source File: TCKChronoLocalDateTimeSerialization.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}}; }
Example #20
Source File: DateTimeFormatterBuilder.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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]) { // Use the reduced value if it fits in minWidth return absValue % EXCEED_POINTS[minWidth]; } // Otherwise truncate to fit in maxWidth return absValue % EXCEED_POINTS[maxWidth]; }
Example #21
Source File: TCKChronoPeriod.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}}; }
Example #22
Source File: TCKChronoPeriod.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") public void test_getUnits(Chronology chrono) { ChronoPeriod period = chrono.period(1, 2, 3); assertEquals(period.getUnits().size(), 3); assertEquals(period.getUnits().get(0), YEARS); assertEquals(period.getUnits().get(1), MONTHS); assertEquals(period.getUnits().get(2), DAYS); }
Example #23
Source File: TCKChronoPeriod.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}}; }
Example #24
Source File: TCKChronoLocalDate.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}}; }
Example #25
Source File: TCKChronology.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_calendar_list() { Set<Chronology> chronos = Chronology.getAvailableChronologies(); assertNotNull(chronos, "Required list of calendars must be non-null"); for (Chronology chrono : chronos) { Chronology lookup = Chronology.of(chrono.getId()); assertNotNull(lookup, "Required calendar not found: " + chrono); } assertEquals(chronos.size() >= data_of_calendars().length, true, "Chronology.getAvailableChronologies().size = " + chronos.size() + ", expected >= " + data_of_calendars().length); }
Example #26
Source File: TCKChronoLocalDate.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") public void test_from_TemporalAccessor(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDate date = chrono.date(refDate); ChronoLocalDate test1 = ChronoLocalDate.from(date); assertEquals(test1, date); ChronoLocalDate test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30))); assertEquals(test2, date); ChronoLocalDate test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC)); assertEquals(test3, date); }
Example #27
Source File: TCKChronoZonedDateTimeSerialization.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}, }; }
Example #28
Source File: TestNonIsoFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="format_data") public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, ChronoLocalDate date, String expected) { DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) .withChronology(chrono).withLocale(formatLocale) .withDecimalStyle(DecimalStyle.of(numberingLocale)); String text = dtf.format(date); assertEquals(text, expected); }
Example #29
Source File: TCKChronoLocalDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "calendars") Chronology[][] data_of_calendars() { return new Chronology[][]{ {HijrahChronology.INSTANCE}, {IsoChronology.INSTANCE}, {JapaneseChronology.INSTANCE}, {MinguoChronology.INSTANCE}, {ThaiBuddhistChronology.INSTANCE}}; }
Example #30
Source File: TCKChronologySerialization.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") private void test_serializationBytes(Chronology chrono) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { dos.writeByte(CHRONO_TYPE); dos.writeUTF(chrono.getId()); } byte[] bytes = baos.toByteArray(); assertSerializedBySer(chrono, bytes); }