Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document Date.later/earlier functionality
  • Loading branch information
lizmat committed Dec 25, 2015
1 parent c898c17 commit b6f8478
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/Type/Date.pod
Expand Up @@ -23,6 +23,7 @@ an object the current day according to the system clock.
say $d.month; # 12
say $d.day; # 24
say $d.day-of-week; # 1 (that's Monday)
say $d.later(days => 20); # 2016-01-13
my $n = Date.new('2015-12-31'); # New Year's Eve
say $n - $d; # 7 days between New Years/Christmas Eve
say $n + 1; # 2016-01-01
Expand Down Expand Up @@ -65,6 +66,53 @@ Usage:
Returns a C<Date> object for the current day.
=head2 method later
Defined as:
method later(Date:D: *%unit)
Usage:
DATE.later(DELTA)
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 C<day>, C<days>, C<week>, C<weeks>, C<month>, C<months>,
C<year>, C<years>.
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);
# 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); # 2015-03-29
say $d.later(days => 2).later(:1month); # 2015-04-01
say $d.later(days => 2).later(:month); # same, as +True === 1
Negative offsets are allowed, though L<#method earlier> is more idiomatic for
that.
=head2 method earlier
Defined as:
method earlier(Date:D: *%unit)
Usage:
DATE.earlier(DELTA)
Returns a Date object based on the current one, but with a date delta
towards the past applied. See L<#method later> for usage.
=head2 method truncated-to
Defined as:
Expand Down

0 comments on commit b6f8478

Please sign in to comment.