Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug in java.time.Duration

Tags:

I need to parse Durations from strings. Java 8 provide a method for that taking the ISO-8601 standard as a basis:

Duration.parse("p10d"); // parses as ten days
Duration.parse("pt1h"); // parses as one hour

As the standard states that "it is permitted to omit the 'T' character by mutual agreement" some of the Javadoc examples of Durations.parse() leave out the T. According to them, the following expression should parse as "-6 hours and +3 minutes":

"P-6H3M"

But I found that all expressions ommitting the T throw a DateTimeParseException. Is that a bug in the parse() method or am I missing something?