Hi,

I recently ran into TimeZone troubles when trying to create a simple
DateTime object representing a simple date:

Example1:
DateTime->new(year => 2011, month => 10, day => 16, time_zone =>
"America/Sao_Paulo") # Fails

Example2:
# simulate current timestamp
*DateTime::now = sub { shift->from_epoch( epoch => ( 1318766400 ), @_ ) };

DateTime->now( time_zone => 'America/Sao_Paulo' ); # Works
DateTime->today( time_zone => 'America/Sao_Paulo' ); # Fails

Example3:
DateTime->new(year => 2011, month => 10, day => 15, time_zone =>
"America/Sao_Paulo")->add( days => 1 ); # Fails

It is perfectly clear to me that DateTime takes 0 as a default for
hours, minutes and seconds, and that due to a switch in Brasil daylight
saving time 2011-10-15T23:59:59 is followed by 2011-10-16T01:00:00 thus
making 2011-10-16T00:00:00 an illegal timestamp.

However i do not know how to prevent my application from failing in
Brasil one day a year (or possibly longer) except by stop using the any
time zones?! I think that it is ok for DateTime to throw an exception
when I explicitly try to generate an invalid timestamp (e.g.
DateTime->new(year => 2011, month => 10, day => 16, hour => 0, minute =>
31, time_zone => "America/Sao_Paulo")) but it should not die when
performing simple DateTime manipulations or requesting the current date.

Any suggestions how to work around this issue?

Cheers
Maroš

Reply via email to