タイムゾーンを含むタイムスタンプ文字列表現の標準化

Date and Time on the Internet: Timestamps with additional information」という提案仕様がIETFで提出されているので簡単に紹介する。

この仕様では、下記のようなタイムスタンプの文字列フォーマットの定義を行う

1996-12-19T16:39:57-08:00[America/Los_Angeles][u-ca=hebrew]

背景 TC39 Temporal

Temporalという時間を扱う新しいAPIが、TC39でStage 3となっている。
tc39.es

このAPIでは、タイムゾーンを含む文字列を生成できる。

const zonedDateTime = Temporal.ZonedDateTime.from({
  timeZone: 'America/Los_Angeles',
  year: 1995,
  month: 12,
  day: 7,
  hour: 3,
  minute: 24,
  second: 30,
  millisecond: 0,
  microsecond: 3,
  nanosecond: 500
}); // => 1995-12-07T03:24:30.0000035-08:00[America/Los_Angeles]

この文字列表現はTemporalの仕様では次のように示している。

f:id:ASnoKaze:20210620000835p:plain

このように、時刻のフォーマットしては RFC3339 を利用しているが、タイムゾーンはTime Zone Extensionとして定義している。

この新しいTime Zone ExtensionをちゃんとRFCとして定義しようというのが「Date and Time on the Internet: Timestamps with additional information」である。IETFへの提案は、Temporalの標準化を行っているUjjwal Sharma氏によって行われている。 (IETF110の発表スライドpdf)。

提案仕様

Date and Time on the Internet: Timestamps with additional information」の提案仕様では、RFC3339 の定義に加えtime-zone, suffix-tag を付加できるようになっている。

フォーマット定義
time-zone-char = ALPHA / "." / "_"
time-zone-part = time-zone-char *13(time-zone-char / DIGIT / "-" / "+") ; but not "." or ".."
time-zone-name = time-zone-part *("/" time-zone-part)
time-zone      = "[" time-zone-name "]"

namespace      = 1*alphanum
namespace-key  = 1*alphanum
suffix-key     = namespace ["-" namespace-key]

suffix-value   = 1*alphanum
suffix-values  = suffix-value *("-" suffix-value)
suffix-tag     = "[" suffix-key "=" suffix-values "]"
suffix         = [time-zone] *suffix-tag

date-time-ext  = date-time suffix

実際に使う例

1996-12-19T16:39:57-08:00[America/Los_Angeles][u-ca=hebrew]

任意のサフィックスタグもつけられる

1996-12-19T16:39:57-08:00[x-foo=bar][x-baz=bat]