Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...