hnwの日記

日付と時刻の豆知識 (4)tz databaseと日本のサマータイム

tz database(zoneinfo database、Olson Databaseとも)とは、世界のタイムゾーン名と、時差およびサマータイムの運用情報をまとめたファイル、もしくはそれをまとめるプロジェクト名のことです。プログラミング言語およびOSでの利用を想定して作られたもので、BSD由来のシステム(FreeBSDNetBSDOpenBSDMacOSXなど)、glibc利用のシステム(Linuxなど)、その他の各種商用UNIXで利用されています。Linuxディストリビューションであればtzdataというパッケージ名でインストールされていますので、見覚えがある人も多いでしょう。


プログラミング言語での利用例を見ると、PHPでは標準のタイムゾーンの枠組みとして組み込まれていますし、JREにも含まれているようです。また、Perlの DateTime::TimeZone モジュールや DateTime::LeapSecond モジュール、Pythonの pytz モジュールでもtz databaseが利用されているようです。

tz databaseの特徴

tz databaseではタイムゾーンごとに、どの標準時に属するか、サマータイムはいつからいつまでかといった情報がまとまっています。これは現在の情報だけでなく、過去の運用状況も含め記録されています。たとえば、日本では戦後すぐの1948年から1951年までサマータイムが実施されていたのですが、この情報も格納されています。


tz database では、「大陸名/地域名」または「大陸名/地域名/細分地域名」という名前でタイムゾーンを表現します。これは独特の形式ですが、理にかなったものです。というのも、国や地域によっては過去に標準時やサマータイムの運用の変更が行われているため、「JST」のような標準時の情報だけではタイムゾーンを表現しきれないのです。


実際、アメリカの代表的な標準時はEST(東部)、CST(中部)、MST(山岳部)、PST(太平洋)、AKST(アラスカ)、HAST(ハワイ・アリューシャン)の計6つですが、これに対応するtz databaseのタイムゾーンは次のリストの通り26個あります。過去から現在まで一つのタイムゾーンで困らない我々にとっては想像しにくい話ですね。

  • America/New_York
  • America/Chicago
  • America/North_Dakota/Center
  • America/North_Dakota/New_Salem
  • America/Denver
  • America/Los_Angeles
  • America/Juneau
  • America/Yakutat
  • America/Anchorage
  • America/Nome
  • America/Adak
  • Pacific/Honolulu
  • America/Phoenix
  • America/Boise
  • America/Indiana/Indianapolis
  • America/Indiana/Marengo
  • America/Indiana/Vincennes
  • America/Indiana/Tell_City
  • America/Indiana/Petersburg
  • America/Indiana/Knox
  • America/Indiana/Winamac
  • America/Indiana/Vevay
  • America/Kentucky/Louisville
  • America/Kentucky/Monticello
  • America/Detroit
  • America/Menominee

日本のタイムゾーン情報を確認してみる

では、tz database中の日本のタイムゾーン情報を確認してみましょう。ftp://elsie.nci.nih.gov/pub/からtzdata2010o.tar.gzといったファイルを取得し、展開してファイルasiaを眺めていくと下記の定義がみつかります。コメント部にあるのはメーリングリストへの投稿内容だと思われます。

###############################################################################

# Japan

# `9:00' and `JST' is from Guy Harris.

# From Paul Eggert (1995-03-06):
# Today's _Asahi Evening News_ (page 4) reports that Japan had
# daylight saving between 1948 and 1951, but ``the system was discontinued
# because the public believed it would lead to longer working hours.''

# From Mayumi Negishi in the 2005-08-10 Japan Times
# <http://www.japantimes.co.jp/cgi-bin/getarticle.pl5?nn20050810f2.htm>:
# Occupation authorities imposed daylight-saving time on Japan on
# [1948-05-01]....  But lack of prior debate and the execution of
# daylight-saving time just three days after the bill was passed generated
# deep hatred of the concept....  The Diet unceremoniously passed a bill to
# dump the unpopular system in October 1951, less than a month after the San
# Francisco Peace Treaty was signed.  (A government poll in 1951 showed 53%
# of the Japanese wanted to scrap daylight-saving time, as opposed to 30% who
# wanted to keep it.)

# From Paul Eggert (2006-03-22):
# Shanks & Pottenger write that DST in Japan during those years was as follows:
# Rule  NAME    FROM    TO      TYPE    IN      ON      AT      SAVE    LETTER/S
Rule    Japan   1948    only    -       May     Sun>=1  2:00    1:00    D
Rule    Japan   1948    1951    -       Sep     Sat>=8  2:00    0       S
Rule    Japan   1949    only    -       Apr     Sun>=1  2:00    1:00    D
Rule    Japan   1950    1951    -       May     Sun>=1  2:00    1:00    D
# but the only locations using it (for birth certificates, presumably, since
# their audience is astrologers) were US military bases.  For now, assume
# that for most purposes daylight-saving time was observed; otherwise, what
# would have been the point of the 1951 poll?

# From Hideyuki Suzuki (1998-11-09):
# 'Tokyo' usually stands for the former location of Tokyo Astronomical
# Observatory: E 139 44' 40".90 (9h 18m 58s.727), N 35 39' 16".0.
# This data is from 'Rika Nenpyou (Chronological Scientific Tables) 1996'
# edited by National Astronomical Observatory of Japan....
# JST (Japan Standard Time) has been used since 1888-01-01 00:00 (JST).
# The law is enacted on 1886-07-07.

# From Hideyuki Suzuki (1998-11-16):
# The ordinance No. 51 (1886) established "standard time" in Japan,
# which stands for the time on E 135 degree.
# In the ordinance No. 167 (1895), "standard time" was renamed to "central
# standard time".  And the same ordinance also established "western standard
# time", which stands for the time on E 120 degree....  But "western standard
# time" was abolished in the ordinance No. 529 (1937).  In the ordinance No.
# 167, there is no mention regarding for what place western standard time is
# standard....
#
# I wrote "ordinance" above, but I don't know how to translate.
# In Japanese it's "chokurei", which means ordinance from emperor.

# Shanks & Pottenger claim JST in use since 1896, and that a few
# places (e.g. Ishigaki) use +0800; go with Suzuki.  Guess that all
# ordinances took effect on Jan 1.

# Zone  NAME            GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Asia/Tokyo      9:18:59 -       LMT     1887 Dec 31 15:00u
                        9:00    -       JST     1896
                        9:00    -       CJT     1938
                        9:00    Japan   J%sT
# Since 1938, all Japanese possessions have been like Asia/Tokyo.


Paul EggertさんがAsahi Evening NewsやJapan Timesといった情報源から日本のタイムゾーン情報を収集しているようです。Hideyuki Suzukiさんも理科年表や勅令を引用したりして標準時に関する情報提供をされているようですね。

日本のサマータイム

引用した定義には、先ほど紹介した日本のサマータイムの情報も含まれています。定義を読み解くと、1948、1950、1951年は5月の第1日曜日から、1949年のみ4月の第1日曜日からサマータイム開始、いずれも9月の第2土曜日に終了、ということのようです。これは当時の法律「夏時刻法」と合致します。


実際、PHPでも日本の夏時間を確認することができます。ちなみに1948年は5月2日が第1日曜日です。

<?php
date_default_timezone_set('Asia/Tokyo');
$st_time = strtotime("1948-05-01 09:00:00 JST");
echo date("c", $st_time), PHP_EOL;
$dst_time = strtotime("1948-05-01 09:00:00 JST +24hour");
echo date("c", $dst_time), PHP_EOL;


これを実行すると次のように後者はGMTとの時差が+10:00となっており、夏時間であることがわかります。また、時計も確かに1時間進んでいます。

$ php /tmp/dst-of-japan.php
1948-05-01T09:00:00+09:00
1948-05-02T10:00:00+10:00
$


ところで、引用した定義ファイルでは日本のサマータイムの開始時刻が午前2時になっているのですが、これは誤りのようです。夏時間法によれば0時に夏時間開始(=夏時間午前1時にする)となっています。


これ、最初はPHPのバグだと思っていたんですが、どう見てもtz databaseのバグですね。そのうちバグレポしたいと考えています。