Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Function<String, ZonedDateTime> getFunction(String format, ZoneId zoneId, Locale
// fill the rest of the date up with the parsed date
if (accessor.isSupported(ChronoField.YEAR) == false
&& accessor.isSupported(ChronoField.YEAR_OF_ERA) == false
&& accessor.isSupported(WeekFields.of(locale).weekOfWeekBasedYear()) == false) {
&& accessor.isSupported(WeekFields.of(locale).weekBasedYear()) == false) {
int year = LocalDate.now(ZoneOffset.UTC).getYear();
ZonedDateTime newTime = Instant.EPOCH.atZone(ZoneOffset.UTC).withYear(year);
for (ChronoField field : FIELDS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@ public void testParseJavaDefaultYear() {
assertThat(dateTime.getYear(), is(year));
}

public void testParseWeekBased() {
String format = randomFrom("YYYY-ww");
public void testParseWeekBasedYearAndWeek() {
String format = "YYYY-ww";
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.ROOT);
ZonedDateTime dateTime = javaFunction.apply("2020-33");
assertThat(dateTime, equalTo(ZonedDateTime.of(2020,8,10,0,0,0,0,timezone)));
}

public void testParseWeekBasedYear() {
String format = "YYYY";
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.ROOT);
ZonedDateTime dateTime = javaFunction.apply("2019");
assertThat(dateTime, equalTo(ZonedDateTime.of(2018,12,31,0,0,0,0,timezone)));
}

public void testParseWeekBasedWithLocale() {
String format = randomFrom("YYYY-ww");
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
Expand Down