Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • The annoying workaround is to do $duration->days * 24 + $duration->minutes or something similar. I'd rather it gave me that automatically and warned about any potential consequences, either that or worked it out correctly. Also it's called DateTime::Duration not interval iirc
    --

    @JAPH = qw(Hacker Perl Another Just);
    print reverse @JAPH;
  • Hello,

    You might want to consider something along these lines.

    use strict;
    use warnings;
    use DateTime;
    use DateTime::Format::Duration;
    use Data::Dumper;

    my $dt1 = DateTime->now(
              time_zone => 'UTC',
             );

    my $dt2 = DateTime->new(
            year  => 2006,
            month => 10,
            day => 31,
            time_zone =>'UTC',
        );

    my $delta = $dt1-
  • There's a module called DateTime::Format::Duration that should do what you want. Unfortunately, it needs some work to pass its tests with the latest DateTime.pm.
    • The last time I checked (this morning), it did not do what I wanted. It could tell me the minutes component of the interval, but it could not convert the days, hours, and minutes to a total number of minutes. Unless I'm missing something, and if so, please point it out, because you will really help me.

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • Have you seen my post on this?
        • Yes, I did, and thank you! I'd discovered delta_ms by that time. However, it still does not really DWIM. If I have real Date objects, I should be able to subtract them and get an interval that can be converted to whatever resolution or units I want. The problem then is that I have to do something unintuitive with my DateTimes: intuitively, I had written

          $end - $start

          and expected to get something that I could express as minutes. I shouldn't have to perform something other than subtraction in order to

          --
          J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • I think you'd be best served by writing a message to datetime@perl.org outlining what you want to do.