0

Want to be able to create custom timezones offset from a particular zone (but observing daylight savings transitions). For example would like to be able to indicate:

ZoneId.of("America/New_York+7")

The above zone would observe either EST or EDT, depending on daylight savings time + 7 hours. The application for this relates to FX markets start / end of day (which is 5pm New York time).

The above offset format is disallowed in ZoneId, as ZoneId only allows for offsets from UTC.

I had implemented a class which generates custom ZoneRules, but then the ZoneRegion constructor, a subclass of ZoneId is not public. ZoneRegion has the following, unavailable constructor:

ZoneRegion(String name, ZoneRules rules)

So the question is, short of not using the java.time library, is there any way to get the behavior of a custom zone with DST rules? Alternatively, does someone know how this would be done using the Joda date/time library?

Addendum

Note that one cannot create subclasses of ZoneId due to the following code in ZoneId (which frankly, seems like a very bad idea unless there is some security reason which I cannot fathom):

/**
 * Constructor only accessible within the package.
 */
ZoneId() {
    if (getClass() != ZoneOffset.class && getClass() != ZoneRegion.class) {
        throw new AssertionError("Invalid subclass");
    }
}
Jonathan Shore
  • 880
  • 2
  • 8
  • 21

0 Answers0