question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ISODateTimeFormat: make millis optional in dateTime format by default

See original GitHub issue

When using joda-time to parse xsd:dateTime values, the developer is forced to choose statically whether their date is a dateTime or as dateTimeNoMillis.

However, it is not uncommon for XML parsers, transformers and XPath engines to optimise xsd:dateTime values with a ,000 fractional part, and completely strip away the milliseconds section.

Try this in Saxon 9.x (XPath 2.0) – probably the most popular XSLT 2.0 parser out there:

'2006-12-28T15:42:04.000+01:00' cast as xs:dateTime

returns

2006-12-28T15:42:04+01:00

Obviously one can create a custom parser with an optional millis part, but this is not intuitive, and certainly not a nice OOTB experience with Joda.

Therefore I propose to modify the dateTime() method to return a formatter that considers the millisecond part as optional OOTB. It doesn’t harm anybody and contributes positively to the usability of Joda.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jodastephencommented, Dec 5, 2013

Changing the meaning of these formats at this point in Joda-Time’s life would essentially be backwards incompatible. The parser is intended for handling variable length input, whereas the dateTime() and dateTimeNoMillis() handle output and parsing of fixed length formats.

0reactions
mrjinkcommented, Jul 2, 2014

The returned formatter prints and parse should be The returned formatter prints and parses. See {@link #dateTimeParser()} for a more flexible parse should be See {@link #dateTimeParser()} for a more flexible parser. This same text occurs 26 and 13 times, respectively.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ISODateTimeFormat (Joda-Time 2.12.1 API)
Returns a generic ISO datetime parser where the date is mandatory and the time is optional. The returned formatter can only be used...
Read more >
java - joda-time ISODateTimeFormat.dateTime() misbehaving
@Abra, all predefined formats in DateTimeFormatter seem to be STRICT . Is there some simple way to get a SMART parser like ISODateTimeFormat....
Read more >
Guide to DateTimeFormatter - Baeldung
Learn how to use the Java 8 DateTimeFormatter class to format and parse dates and times.
Read more >
Class ISODateTimeFormat - Adobe Developer
Factory that creates instances of DateTimeFormatter based on the ISO8601 standard. Date-time formatting is performed by the DateTimeFormatter class.
Read more >
Uses of Class org.joda.time.format.DateTimeFormatter
static DateTimeFormatter, ISODateTimeFormat.basicDateTimeNoMillis() Returns a basic formatter that combines a basic date and time without millis, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found