Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

timezone - A day without midnight

There's at least one time zone that skips from 23:59:59 to 1:00:00 when "springing forward" for DST. Does anyone know what it is?

The following normally gets today's date, but it fails one day a year for time zones matching the above criterion.

$ perl -MDateTime -E'say DateTime->today( time_zone => $ARGV[0] )->ymd;' 
   America/New_York
2013-08-28

I need the time zone for testing purposes. I'm not trying to get the above code to work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are several. As of 2020-04, there are 14 such time zones in 10 countries: Paraguay, Cuba, Chile, Greenland/Denmark, Jordan, Lebanon, Syria, Palestine, Iran, and Azores/Portugal.

Before 2019-04, the list included Brazil using the America/Sao_Paulo time zone.

$ perl -MDateTime -E'say DateTime->new(
     year => 2013, month => 10, day => 20, hour => 12,
     time_zone => "America/Sao_Paulo")->truncate( to => "day" )->ymd;'
Invalid local time for date in time zone: America/Sao_Paulo

You can get around the problem by switching to the "floating" tome zone before getting the date:

$ perl -MDateTime -E'say DateTime->new(
     year => 2013, month => 10, day => 20, hour => 12,
     time_zone => "America/Sao_Paulo")
   ->set_time_zone("floating")
   ->truncate( to => "day" )
   ->ymd;'
2013-10-20

See this documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...