method later

Documentation for method later assembled from the following types:

class Date

From Date

(Date) method later

Defined as:

method later(Date:D: *%unit)

Returns a Date object based on the current one, but with a date delta applied. The date delta can be passed as a named argument where the argument name is the unit.

Allowed units are day, days, week, weeks, month, months, year, years. Please note that the plural forms can only be used with the later method.

Please note that the special ":2nd" named parameter syntax can be a compact and self-documenting way of specifying the delta

say Date.new('2015-12-24').later(:2years);  # OUTPUT: «2017-12-24␤»

Since addition of several different time units is not commutative, only one unit may be passed.

my $d = Date.new('2015-02-27');
say $d.later(month => 1).later(:2days);  # OUTPUT: «2015-03-29␤» 
say $d.later(days => 2).later(:1month);  # OUTPUT: «2015-04-01␤» 
say $d.later(days => 2).later(:month);   # same, as +True === 1

Negative offsets are allowed, though method earlier is more idiomatic for that.

class DateTime

From DateTime

(DateTime) method later

Defined as:

method later(DateTime:D: *%unit)

Returns a DateTime object based on the current one, but with a time delta applied. The time delta can be passed as a named argument where the argument name is the unit.

Unless the given unit is second or seconds, the given value will be converted to an Int.

Allowed units are second, seconds, minute, minutes, hour, hours, day, days, week, weeks, month, months, year, years. Please note that the plural forms can only be used with the later and earlier methods.

The :2nd form of colonpairs can be used as a compact and self-documenting way of specifying the delta:

say DateTime.new('2015-12-24T12:23:00Z').later(:2years);
# OUTPUT: «2017-12-24T12:23:00Z␤»

Since addition of several different time units is not commutative, only one unit may be passed.

my $d = DateTime.new(date => Date.new('2015-02-27'));
say $d.later(month => 1).later(:2days);  # OUTPUT: «2015-03-29T00:00:00Z␤» 
say $d.later(days => 2).later(:1month);  # OUTPUT: «2015-04-01T00:00:00Z␤» 
say $d.later(days => 2).later(:month);   # same, as +True === 1

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').later: :1day;
# OUTPUT: «2009-01-01T23:59:59Z␤»

Negative offsets are allowed, though earlier is more idiomatic for that.