Skip to content
DateTime::Math -- provides common math operations on DateTime objects
Other
  1. Other 100.0%
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/DateTime
t
.gitignore
.travis.yml
META6.json
README.md

README.md

DateTime::Math

Description

Provides to-seconds(), from-seconds(), duration-from-to() and the ability to perform certain math operations on DateTime objects.

  use DateTime::Math;

  ## Given $dt1 and $dt2 are both DateTime objects.

  my $days = from-seconds($dt2 - $dt1, 'd');
  say "The events where $days days apart";

  my $target = $dt1 + to-seconds(1, 'M');
  say "One month after $dt1 would be $target";

  my $hours = duration-from-to(3, 'y', 'h');
  say "3 years contains $hours hours.";

The math functions allowed are:

  • Seconds = DateTime + DateTime
  • Seconds = DateTime - DateTime
  • DateTime = DateTime + Seconds
  • DateTime = DateTime - Seconds

And comparisons:

  • DateTime cmp DateTime
  • DateTime <=> DateTime
  • DateTime == DateTime
  • DateTime != DateTime
  • DateTime <= DateTime
  • DateTime < DateTime
  • DateTime >= DateTime
  • DateTime > DateTime

Note: Rakudo has since implemented internal DateTime comparisons, therefore DateTime::Math's comparisons have been removed.

Note that all of the math operations on DateTime objects are using the POSIX time, which is stored as seconds, so it does not support sub-second math at this time.

Author

Contributions by

License

Artistic License 2.0

You can’t perform that action at this time.