@@ -71,45 +71,106 @@ Note that this can lead to invalid dates in some circumstances:
71
71
72
72
= head2 method hour
73
73
74
- method hour(DateTime:D) returns Int:D
74
+ method hour(DateTime:D: ) returns Int:D
75
75
76
76
Returns the hour component.
77
77
78
78
say DateTime.new('2012-02-29T12:34:56Z').hour; # 12
79
79
80
80
= head2 method minute
81
81
82
- method minute(DateTime:D) returns Int:D
82
+ method minute(DateTime:D: ) returns Int:D
83
83
84
84
Returns the minute component.
85
85
86
86
say DateTime.new('2012-02-29T12:34:56Z').minute; # 34
87
87
88
88
= head2 method second
89
89
90
- method second(DateTime:D)
90
+ method second(DateTime:D: )
91
91
92
92
Returns the second component, including potentially fractional seconds.
93
93
94
94
say DateTime.new('2012-02-29T12:34:56Z').second; # 56
95
95
96
+ = head2 method whole-second
97
+
98
+ method whole-second(DateTime:D:)
99
+
100
+ Returns the second component, rounded down to an L < Int|/type/Int > .
101
+
102
+ say DateTime.new('2012-02-29T12:34:56Z').whole-second; # 56
103
+
104
+ = head2 method timezone
105
+
106
+ method timezone(DateTime:D:) returns Int:D
107
+
108
+ Returns the time zone in seconds as an offset from UTC.
109
+
110
+ say DateTime.new('2015-12-24T12:23:00+0200').timezone; # 7200
111
+
112
+ = head2 method offset
113
+
114
+ method offset(DateTime:D:) returns Int:D
115
+
116
+ Returns the time zone in seconds as an offset from UTC. This is an alias for
117
+ L < #method timezone > .
118
+
119
+ say DateTime.new('2015-12-24T12:23:00+0200').offset; # 7200
120
+
121
+ = head2 method offset-in-minutes
122
+
123
+ method offset-in-minutes(DateTime:D:) returns Real:D
124
+
125
+ Returns the time zone in minutes as an offset from UTC.
126
+
127
+ say DateTime.new('2015-12-24T12:23:00+0200').offset-in-minutes;
128
+ # 120
129
+
130
+ = head2 method offset-in-hours
131
+
132
+ method offset-in-hours(DateTime:D:) returns Real:D
133
+
134
+ Returns the time zone in hours as an offset from UTC.
135
+
136
+ say DateTime.new('2015-12-24T12:23:00+0200').offset-in-hours;
137
+ # 2
138
+
139
+ = head2 method formatter
140
+
141
+ method formatter(DateTime:D:)
142
+
143
+ Returns the formatting function which is used for conversion to
144
+ L < Str|/type/Str > . If none was provided at object construction, a
145
+ default formatter is used which produces an ISO 8601 timestamp.
146
+
147
+ The formatting function is called by L < #method Str > with the invocant as its
148
+ ownly argument.
149
+
150
+ = head2 method Str
151
+
152
+ method Str(DateTime:D:) returns Str:D
153
+
154
+ Returns a string representation of the invocant, as done by
155
+ L < the formatter|#method formatter > .
156
+
96
157
= head2 method Instant
97
158
98
- method Instant() returns Instant:D
159
+ method Instant(DateTime:D: ) returns Instant:D
99
160
100
161
Returns an L < Instant|/type/Instant > object based on the invocant.
101
162
102
163
= head2 method posix
103
164
104
- method posix($ignore-timezone = False) returns Int:D
165
+ method posix(DateTime:D: $ignore-timezone = False) returns Int:D
105
166
106
167
Returns the date and time as a POSIX/UNIX timestamp.
107
168
108
169
say DateTime.new('2015-12-24T12:23:00Z').posix; # 1450959780
109
170
110
171
= head2 method later
111
172
112
- method later(*%unit)
173
+ method later(DateTime:D: *%unit)
113
174
114
175
Returns a DateTime object based on the current one, but with a time delta
115
176
applied. The time delta can be passed as a named argument where the argument
@@ -134,14 +195,14 @@ that.
134
195
135
196
= head2 method earlier
136
197
137
- method earlier(*%unit)
198
+ method earlier(DateTime:D: *%unit)
138
199
139
200
Returns a DateTime object based on the current one, but with a time delta
140
201
towards the past applied. See L < #method later > for usage.
141
202
142
203
= head2 method truncated-to
143
204
144
- method truncated-to(Cool $unit)
205
+ method truncated-to(DateTime:D: Cool $unit)
145
206
146
207
Returns a copy of the invocant, with everything smaller than the specified
147
208
unit truncated to the smallest possible value.
@@ -158,31 +219,36 @@ C<.truncated-to('second')>.
158
219
159
220
= head2 method Date
160
221
161
- method Date() returns Date:D
222
+ method Date(DateTime:D: ) returns Date:D
162
223
163
- Returns a L < Date|/type/Date > object for this datetime object.
224
+ Returns a L < Date|/type/Date > object for this datetime object. Which obviously
225
+ lacks the time component.
164
226
165
227
= head2 method utc
166
228
167
- method utc() returns DateTime:D
229
+ method utc(DateTime:D: ) returns DateTime:D
168
230
169
231
Returns a DateTime object for the same time, but in time zone UTC.
170
232
171
233
say DateTime.new('2015-12-24T12:23:00+0200').utc"; # 2015-12-24T10:23:00Z
172
234
173
235
= head2 method in-timezone
174
236
175
- method in-timezone($timezone = 0) returns DateTime:D
237
+ method in-timezone(DateTime:D: $timezone = 0) returns DateTime:D
176
238
177
239
Returns a DateTime object for the same time, but in the specified time zone.
178
240
179
241
say DateTime.new('2015-12-24T12:23:00Z').in-timezone(3600 + 1800);
180
242
# 2015-12-24T13:53:00+0130
181
243
182
- = begin comment
244
+ = head2 method local
183
245
184
- TODO: offset, offset-in-minutes, offset-in-hours, whole-second, local, Str
246
+ method local(DateTime:D:) returns DateTime:D
185
247
186
- = end comment
248
+ Returns a DateTime object for the same time, but in the local time zone
249
+ (C < $*TZ > ).
187
250
251
+ my $*TZ = -3600;
252
+ say DateTime.new('2015-12-24T12:23:00+0200').local;
253
+ # 2015-12-24T09:23:00-0100
188
254
= end pod
0 commit comments