I dealt with DateTime recently, and I have great respect for it. The author understands the complexities of data and time arithmetic and does a good job of preventing you from shooting yourself in the foot.
use strict; use warnings; use DateTime qw( ); my $today = DateTime->today( time_zone => 'local' ); my $xmas = $today->clone()->set_month( 12 )->set_day( 25 ); if ( $xmas < $today ) { $xmas->add( year => 1 ); } my $days = $xmas->delta_days( $today )->in_units( 'days' ); if ($days == 0) { print( "Merry Christmas!\n" ); } elsif ($days == 1) { print( "Christmas is tomorrow!\n" ); } else { print( "Christmas is in $days days.\n" ); }
prints
Christmas is in 78 days.
Update: Removed unnecessary $today->set_time_zone( 'floating' );.
In reply to Re: Time / Date Arithmetic Module Recommendations
by ikegami
in thread Time / Date Arithmetic Module Recommendations
by tomazos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |