Skip to content

Commit b6f8478

Browse files
committed
Document Date.later/earlier functionality
1 parent c898c17 commit b6f8478

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

doc/Type/Date.pod

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ an object the current day according to the system clock.
2323
say $d.month; # 12
2424
say $d.day; # 24
2525
say $d.day-of-week; # 1 (that's Monday)
26+
say $d.later(days => 20); # 2016-01-13
2627
my $n = Date.new('2015-12-31'); # New Year's Eve
2728
say $n - $d; # 7 days between New Years/Christmas Eve
2829
say $n + 1; # 2016-01-01
@@ -65,6 +66,53 @@ Usage:
6566
6667
Returns a C<Date> object for the current day.
6768
69+
=head2 method later
70+
71+
Defined as:
72+
73+
method later(Date:D: *%unit)
74+
75+
Usage:
76+
77+
DATE.later(DELTA)
78+
79+
Returns a Date object based on the current one, but with a date delta
80+
applied. The date delta can be passed as a named argument where the argument
81+
name is the unit.
82+
83+
Allowed units are C<day>, C<days>, C<week>, C<weeks>, C<month>, C<months>,
84+
C<year>, C<years>.
85+
86+
Please note that the special ":2nd" named parameter syntax can be a compact
87+
and self-documenting way of specifying the delta
88+
89+
say Date.new('2015-12-24').later(:2years);
90+
# 2017-12-24
91+
92+
Since addition of several different time units is not commutative, only one
93+
unit may be passed.
94+
95+
my $d = Date.new('2015-02-27');
96+
say $d.later(month => 1).later(:2days); # 2015-03-29
97+
say $d.later(days => 2).later(:1month); # 2015-04-01
98+
say $d.later(days => 2).later(:month); # same, as +True === 1
99+
100+
Negative offsets are allowed, though L<#method earlier> is more idiomatic for
101+
that.
102+
103+
=head2 method earlier
104+
105+
Defined as:
106+
107+
method earlier(Date:D: *%unit)
108+
109+
Usage:
110+
111+
DATE.earlier(DELTA)
112+
113+
Returns a Date object based on the current one, but with a date delta
114+
towards the past applied. See L<#method later> for usage.
115+
68116
=head2 method truncated-to
69117
70118
Defined as:

0 commit comments

Comments
 (0)