@@ -38,6 +38,8 @@ say $dt.in-timezone(-8 * 3600); # 2015-11-21T08:01:00-0800
38
38
39
39
= head2 method new
40
40
41
+ Defined as:
42
+
41
43
multi method new(Int :$year!, Int :$month, Int :$day,
42
44
Int :$hour, Int :$minute, :$second
43
45
:$timezone, :&formatter)
@@ -48,6 +50,16 @@ say $dt.in-timezone(-8 * 3600); # 2015-11-21T08:01:00-0800
48
50
multi method new(Int:D $posix, :$timezone=0, :&formatter)
49
51
multi method new(Str:D $format, :$timezone=0, :&formatter)
50
52
53
+ Usage:
54
+
55
+ $datetime = DateTime.new(YEAR, MONTH?, DAY?, HOUR? MINUTE?, SECOND?,
56
+ TIMEZONE?, FORMATTER?)
57
+ $datetime = DateTime.new(DATE, HOUR?, MINUTE?, SECOND?, TIMEZONE?,
58
+ FORMATTER?)
59
+ $datetime = DateTime.new(INSTANT, TIMEZONE?, FORMATTER?)
60
+ $datetime = DateTime.new(TIMESTAMP, TIMEZONE?, FORMATTER?)
61
+ $datetime = DateTime.new(FORMAT, TIMEZONE?, FORMATTER?)
62
+
51
63
Creates a new C < DateTime > object. One option for creating a new DateTime object
52
64
is from the components (year, month, day, hour, ...) separately. Another is to
53
65
pass a L < Date|/type/Date > object for the date component, and specify the time
@@ -64,16 +76,29 @@ L<X::DateTime:TimezoneClash> is thrown.
64
76
65
77
= head2 method now
66
78
79
+ Defined as:
80
+
67
81
method now(:$timezone=*$TZ, &formatter) returns DateTime:D
68
82
83
+ Usage:
84
+
85
+ DateTime.now
86
+
69
87
Creates a new C < DateTime > object from the current system time, optionally with
70
88
a different timezone than the default attached.
71
89
72
90
= head2 method clone
73
91
92
+ Defined as:
93
+
74
94
method clone(:$year, :$month, :$day, :$hour, :$minute, :$second,
75
95
:$timezone, :&formatter)
76
96
97
+ Usage:
98
+
99
+ DATETIME.clone(YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, TIMEZONE,
100
+ FORMATTER)
101
+
77
102
Creates a new C < DateTime > object based on the invocant, but with the given
78
103
arguments overriding the values from the invocant.
79
104
@@ -87,75 +112,129 @@ Note that this can lead to invalid dates in some circumstances:
87
112
88
113
= head2 method hour
89
114
115
+ Defined as:
116
+
90
117
method hour(DateTime:D:) returns Int:D
91
118
119
+ Usage:
120
+
121
+ DATETIME.hour
122
+
92
123
Returns the hour component.
93
124
94
125
say DateTime.new('2012-02-29T12:34:56Z').hour; # 12
95
126
96
127
= head2 method minute
97
128
129
+ Defined as:
130
+
98
131
method minute(DateTime:D:) returns Int:D
99
132
133
+ Usage:
134
+
135
+ DATETIME.minute
136
+
100
137
Returns the minute component.
101
138
102
139
say DateTime.new('2012-02-29T12:34:56Z').minute; # 34
103
140
104
141
= head2 method second
105
142
143
+ Defined as:
144
+
106
145
method second(DateTime:D:)
107
146
147
+ Usage:
148
+
149
+ DATETIME.second
150
+
108
151
Returns the second component, including potentially fractional seconds.
109
152
110
153
say DateTime.new('2012-02-29T12:34:56Z').second; # 56
111
154
112
155
= head2 method whole-second
113
156
157
+ Defined as:
158
+
114
159
method whole-second(DateTime:D:)
115
160
161
+ Usage:
162
+
163
+ DATETIME.whole-second
164
+
116
165
Returns the second component, rounded down to an L < Int|/type/Int > .
117
166
118
167
say DateTime.new('2012-02-29T12:34:56Z').whole-second; # 56
119
168
120
169
= head2 method timezone
121
170
171
+ Defined as:
172
+
122
173
method timezone(DateTime:D:) returns Int:D
123
174
175
+ Usage:
176
+
177
+ DATETIME.timezone
178
+
124
179
Returns the time zone in seconds as an offset from UTC.
125
180
126
181
say DateTime.new('2015-12-24T12:23:00+0200').timezone; # 7200
127
182
128
183
= head2 method offset
129
184
185
+ Defined as:
186
+
130
187
method offset(DateTime:D:) returns Int:D
131
188
189
+ Usage:
190
+
191
+ DATETIME.offset
192
+
132
193
Returns the time zone in seconds as an offset from UTC. This is an alias for
133
194
L < #method timezone > .
134
195
135
196
say DateTime.new('2015-12-24T12:23:00+0200').offset; # 7200
136
197
137
198
= head2 method offset-in-minutes
138
199
200
+ Defined as:
201
+
139
202
method offset-in-minutes(DateTime:D:) returns Real:D
140
203
204
+ Usage:
205
+
206
+ DATETIME.offset-in-minutes
207
+
141
208
Returns the time zone in minutes as an offset from UTC.
142
209
143
210
say DateTime.new('2015-12-24T12:23:00+0200').offset-in-minutes;
144
211
# 120
145
212
146
213
= head2 method offset-in-hours
147
214
215
+ Defined as:
216
+
148
217
method offset-in-hours(DateTime:D:) returns Real:D
149
218
219
+ Usage:
220
+
221
+ DATETIME.offset-in-hours
222
+
150
223
Returns the time zone in hours as an offset from UTC.
151
224
152
225
say DateTime.new('2015-12-24T12:23:00+0200').offset-in-hours;
153
226
# 2
154
227
155
228
= head2 method formatter
156
229
230
+ Defined as:
231
+
157
232
method formatter(DateTime:D:)
158
233
234
+ Usage:
235
+
236
+ DATETIME.formatter
237
+
159
238
Returns the formatting function which is used for conversion to
160
239
L < Str|/type/Str > . If none was provided at object construction, a
161
240
default formatter is used which produces an ISO 8601 timestamp.
@@ -165,29 +244,53 @@ only argument.
165
244
166
245
= head2 method Str
167
246
247
+ Defined as:
248
+
168
249
method Str(DateTime:D:) returns Str:D
169
250
251
+ Usage:
252
+
253
+ DATETIME.Str
254
+
170
255
Returns a string representation of the invocant, as done by
171
256
L < the formatter|#method formatter > .
172
257
173
258
= head2 method Instant
174
259
260
+ Defined as:
261
+
175
262
method Instant(DateTime:D:) returns Instant:D
176
263
264
+ Usage:
265
+
266
+ DATETIME.Instant
267
+
177
268
Returns an L < Instant|/type/Instant > object based on the invocant.
178
269
179
270
= head2 method posix
180
271
272
+ Defined as:
273
+
181
274
method posix(DateTime:D: $ignore-timezone = False) returns Int:D
182
275
276
+ Usage:
277
+
278
+ DATETIME.posix
279
+
183
280
Returns the date and time as a POSIX/UNIX timestamp.
184
281
185
282
say DateTime.new('2015-12-24T12:23:00Z').posix; # 1450959780
186
283
187
284
= head2 method later
188
285
286
+ Defined as:
287
+
189
288
method later(DateTime:D: *%unit)
190
289
290
+ Usage:
291
+
292
+ DATETIME.later(DELTA)
293
+
191
294
Returns a DateTime object based on the current one, but with a time delta
192
295
applied. The time delta can be passed as a named argument where the argument
193
296
name is the unit.
@@ -211,15 +314,27 @@ that.
211
314
212
315
= head2 method earlier
213
316
317
+ Defined as:
318
+
214
319
method earlier(DateTime:D: *%unit)
215
320
321
+ Usage:
322
+
323
+ DATETIME.earlier(DELTA)
324
+
216
325
Returns a DateTime object based on the current one, but with a time delta
217
326
towards the past applied. See L < #method later > for usage.
218
327
219
328
= head2 method truncated-to
220
329
330
+ Defined as:
331
+
221
332
method truncated-to(DateTime:D: Cool $unit)
222
333
334
+ Usage:
335
+
336
+ DATETIME.truncated-to(UNIT)
337
+
223
338
Returns a copy of the invocant, with everything smaller than the specified
224
339
unit truncated to the smallest possible value.
225
340
@@ -235,32 +350,56 @@ C<.truncated-to('second')>.
235
350
236
351
= head2 method Date
237
352
353
+ Defined as:
354
+
238
355
method Date(DateTime:D:) returns Date:D
239
356
357
+ Usage:
358
+
359
+ DATETIME.Date
360
+
240
361
Returns a L < Date|/type/Date > object for this DateTime object. Which obviously
241
362
lacks the time component.
242
363
243
364
= head2 method utc
244
365
366
+ Defined as:
367
+
245
368
method utc(DateTime:D:) returns DateTime:D
246
369
370
+ Usage:
371
+
372
+ DATETIME.utc
373
+
247
374
Returns a DateTime object for the same time, but in time zone UTC.
248
375
249
376
say DateTime.new('2015-12-24T12:23:00+0200').utc"; # 2015-12-24T10:23:00Z
250
377
251
378
= head2 method in-timezone
252
379
380
+ Defined as:
381
+
253
382
method in-timezone(DateTime:D: $timezone = 0) returns DateTime:D
254
383
384
+ Usage:
385
+
386
+ DATETIME.in-timezone
387
+
255
388
Returns a DateTime object for the same time, but in the specified time zone.
256
389
257
390
say DateTime.new('2015-12-24T12:23:00Z').in-timezone(3600 + 1800);
258
391
# 2015-12-24T13:53:00+0130
259
392
260
393
= head2 method local
261
394
395
+ Defined as:
396
+
262
397
method local(DateTime:D:) returns DateTime:D
263
398
399
+ Usage:
400
+
401
+ DATETIME.local
402
+
264
403
Returns a DateTime object for the same time, but in the local time zone
265
404
(C < $*TZ > ).
266
405
0 commit comments