method earlier

Documentation for method earlier assembled from the following types:

class Date

From Date

(Date) method earlier

Defined as:

method earlier(Date:D: *%unit)

Returns a Date object based on the current one, but with a date delta towards the past applied. See method later for usage.

my $d = Date.new('2015-02-27');
say $d.earlier(month => 5).earlier(:2days);  # OUTPUT: «2014-09-25␤»

class DateTime

From DateTime

(DateTime) method earlier

Defined as:

method earlier(DateTime:D: *%unit)

Returns a DateTime object based on the current one, but with a time delta towards the past applied. Unless the given unit is second or seconds, the given value will be converted to an Int. See method later for usage.

my $d = DateTime.new(date => Date.new('2015-02-27'));
say $d.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.