Help language development. Donate to The Perl Foundation
Interval - a DateTime that has intervals
use Interval; # just export the Interval class 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 use Interval :refine; # lexical refinement of the DateTime class my $c = DateTime.new(time); # from now, interval of 1 minute say $c; # 2020-04-03T11:42:09Z $c += 10; say $c; # 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.
You can also use the
Interval class with the
:refine parameter. This will "augment" the
DateTime class in the lexical scope in which the
use statement is located. This allows one to not to have to change existing code using the
DateTime class, while still having the added functionality of the
Please note that the use of lexical refinement is an experiment for now, until it has proven its worth.
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.