In role Dateish§
See primary documentation in context for method earlier
multi method earlier(Dateish: *)multi method earlier(Dateish: )
Returns an object based on the current one, but with a date delta towards the past applied. Unless the given unit is second
or seconds
, the given value will be converted to an Int
. See .later
for usage. It will generally be used through classes that implement this role, Date
or DateTime
my = Date.new('2015-02-27');say .earlier(month => 5).earlier(:2days); # OUTPUT: «2014-09-25»my = DateTime.new(date => Date.new('2015-02-27'));say .earlier(month => 1).earlier(:2days); # OUTPUT: «2015-01-25T00:00:00Z»
If the resultant time has value 60
for seconds, yet no leap second actually exists for that time, seconds will be set to 59
:
say DateTime.new('2008-12-31T23:59:60Z').earlier: :1day;# OUTPUT: «2008-12-30T23:59:59Z»
Negative offsets are allowed, though later is more idiomatic for that.
If you need to use more than one unit, you will need to build them into a List
of Pair
s to use the second form of the method:
say Date.new('2021-03-31').earlier( ( year => 3, month => 2, day => 8 ) ); # OUTPUT: «2018-01-23»
This feature was introduced in release 2021.02 of the Rakudo compiler.