I once wrote a module to do this (long before DateTime).
Note that in the second case the result is exact.
Date::Tie is _very_ careful to round errors correctly.

  use Date::Tie;

  tie my %date, 'Date::Tie', frac_hour => 2.67;

  print $date{frac_hour}, "\n";
  print $date{hour}, ":", 
        $date{minute}, ":", 
        $date{frac_second}, "\n";

  # 02.67
  # 02:40:12.0

  $date{frac_hour} = 2 + 2/3;

  print $date{frac_hour}, "\n";
  print $date{hour}, ":", 
        $date{minute}, ":",   
        $date{frac_second}, "\n";

  # 02.66666666666667
  # 02:40:00.0

- Flavio S. Glock


Reply via email to