LoginSignup
0
3

More than 5 years have passed since last update.

Linux の timezone

Posted at

Linux の timezone についてちょっと調べた。

Ubuntu では、現在の timezone は /etc/localtime にある。このファイル自体はシンボリックリンクで、実体は /usr/share/zoneinfo 以下にある。ここに timezone には関係する色々な情報が入っているらしいが、バイナリファイルなので直接は読めない。中を調べる方法は二つある。

zdump でファイルを読む

zdump は現在の時刻を指定された timezone で表示するツールだが、-v オプションを付けると timezone data の解釈を表示してくれる。

$ zdump -v /usr/share/zoneinfo/Japan | tail
/usr/share/zoneinfo/Japan  Sat May  6 16:59:59 1950 UT = Sun May  7 01:59:59 1950 JST isdst=0 gmtoff=32400
/usr/share/zoneinfo/Japan  Sat May  6 17:00:00 1950 UT = Sun May  7 03:00:00 1950 JDT isdst=1 gmtoff=36000
/usr/share/zoneinfo/Japan  Fri Sep  8 15:59:59 1950 UT = Sat Sep  9 01:59:59 1950 JDT isdst=1 gmtoff=36000
/usr/share/zoneinfo/Japan  Fri Sep  8 16:00:00 1950 UT = Sat Sep  9 01:00:00 1950 JST isdst=0 gmtoff=32400
/usr/share/zoneinfo/Japan  Sat May  5 16:59:59 1951 UT = Sun May  6 01:59:59 1951 JST isdst=0 gmtoff=32400
/usr/share/zoneinfo/Japan  Sat May  5 17:00:00 1951 UT = Sun May  6 03:00:00 1951 JDT isdst=1 gmtoff=36000
/usr/share/zoneinfo/Japan  Fri Sep  7 15:59:59 1951 UT = Sat Sep  8 01:59:59 1951 JDT isdst=1 gmtoff=36000
/usr/share/zoneinfo/Japan  Fri Sep  7 16:00:00 1951 UT = Sat Sep  8 01:00:00 1951 JST isdst=0 gmtoff=32400
/usr/share/zoneinfo/Japan  9223372036854689407 = NULL
/usr/share/zoneinfo/Japan  9223372036854775807 = NULL

それぞれの意味はマニュアルを読んでも良くわからなかったが、複数のゾーンが定義されている雰囲気は分かる。

ソースコードを読む

apt-get source tzdata でソースコードを取得できるが、大本は Time Zone Database らしい。日本のタイムゾーンのソースは https://github.com/eggert/tz/blob/master/asia#L1512 にある。これが歴史的資料感を醸し出していて非常に面白い。

timezone の変更方法

ここでも systemd の支配が及んでいて、timezone の変更も systemd で行う。コマンド名は timedatectl

timezone を自動検出する方法としては tzupate というのを見つけた。ip-api.com などの API を利用している。

現在位置を求める方法として GeoClue も使えそうだが TimeZone を返す API は見つからなかった。

参考

この調査の動機は現在使ってる AGL に timezone を設定したかったからだが、意外と面倒だったのでやめた。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3