assertTrue(immutability.test(WeekFields.ISO)); assertTrue(immutability.test(Year.now())); assertTrue(immutability.test(YearMonth.now())); assertTrue(immutability.test(ZoneOffset.UTC)); assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));
/** The license that we'd like enforced. */ private LicenseHeaderStep(String licenseHeader, String delimiter, String yearSeparator) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } // sanitize the input license licenseHeader = LineEnding.toUnix(licenseHeader); if (!licenseHeader.endsWith("\n")) { licenseHeader = licenseHeader + "\n"; } this.licenseHeader = licenseHeader; this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); this.hasYearToken = licenseHeader.contains("$YEAR"); if (this.hasYearToken) { int yearTokenIndex = licenseHeader.indexOf("$YEAR"); this.licenseHeaderBeforeYearToken = licenseHeader.substring(0, yearTokenIndex); this.licenseHeaderAfterYearToken = licenseHeader.substring(yearTokenIndex + 5, licenseHeader.length()); this.licenseHeaderWithYearTokenReplaced = licenseHeader.replace("$YEAR", String.valueOf(YearMonth.now().getYear())); this.yearMatcherPattern = Pattern.compile("[0-9]{4}(" + Pattern.quote(yearSeparator) + "[0-9]{4})?"); } }
private String currentYear() { return String.valueOf(YearMonth.now().getYear()); }
selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now()); selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());
public static YearMonth now(Clock clock) { return YearMonth.now(clock); }
@Override protected YearMonth getReferenceValue(Clock reference) { return YearMonth.now( reference ); }
@Override protected YearMonth getReferenceValue(Clock reference) { return YearMonth.now( reference ); }
@Override protected YearMonth getReferenceValue(Clock reference) { return YearMonth.now( reference ); }
@Override protected YearMonth getReferenceValue(Clock reference) { return YearMonth.now( reference ); }
@Override public String getValueInsertTest() { return YearMonth.now().format(DateTimeFormatter.ofPattern(MMYYYY)); }
/** * Obtains the current year-month from the system clock in the specified time-zone. * <p> * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current year-month. * Specifying the time-zone avoids dependence on the default time-zone. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @param zone the zone ID to use, not null * @return the current year-month using the system clock, not null */ public static YearMonth now(ZoneId zone) { return now(Clock.system(zone)); }
/** * Obtains the current year-month from the system clock in the default time-zone. * <p> * This will query the {@link Clock#systemDefaultZone() system clock} in the default * time-zone to obtain the current year-month. * The zone and offset will be set based on the time-zone in the clock. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @return the current year-month using the system clock and default time-zone, not null */ public static YearMonth now() { return now(Clock.systemDefaultZone()); }
@Test public void testWithNonStandardYearSeparator() throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'nebula.kotlin' version '1.0.6'", " id 'com.diffplug.gradle.spotless'", "}", "repositories { mavenCentral() }", "spotless {", " kotlin {", " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", " ktlint()", " }", "}"); setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/test.kt").matches(matcher -> { matcher.startsWith("// License Header 2012, 2014"); }); assertFile("src/main/kotlin/test2.kt").matches(matcher -> { matcher.startsWith(HEADER_WITH_YEAR.replace("$YEAR", String.valueOf(YearMonth.now().getYear()))); }); } }
@Override public String getValueCloneTest() { return YearMonth.now().minusMonths(1).format(DateTimeFormatter.ofPattern(MMYYYY)); }
@Override public String getValueChangeTest() { return YearMonth.now().minusMonths(2).format(DateTimeFormatter.ofPattern(MMYYYY)); }
/** * setSelectedDate, This sets a date that will be marked as "selected" in the calendar, and sets * the displayed YearMonth to show that date. If the supplied date is null, then the selected * date will be cleared, and the displayed YearMonth will be set to today's year and month. * * Technical note: This is implemented with the following two functions: * setSelectedDateWithoutShowing() and setSelectedYearMonth(). */ public void setSelectedDate(LocalDate selectedDate) { setSelectedDateWithoutShowing(selectedDate); YearMonth yearMonthToShow = (selectedDate == null) ? YearMonth.now() : YearMonth.from(selectedDate); setDisplayedYearMonth(yearMonthToShow); }
public void newRoyalty() { Royalty royalty = new Royalty(); royalty.setAmount(45.5f); royalty.setPayedOn(YearMonth.now()); royaltyRepository.save(royalty); } }
@Test public void testJavaYearMonth() throws Exception { java.time.YearMonth value = java.time.YearMonth.now(); java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles"); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId)); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class); verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli())); verify(ps).setNull(2, Types.DATE); }
@Test public void testCharacterToTime() throws Exception { testConvertFromCharSequence(Instant.now(), DateTimeFormatter.ISO_INSTANT); testConvertFromCharSequence(LocalDate.now(), DateTimeFormatter.ISO_LOCAL_DATE); testConvertFromCharSequence(LocalDateTime.now(), DateTimeFormatter.ISO_LOCAL_DATE_TIME); testConvertFromCharSequence(LocalTime.now(), DateTimeFormatter.ISO_LOCAL_TIME); testConvertFromCharSequence(OffsetDateTime.now(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); testConvertFromCharSequence(OffsetTime.now(), DateTimeFormatter.ISO_OFFSET_TIME); testConvertFromCharSequence(Year.now(), DateTimeFormatter.ofPattern("yyyy")); testConvertFromCharSequence(YearMonth.now(), DateTimeFormatter.ofPattern("yyyy-MM")); testConvertFromCharSequence(ZonedDateTime.now(), DateTimeFormatter.ISO_ZONED_DATE_TIME); }