为什么 Swift 的日期时间间隔会忽略闰秒?

Why do Swift's Date time intervals ignore leap seconds?

30 June 2012 had a leap second。因此它持续了 86401 秒。 但是,在下面的 Swift 代码中, timeInterval 是 86400。 怎么会?

let formatter = ISO8601DateFormatter()
let date = formatter.date(from: "2012-06-30T00:00:00Z")!
let dayAfter = formatter.date(from: "2012-07-01T00:00:00Z")!
let timeInterval = date.distance(to: dayAfter)

(ps: 我是在什么情况下写这段代码的?这只是为了玩代码。我试图写出令人困惑的代码结果,但我对这种试图成为的尝试感到失望聪明)

Apple 日期和时间 API 和系统实现的基础是 ICU library, and the underpinnings for most of the results you see depends on ICU behavior. Notably, ICU doesn't support or consider the existence of leap seconds:

For historical reasons, the reference point is Greenwich, England. Local time in Greenwich is referred to as Greenwich Mean Time, or GMT. (This is similar, but not precisely identical, to Universal Coordinated Time, or UTC. We use the two terms interchangeably in ICU since ICU does not concern itself with either leap seconds or historical behavior.)

因此,Apple 平台也不以任何方式在 API 中表示历史(或未来)的闰秒;系统 有效地 通过 NTP 处理闰秒,并简单地适当地设置它们的时钟,但像这样查询闰秒不会产生任何结果。