Skip to content

Commit

Permalink
fix: make time even more lenient
Browse files Browse the repository at this point in the history
it is now allowed to provide only a time
  • Loading branch information
qixils committed Dec 22, 2023
1 parent 81224bb commit e9c8a25
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ public class ZonedDateTimeConverter implements Converter<String, ZonedDateTime>
}

// error if date is invalid
if (month == 0 || day == 0 || month > 12 || day > 31)
var now = ZonedDateTime.now(zone);
boolean autoDate = month == 0 && day == 0 && year == 0;
if (autoDate) {
year = now.getYear();
month = now.getMonthValue();
day = now.getDayOfMonth();
}
else if (month < 1 || day < 1 || year == 0 || month > 12 || day > 31)
throw new UserError(library("exception.invalid_date"));

// get time
Expand Down Expand Up @@ -91,6 +98,9 @@ else if (meridiem == 'a' && hour == 12)
hour = 0;

// return
return ZonedDateTime.of(year, month, day, hour, minute, second, nanos, zone);
var zdt = ZonedDateTime.of(year, month, day, hour, minute, second, nanos, zone);
if (zdt.isBefore(now) && autoDate)
zdt = zdt.plusDays(1); // TODO: this might pose accuracy issues around daylight savings crossovers?
return zdt;
}
}

0 comments on commit e9c8a25

Please sign in to comment.