DateTime.pm and midnight

Discussion in 'Perl Misc' started by Arvin Portlock, Dec 29, 2005.

  1. 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";
    Arvin Portlock, Dec 29, 2005
    #1
    1. Advertising

  2. Arvin Portlock

    J. Gleixner Guest

    Arvin Portlock wrote:
    > 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.
    J. Gleixner, Dec 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    704
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    532
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    386
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    333
    Martin
    Dec 27, 2008
  5. Ethan Furman

    datetime.time and midnight

    Ethan Furman, Feb 21, 2009, in forum: Python
    Replies:
    6
    Views:
    1,054
    Ethan Furman
    Feb 22, 2009
Loading...

Share This Page