Velocity Reviews > Perl > DateTime.pm and midnight

# DateTime.pm and midnight

Arvin Portlock
Guest
Posts: n/a

 12-29-2005
Why does the following code return 0 minutes instead of 60?

use DateTime;
use DateTime:uration;

my \$year = 1969;
my \$month = 4;
my \$day = 2;
my \$hour = 23;

my \$datetime = new DateTime (year => \$year,
month => \$month,
day => \$day,
hour => \$hour);

my \$onehour = new DateTime:uration (hours => '1');

my \$elevenpm = new DateTime (year => \$year,
month => \$month,
day => \$day,
hour => '23');

my \$midnight = \$elevenpm + \$onehour;

my \$delta = \$midnight - \$datetime;
print \$delta->minutes, "\n";

J. Gleixner
Guest
Posts: n/a

 12-30-2005
Arvin Portlock wrote:
> Why does the following code return 0 minutes instead of 60?
>
> use DateTime;
> use DateTime:uration;
>
> my \$year = 1969;
> my \$month = 4;
> my \$day = 2;
> my \$hour = 23;
>
> my \$datetime = new DateTime (year => \$year,
> month => \$month,
> day => \$day,
> hour => \$hour);
>
> my \$onehour = new DateTime:uration (hours => '1');
>
> my \$elevenpm = new DateTime (year => \$year,
> month => \$month,
> day => \$day,
> hour => '23');
>
> my \$midnight = \$elevenpm + \$onehour;
>
> my \$delta = \$midnight - \$datetime;
> print \$delta->minutes, "\n";

Because it's 1 hour and 0 minutes difference. Minutes are 0-59.