I was trying to compare two durations, and came up with some surprises.

  DB<1> use DateTime;

  DB<2> $hour = DateTime::Duration->new(hours=>1);

  DB<3> $minute = DateTime::Duration->new(minutes=>1);

  # Try comparing $hour and $minute
  DB<4> print ($hour < $minute)
1   # Whaaaa??

  # Try subtracting and check sign of result.
  DB<7> $d3 = $hour - $minute;

  DB<9> print $d3->is_positive
1   # Ok so far....

  DB<10> $d4 = $minute - $hour;

  DB<11> print $d4->is_positive
1   # Whaaaaa??

  # Try comparing as a time value
  DB<12> print (DateTime->now + $hour) > (DateTime->now + $minute)
1   # Ok, that worked.

I couldn't find anything about this in the documentation. I can understand
after some reflection why you shouldn't be able to compare durations (e.g.
how would you compare 30 days to 1 month), but it seems like this should be
documented, and using comparison operator should fail. Let me know if I'm
missed something obvious...

Jon

Reply via email to