在时区的日期时间不明确的情况下抛出异常?

Throw exception in case of ambiguous date-time for a timezone?

使用 java.time 包:

我正在将自由插入的日期时间(年、月、日、小时、分钟)的用户输入转换为 LocalDateTime and then, according to the timezone of the user, to a ZonedDateTime

爱沙尼亚的例子:

LocalDateTime local = LocalDateTime.of(2018, 10, 28, 3, 30); // October 28th 03:30
ZonedDateTime zoned = local.atZone(ZoneId.of("Europe/Tallinn"));

以上时间03:30可能意味着时间线上的两个实例,因为爱沙尼亚的夏令时于 2018 年 10 月 28 日结束。在 04:00 GMT+3,时钟更改为 03:00 GMT+2,这意味着当天两次达到 03:30 时间。根据the documentation of atZone(),转换的结果时间是夏令时03:30 GMT+3(强调我的):

In most cases, there is only one valid offset for a local date-time. In the case of an overlap, where clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer".

我想要的是不要隐式执行此转换。相反,我想捕获异常并通知用户输入不明确。似乎有一种方法可以做到这一点,但我不明白的是为什么该方法是静态的并接受三个参数。如何为我的案例正确使用它?来自同一文档:

To throw an exception when there is a gap or overlap, use ZonedDateTime.ofStrict(LocalDateTime, ZoneOffset, ZoneId).

为什么它要求 ZoneOffset 参数?在我看来,我只需要 LocalDateTimeZoneId。不然每次转换成ZonedDateTime,我怎么知道是用GMT+2还是GMT+3的偏移量呢?这是我希望 Java 告诉我或抛出异常(如果两者都适用)的内容。

我找到了 并将我自己的问题标记为重复。

ZoneId zoneId = ZoneId.of("America/Chicago");
LocalDateTime ldt = LocalDateTime.of(2017, 3, 12, 2, 39, 0, 0);
ZoneOffset zoneOffset = zoneId.getRules().getOffset(ldt);
ZonedDateTime zdt = ZonedDateTime.ofStrict(ldt, zoneOffset, zoneId);

would throw

Exception in thread "main" java.time.DateTimeException: LocalDateTime '2017-03-12T02:39' does not exist in zone 'America/Chicago' due to a gap in the local time-line, typically caused by daylight savings
    at java.time.ZonedDateTime.ofStrict(ZonedDateTime.java:484)