DateTime.pm and midnight

A

Arvin Portlock

Why does the following code return 0 minutes instead of 60?

use DateTime;
use DateTime::Duration;

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::Duration (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

J. Gleixner

Arvin said:
Why does the following code return 0 minutes instead of 60?

use DateTime;
use DateTime::Duration;

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::Duration (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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top