tokuhirom's Blog

Time::Piece とstrptimeの甘い罠

my $time = Time::Piece->strptime('2011-11-30T18:19', '%Y-%m-%dT%H:%M:%SZ')->epoch;

みたいなコードをかいたら、なんか FATAL Error になるよ! みたいなことをいわれたので、なんでやねん! みたいなことをおもったりしたわけですが、

https://metacpan.org/source/MSERGEANT/Time-Piece-1.20/Changes
これによると

1.17
    - Force all to use internal strptime then everyone gets %z even OSX
      users.
    - Finally figured out the timezone test failures on Win32 and fixed
      them.

とかいてあって、要は strptime(3) がある環境では strptime(3) をつかってたんだけど、環境によって挙動がやっぱちがったりしてアレゲだから全部自前のをつかうようにしたよ! ってなわけだ。

そんなわけなので、Time::Piece は最新版をつかうよろし!

【あわせて読みたい】
http://d.hatena.ne.jp/hirose31/20110210/1297341952