Help language development. Donate to The Perl Foundation
Interval - a DateTime that has intervals
use Interval; my $a = Interval.new(2020,1,1,0,0,0); # from 2020, interval of 1 hour say $a; # 2020-01-01T00:00:00Z $a++; # 2020-01-01T01:00:00Z # one hour later say $a.seconds; # 3600 my $b = Interval.new(time); # from now, interval of 1 minute say $b; # 2020-04-03T11:42:09Z $b += 10; say $b; # 2020-04-03T11:52:09Z # ten minutes later
Interval class is a parameterizable subclass of
DateTime that incorporates interval information (in seconds), and the
.pred methods, which allow it to be used as endpoints in
..) or series (aka
...). Or allow it to be incremented or decremented to get to after the interval. Or add / subtract a given number of intervals.
The parameterization value is in seconds and defaults to
3600, aka 1 hour.
Produces the "next"
Produces the "previous"
Returns the number of seconds of the interval.
my $b = Interval.new(time); # from now, interval of 1 minute say $b; # 2020-04-03T11:42:09Z $b += 10; say $b; # 2020-04-03T11:52:09Z # ten minutes later
Allows adding a number of steps of the interval;
Allows subtracting a number of steps of the interval;
Elizabeth Mattijsen [email protected]
Source can be located at: https://github.com/lizmat/Interval . Comments and Pull Requests are welcome.
Copyright 2020,2021 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.