(filed on behalf of a colleague)
DateTimeFormatterBuilder.appendZoneId() (and all the similar, related methods) suggests that parsing "+01:00", "UT+01:00", "UTC+01:00" or "GMT+01:00" will result in some ZoneOffset being returned.
However, of those only "+01:00" actually returns a ZoneOffset, all the others return a ZoneId (with the normalized input text in it, basically). Which matches the fact that only ZoneOffset.of("+01:00") actually returns a ZoneOffset, all other calls (with "UT", "UTC" or "GMT" prefix) actually throw a DateTimeException.
Parsing "GMT+01:00" (or any other variant with a prefix) will return a ZoneId with the respective value in it.
The ZoneOffset.of("UTC+01:30") mentioned in the JavaDoc of appendZoneOrOffsetId (only) does not actually return a ZoneOffset, but throws an exception instead.
In its place other methods JavaDoc mention ZoneOffset.of("+01:30"), which does work. They do not, however actually return a ZoneOffset in every case where they claim they do (specifically they only return it for input that looks like "+01:30", i.e. has no prefix).
Here is a repro:
public class DateTimeFormatter {
static void printZoneId(String input) {
java.time.ZoneId zoneId =
new java.time.format.DateTimeFormatterBuilder()
.appendZoneOrOffsetId()
.toFormatter(java.util.Locale.ROOT)
.parse(input)
.query(java.time.temporal.TemporalQueries.zoneId());
System.out.printf("\"%s\" => zoneId=%s class=%s\n",
input, zoneId, zoneId.getClass().getSimpleName());
}
public static void main(String[] args) throws Throwable {
printZoneId("+01:30");
printZoneId("UT+01:30");
printZoneId("UTC+01:30");
printZoneId("GMT+01:30");
}
}
"+01:30" => zoneId=+01:30 class=ZoneOffset
"UT+01:30" => zoneId=UT+01:30 class=ZoneRegion
"UTC+01:30" => zoneId=UTC+01:30 class=ZoneRegion
"GMT+01:30" => zoneId=GMT+01:30 class=ZoneRegion
DateTimeFormatterBuilder.appendZoneId() (and all the similar, related methods) suggests that parsing "+01:00", "UT+01:00", "UTC+01:00" or "GMT+01:00" will result in some ZoneOffset being returned.
However, of those only "+01:00" actually returns a ZoneOffset, all the others return a ZoneId (with the normalized input text in it, basically). Which matches the fact that only ZoneOffset.of("+01:00") actually returns a ZoneOffset, all other calls (with "UT", "UTC" or "GMT" prefix) actually throw a DateTimeException.
Parsing "GMT+01:00" (or any other variant with a prefix) will return a ZoneId with the respective value in it.
The ZoneOffset.of("UTC+01:30") mentioned in the JavaDoc of appendZoneOrOffsetId (only) does not actually return a ZoneOffset, but throws an exception instead.
In its place other methods JavaDoc mention ZoneOffset.of("+01:30"), which does work. They do not, however actually return a ZoneOffset in every case where they claim they do (specifically they only return it for input that looks like "+01:30", i.e. has no prefix).
Here is a repro:
public class DateTimeFormatter {
static void printZoneId(String input) {
java.time.ZoneId zoneId =
new java.time.format.DateTimeFormatterBuilder()
.appendZoneOrOffsetId()
.toFormatter(java.util.Locale.ROOT)
.parse(input)
.query(java.time.temporal.TemporalQueries.zoneId());
System.out.printf("\"%s\" => zoneId=%s class=%s\n",
input, zoneId, zoneId.getClass().getSimpleName());
}
public static void main(String[] args) throws Throwable {
printZoneId("+01:30");
printZoneId("UT+01:30");
printZoneId("UTC+01:30");
printZoneId("GMT+01:30");
}
}
"+01:30" => zoneId=+01:30 class=ZoneOffset
"UT+01:30" => zoneId=UT+01:30 class=ZoneRegion
"UTC+01:30" => zoneId=UTC+01:30 class=ZoneRegion
"GMT+01:30" => zoneId=GMT+01:30 class=ZoneRegion
- csr for
-
JDK-8346682 DateTimeFormatterBuilder.appendZoneId() has misleading JavaDoc
- Closed
- links to
-
Commit(master) openjdk/jdk/9702accd
-
Review(master) openjdk/jdk/22837