java.time.YearMonth Java Examples
The following examples show how to use
java.time.YearMonth.
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: TCKYearMonth.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
void doTest_comparisons_YearMonth(YearMonth... localDates) { for (int i = 0; i < localDates.length; i++) { YearMonth a = localDates[i]; for (int j = 0; j < localDates.length; j++) { YearMonth b = localDates[j]; if (i < j) { assertTrue(a.compareTo(b) < 0, a + " <=> " + b); assertEquals(a.isBefore(b), true, a + " <=> " + b); assertEquals(a.isAfter(b), false, a + " <=> " + b); assertEquals(a.equals(b), false, a + " <=> " + b); } else if (i > j) { assertTrue(a.compareTo(b) > 0, a + " <=> " + b); assertEquals(a.isBefore(b), false, a + " <=> " + b); assertEquals(a.isAfter(b), true, a + " <=> " + b); assertEquals(a.equals(b), false, a + " <=> " + b); } else { assertEquals(a.compareTo(b), 0, a + " <=> " + b); assertEquals(a.isBefore(b), false, a + " <=> " + b); assertEquals(a.isAfter(b), false, a + " <=> " + b); assertEquals(a.equals(b), true, a + " <=> " + b); } } } }
Example #2
Source File: CronExpression.java From cron with Apache License 2.0 | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { YearMonth ym = YearMonth.of(dato.getYear(), dato.getMonth().getValue()); return dato.getDayOfWeek() == DayOfWeek.of(part.from) && dato.getDayOfMonth() > (ym.lengthOfMonth() - 7); } else if ("#".equals(part.incrementModifier)) { if (dato.getDayOfWeek() == DayOfWeek.of(part.from)) { int num = dato.getDayOfMonth() / 7; return part.increment == (dato.getDayOfMonth() % 7 == 0 ? num : num + 1); } return false; } else if (matches(dato.getDayOfWeek().getValue(), part)) { return true; } } return false; }
Example #3
Source File: TCKYearMonth.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_equals() { YearMonth a = YearMonth.of(2008, 6); YearMonth b = YearMonth.of(2008, 6); YearMonth c = YearMonth.of(2007, 6); YearMonth d = YearMonth.of(2008, 5); assertEquals(a.equals(a), true); assertEquals(a.equals(b), true); assertEquals(a.equals(c), false); assertEquals(a.equals(d), false); assertEquals(b.equals(a), true); assertEquals(b.equals(b), true); assertEquals(b.equals(c), false); assertEquals(b.equals(d), false); assertEquals(c.equals(a), false); assertEquals(c.equals(b), false); assertEquals(c.equals(c), true); assertEquals(c.equals(d), false); assertEquals(d.equals(a), false); assertEquals(d.equals(b), false); assertEquals(d.equals(c), false); assertEquals(d.equals(d), true); }
Example #4
Source File: YearMonthSerializationTest.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Test public void testSerializationAsTimestamp01() throws Exception { YearMonth yearMonth = YearMonth.of(1986, Month.JANUARY); String value = MAPPER.writer() .with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(yearMonth); assertNotNull("The value should not be null.", value); assertEquals("The value is not correct.", "[1986,1]", value); }
Example #5
Source File: TCKDateTimeFormatterBuilder.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_padOptional() throws Exception { builder.appendValue(MONTH_OF_YEAR).appendLiteral(':') .padNext(5).optionalStart().appendValue(DAY_OF_MONTH).optionalEnd() .appendLiteral(':').appendValue(YEAR); assertEquals(builder.toFormatter().format(LocalDate.of(2013, 2, 1)), "2: 1:2013"); assertEquals(builder.toFormatter().format(YearMonth.of(2013, 2)), "2: :2013"); }
Example #6
Source File: TCKMonthDay.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_hashCode_unique() { int leapYear = 2008; Set<Integer> uniques = new HashSet<Integer>(366); for (int i = 1; i <= 12; i++) { for (int j = 1; j <= 31; j++) { if (YearMonth.of(leapYear, i).isValidDay(j)) { assertTrue(uniques.add(MonthDay.of(i, j).hashCode())); } } } }
Example #7
Source File: TCKYearMonth.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="minus_long_TemporalUnit") public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) { if (expectedEx == null) { assertEquals(base.minus(amount, unit), expectedYearMonth); } else { try { YearMonth result = base.minus(amount, unit); fail(); } catch (Exception ex) { assertTrue(expectedEx.isInstance(ex)); } } }
Example #8
Source File: TCKYearMonth.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_equals() { YearMonth a = YearMonth.of(2008, 6); YearMonth b = YearMonth.of(2008, 6); YearMonth c = YearMonth.of(2007, 6); YearMonth d = YearMonth.of(2008, 5); assertEquals(a.equals(a), true); assertEquals(a.equals(b), true); assertEquals(a.equals(c), false); assertEquals(a.equals(d), false); assertEquals(b.equals(a), true); assertEquals(b.equals(b), true); assertEquals(b.equals(c), false); assertEquals(b.equals(d), false); assertEquals(c.equals(a), false); assertEquals(c.equals(b), false); assertEquals(c.equals(c), true); assertEquals(c.equals(d), false); assertEquals(d.equals(a), false); assertEquals(d.equals(b), false); assertEquals(d.equals(c), false); assertEquals(d.equals(d), true); }
Example #9
Source File: SimplePriceIndexValues.java From Strata with Apache License 2.0 | 5 votes |
@Override public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) { YearMonth fixingMonth = observation.getFixingMonth(); // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(fixingMonth.atEndOfMonth()).isPresent()) { return PointSensitivityBuilder.none(); } } return InflationRateSensitivity.of(observation, 1d); }
Example #10
Source File: YearMonthChangeEvent.java From LGoodDatePicker with MIT License | 5 votes |
/** * Constructor. */ public YearMonthChangeEvent(CalendarPanel source, YearMonth newYearMonth, YearMonth oldYearMonth) { this.source = source; this.newYearMonth = newYearMonth; this.oldYearMonth = oldYearMonth; }
Example #11
Source File: IborFutureCurveNodeTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_metadata_last_fixing() { IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.LAST_FIXING); ImmutableMarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, 0.0d).build(); IborFutureTrade trade = node.trade(1d, marketData, REF_DATA); LocalDate fixingDate = trade.getProduct().getFixingDate(); DatedParameterMetadata metadata = node.metadata(VAL_DATE, REF_DATA); assertThat(metadata.getDate()).isEqualTo(fixingDate); LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(VAL_DATE, REF_DATA); assertThat(((YearMonthDateParameterMetadata) metadata).getYearMonth()).isEqualTo(YearMonth.from(referenceDate)); }
Example #12
Source File: TCKYearMonth.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_isValidDay_int_june() { YearMonth test = YearMonth.of(2007, 6); assertEquals(test.isValidDay(1), true); assertEquals(test.isValidDay(30), true); assertEquals(test.isValidDay(-1), false); assertEquals(test.isValidDay(0), false); assertEquals(test.isValidDay(31), false); assertEquals(test.isValidDay(32), false); }
Example #13
Source File: TCKYearMonthSerialization.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { dos.writeByte(12); // java.time.temporal.Ser.YEAR_MONTH_TYPE dos.writeInt(2012); dos.writeByte(9); } byte[] bytes = baos.toByteArray(); assertSerializedBySer(YearMonth.of(2012, 9), bytes); }
Example #14
Source File: TCKYearMonth.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="sampleDates") public void test_get(int y, int m) { YearMonth a = YearMonth.of(y, m); assertEquals(a.getYear(), y); assertEquals(a.getMonth(), Month.of(m)); assertEquals(a.getMonthValue(), m); }
Example #15
Source File: TestDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_errorMessage() throws Exception { assertGoodErrorDate(DayOfWeek::from, "DayOfWeek"); assertGoodErrorDate(Month::from, "Month"); assertGoodErrorDate(YearMonth::from, "YearMonth"); assertGoodErrorDate(MonthDay::from, "MonthDay"); assertGoodErrorDate(LocalDate::from, "LocalDate"); assertGoodErrorDate(LocalTime::from, "LocalTime"); assertGoodErrorDate(LocalDateTime::from, "LocalDateTime"); assertGoodErrorDate(OffsetTime::from, "OffsetTime"); assertGoodErrorDate(OffsetDateTime::from, "OffsetDateTime"); assertGoodErrorDate(ZonedDateTime::from, "ZonedDateTime"); assertGoodErrorDate(Instant::from, "Instant"); assertGoodErrorDate(ZoneOffset::from, "ZoneOffset"); assertGoodErrorDate(ZoneId::from, "ZoneId"); assertGoodErrorDate(ThaiBuddhistChronology.INSTANCE::date, ""); assertGoodErrorTime(DayOfWeek::from, "DayOfWeek"); assertGoodErrorTime(Month::from, "Month"); assertGoodErrorTime(Year::from, "Year"); assertGoodErrorTime(YearMonth::from, "YearMonth"); assertGoodErrorTime(MonthDay::from, "MonthDay"); assertGoodErrorTime(LocalDate::from, "LocalDate"); assertGoodErrorTime(LocalTime::from, "LocalTime"); assertGoodErrorTime(LocalDateTime::from, "LocalDateTime"); assertGoodErrorTime(OffsetTime::from, "OffsetTime"); assertGoodErrorTime(OffsetDateTime::from, "OffsetDateTime"); assertGoodErrorTime(ZonedDateTime::from, "ZonedDateTime"); assertGoodErrorTime(Instant::from, "Instant"); assertGoodErrorTime(ZoneOffset::from, "ZoneOffset"); assertGoodErrorTime(ZoneId::from, "ZoneId"); assertGoodErrorTime(ThaiBuddhistChronology.INSTANCE::date, ""); }
Example #16
Source File: TCKYearMonth.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_isValidDay_int_febLeap() { YearMonth test = YearMonth.of(2008, 2); assertEquals(test.isValidDay(1), true); assertEquals(test.isValidDay(29), true); assertEquals(test.isValidDay(-1), false); assertEquals(test.isValidDay(0), false); assertEquals(test.isValidDay(30), false); assertEquals(test.isValidDay(32), false); }
Example #17
Source File: TCKYearMonth.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_isValidDay_int_febNonLeap() { YearMonth test = YearMonth.of(2007, 2); assertEquals(test.isValidDay(1), true); assertEquals(test.isValidDay(28), true); assertEquals(test.isValidDay(-1), false); assertEquals(test.isValidDay(0), false); assertEquals(test.isValidDay(29), false); assertEquals(test.isValidDay(32), false); }
Example #18
Source File: TCKYearMonth.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_isValidDay_int_febLeap() { YearMonth test = YearMonth.of(2008, 2); assertEquals(test.isValidDay(1), true); assertEquals(test.isValidDay(29), true); assertEquals(test.isValidDay(-1), false); assertEquals(test.isValidDay(0), false); assertEquals(test.isValidDay(30), false); assertEquals(test.isValidDay(32), false); }
Example #19
Source File: TCKYearMonth.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="minus_long_TemporalUnit") public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) { if (expectedEx == null) { assertEquals(base.minus(amount, unit), expectedYearMonth); } else { try { YearMonth result = base.minus(amount, unit); fail(); } catch (Exception ex) { assertTrue(expectedEx.isInstance(ex)); } } }
Example #20
Source File: IsExpiredTest.java From creditcardnumber with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void isExpired3() { final YearMonth expirationDateLastMonth = YearMonth.now() .minus(1, ChronoUnit.MONTHS); check(expirationDateLastMonth, true); }
Example #21
Source File: TCKDateTimeFormatterBuilder.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_padOptional() throws Exception { builder.appendValue(MONTH_OF_YEAR).appendLiteral(':') .padNext(5).optionalStart().appendValue(DAY_OF_MONTH).optionalEnd() .appendLiteral(':').appendValue(YEAR); assertEquals(builder.toFormatter().format(LocalDate.of(2013, 2, 1)), "2: 1:2013"); assertEquals(builder.toFormatter().format(YearMonth.of(2013, 2)), "2: :2013"); }
Example #22
Source File: TCKYearMonth.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); YearMonth expected = YearMonth.now(Clock.system(zone)); YearMonth test = YearMonth.now(zone); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = YearMonth.now(Clock.system(zone)); test = YearMonth.now(zone); } assertEquals(test, expected); }
Example #23
Source File: TCKYearMonth.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="goodParseData") Object[][] provider_goodParseData() { return new Object[][] { {"0000-01", YearMonth.of(0, 1)}, {"0000-12", YearMonth.of(0, 12)}, {"9999-12", YearMonth.of(9999, 12)}, {"2000-01", YearMonth.of(2000, 1)}, {"2000-02", YearMonth.of(2000, 2)}, {"2000-03", YearMonth.of(2000, 3)}, {"2000-04", YearMonth.of(2000, 4)}, {"2000-05", YearMonth.of(2000, 5)}, {"2000-06", YearMonth.of(2000, 6)}, {"2000-07", YearMonth.of(2000, 7)}, {"2000-08", YearMonth.of(2000, 8)}, {"2000-09", YearMonth.of(2000, 9)}, {"2000-10", YearMonth.of(2000, 10)}, {"2000-11", YearMonth.of(2000, 11)}, {"2000-12", YearMonth.of(2000, 12)}, {"+12345678-03", YearMonth.of(12345678, 3)}, {"+123456-03", YearMonth.of(123456, 3)}, {"0000-03", YearMonth.of(0, 3)}, {"-1234-03", YearMonth.of(-1234, 3)}, {"-12345678-03", YearMonth.of(-12345678, 3)}, {"+" + Year.MAX_VALUE + "-03", YearMonth.of(Year.MAX_VALUE, 3)}, {Year.MIN_VALUE + "-03", YearMonth.of(Year.MIN_VALUE, 3)}, }; }
Example #24
Source File: TCKYearMonth.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="plus_TemporalAmount") public void test_plus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class<?> expectedEx) { if (expectedEx == null) { assertEquals(base.plus(temporalAmount), expectedYearMonth); } else { try { YearMonth result = base.plus(temporalAmount); fail(); } catch (Exception ex) { assertTrue(expectedEx.isInstance(ex)); } } }
Example #25
Source File: EtdFutureSecurityTest.java From Strata with Apache License 2.0 | 5 votes |
static EtdFutureSecurity sut() { return EtdFutureSecurity.builder() .info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))) .contractSpecId(EtdContractSpecId.of("test", "123")) .expiry(YearMonth.of(2017, 6)) .build(); }
Example #26
Source File: YearMonthFormatter.java From java-technology-stack with MIT License | 4 votes |
@Override public YearMonth parse(String text, Locale locale) throws ParseException { return YearMonth.parse(text); }
Example #27
Source File: TCKYearMonth.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void test_until_convertedType() { YearMonth start = YearMonth.of(2010, 6); LocalDate end = start.plusMonths(2).atDay(12); assertEquals(start.until(end, MONTHS), 2); }
Example #28
Source File: TCKYearMonth.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test public void test_adjustDate() { YearMonth test = YearMonth.of(2008, 6); LocalDate date = LocalDate.of(2007, 1, 1); assertEquals(test.adjustInto(date), LocalDate.of(2008, 6, 1)); }
Example #29
Source File: TCKYear.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test public void test_atMonth_int() { Year test = Year.of(2008); assertEquals(test.atMonth(6), YearMonth.of(2008, 6)); }
Example #30
Source File: TCKYearMonth.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_minusYears_long_invalidTooLargeMaxSubtractMin() { YearMonth test = YearMonth.of(Year.MIN_VALUE, 12); test.minusYears(Long.MIN_VALUE); }