@@ -23,6 +23,7 @@ an object the current day according to the system clock.
23
23
say $d.month; # 12
24
24
say $d.day; # 24
25
25
say $d.day-of-week; # 1 (that's Monday)
26
+ say $d.later(days => 20); # 2016-01-13
26
27
my $n = Date.new('2015-12-31'); # New Year's Eve
27
28
say $n - $d; # 7 days between New Years/Christmas Eve
28
29
say $n + 1; # 2016-01-01
@@ -65,6 +66,53 @@ Usage:
65
66
66
67
Returns a C < Date > object for the current day.
67
68
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
+
68
116
= head2 method truncated-to
69
117
70
118
Defined as:
0 commit comments