Today I came across a blog post from Daniel Nashed about international date conversion. It's a problem I came across about a year ago with getting JSON dates from Notes fields in ODA. The code there was getting the GMT format by parsing specifically for US date formats. For a temporary workaround at the time, for my server, I changed it to UK format. Then a few month ago we had an issue raised on ODA for the same issue.

Because we could use Java 8, we were using the LocalDate Java class to parse a date string. The problem is that date formats come in multiple ways - MDY for US, DMY for much of the rest of the world, but also YMD. And then different countries have different separators. And as I dug even deeper, there's an additional challenge that times are also handled differently on different servers - 24 hour time or 12 hour time + am/pm.

Fortunately Java (and LotusScript) have the International class (or NotesInternational class in LS). This is a property of the Session (or NotesSession) and will get the current operating system's internationalisation settings. There are various methods available relevant here:

  • International.getDateSep() to get the separator between portions of the date, e.g. "/" or "-"
  • International.isDateMDY() to check whether it's US date format
  • International.isDateDMY() to check whether the day comes first
  • International.isDateYMD() to check whether the year comes first
  • International.isTime24Hour() to check if it's 24 hour time format, so 14:00 instead of 2:00pm

Combining all of these allows you to build a date formatter amd date-time formatter for converting the date/time to a ISO format string, as I did in ODA's Session class. We used the java.time.format.DateTimeFormatterBuilder class to build a java.time.format.DateTimeFormatter offsetting to GMT, which is what's used in ODA's DateTime class.

The isAnyTime() method of DateTime allows us to tell if it's just a date or a date-time. That allows us in DateTime.toGMTDateTime() to use the GMT string according from the server's DateTime class to pass through a formatter in the same format to return a java.time.temporal.Temporal that's an instance of either a java.time.LocalDate for date only or a java.time.ZonedDateTime for a date-time.

The DateTime.toGMTISO() method allows us to use another DateTimeFormatter to get the ISO_INSTANT format for a date-time or ISO_DATE format for a date. So we get the correct ISO format for the relevant server's settings with minimal manipulation.

And believe me, from when Java 8 came out and I started looking at auto-boxing the Java 8 date-time classes to Domino DateTime objects, Notes timezones are such an arcane quirkiness that the minimal manipulation still has this kind of degree of complexity. And as I found out at the time, it's currently not possible to create a DateTime in a timezone other than the server's.

1 thought on “Converting Dates to ISO Formats”

  1. Should be noted that Javascript (which marshaled our decision for DQL) uses RFC3339 time stamps. Same order and timedate parts as ISO 8601, just different punctuation.

    -John Curtis

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top