The code works fine for me on OSX, using the same module versions, installed from cpan. Anyway, please check if this fixes the problem: this sets the timezone on the whole set, instead of the start/end dates.
my $dt1 = DateTime->new(year => 2007, month => 11)->truncate(to => 'month'); my $dt2 = DateTime->new(year => 2007, month => 11, day => 5)->truncate(to => 'day'); my $dtset = DateTime::Set->from_recurrence( start => $dt1, end => $dt2, recurrence => sub { return $_[0]->truncate( to => 'day' )->add( days => 1 ); }, )->set_time_zone('EST5EDT'); - Flavio S. Glock 2007/11/5, Phil Sorber <[EMAIL PROTECTED]>: > I searched around a little bit and it seems that most bug reports for > DateTime::Set have to do with the from_recurrence method or misunderstandings > thereof. So it is entirely possible that the problem I am about to describe is > not a bug but a intricacy of handling Daylight savings in recurrence sets. > > First off I am using the perl-DateTime-0.2901-1.2.el4.rf and > perl-DateTime-Set-0.25-2.2.el4.rf RPM's from RPMForge. I am running perl 5.8.8 > (perl-5.8.8-4.el4s1) on CentOS 4.5 (Linux hostname.domain.com > 2.6.9-55.0.12.ELsmp #1 SMP Fri Nov 2 11:19:08 EDT 2007 i686 i686 i386 > GNU/Linux). > > > The Code: > -- > > #!/usr/bin/perl > > use strict; > use warnings; > > use DateTime; > use DateTime::Set; > use DateTime::Format::MySQL; > > # The reason for the truncate's is because usually I am not > # specifying year and month I am simply doing now(). > > my $dt1 = DateTime->new(year => 2007, month => > 11)->set_time_zone('EST5EDT')->truncate(to => 'month'); > > my $dt2 = DateTime->new(year => 2007, month => 11, day => > 5)->set_time_zone('EST5EDT')->truncate(to => 'day'); > > # This was adapted from an example on the DateTime::Set doc page > > my $dtset = DateTime::Set->from_recurrence( > start => $dt1, > end => $dt2, > recurrence => sub { > return $_[0]->truncate( to => 'day' )->add( days => 1 ); > }, > ); > > my $itr1 = $dtset->iterator; > > while (my $dt3 = $itr1->next()) > { > print DateTime::Format::MySQL->format_date($dt3) . "\n"; > } > > -- > > Output: > > 2007-11-01 > 2007-11-02 > 2007-11-03 > 2007-11-04 > 2007-11-04 > 2007-11-04 > 2007-11-04 > .... etc > > When I run the previous code it iterates as you would expect to '2007-11-04' > then repeatedly prints out '2007-11-04'. I think this has to do with daylight > savings time. Nov 4th effectively has 25 hours in it so adding 24 hours (1 > day) > will leave you still in Nov 4th. I fixed this by adding "hours => 26" instead > of > "days => 1" and then doing a truncate( to => 'day' ). I don't really like > that, > but If this is the intended behavior I will live with it. > > Thanks. >