Skip to content

Commit b264497

Browse files
committed
Added usage statements to DateTime.pod
1 parent 3f016cd commit b264497

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

lib/Type/DateTime.pod

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ say $dt.in-timezone(-8 * 3600); # 2015-11-21T08:01:00-0800
3838
3939
=head2 method new
4040
41+
Defined as:
42+
4143
multi method new(Int :$year!, Int :$month, Int :$day,
4244
Int :$hour, Int :$minute, :$second
4345
:$timezone, :&formatter)
@@ -48,6 +50,16 @@ say $dt.in-timezone(-8 * 3600); # 2015-11-21T08:01:00-0800
4850
multi method new(Int:D $posix, :$timezone=0, :&formatter)
4951
multi method new(Str:D $format, :$timezone=0, :&formatter)
5052
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+
5163
Creates a new C<DateTime> object. One option for creating a new DateTime object
5264
is from the components (year, month, day, hour, ...) separately. Another is to
5365
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.
6476
6577
=head2 method now
6678
79+
Defined as:
80+
6781
method now(:$timezone=*$TZ, &formatter) returns DateTime:D
6882
83+
Usage:
84+
85+
DateTime.now
86+
6987
Creates a new C<DateTime> object from the current system time, optionally with
7088
a different timezone than the default attached.
7189
7290
=head2 method clone
7391
92+
Defined as:
93+
7494
method clone(:$year, :$month, :$day, :$hour, :$minute, :$second,
7595
:$timezone, :&formatter)
7696
97+
Usage:
98+
99+
DATETIME.clone(YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, TIMEZONE,
100+
FORMATTER)
101+
77102
Creates a new C<DateTime> object based on the invocant, but with the given
78103
arguments overriding the values from the invocant.
79104
@@ -87,75 +112,129 @@ Note that this can lead to invalid dates in some circumstances:
87112
88113
=head2 method hour
89114
115+
Defined as:
116+
90117
method hour(DateTime:D:) returns Int:D
91118
119+
Usage:
120+
121+
DATETIME.hour
122+
92123
Returns the hour component.
93124
94125
say DateTime.new('2012-02-29T12:34:56Z').hour; # 12
95126
96127
=head2 method minute
97128
129+
Defined as:
130+
98131
method minute(DateTime:D:) returns Int:D
99132
133+
Usage:
134+
135+
DATETIME.minute
136+
100137
Returns the minute component.
101138
102139
say DateTime.new('2012-02-29T12:34:56Z').minute; # 34
103140
104141
=head2 method second
105142
143+
Defined as:
144+
106145
method second(DateTime:D:)
107146
147+
Usage:
148+
149+
DATETIME.second
150+
108151
Returns the second component, including potentially fractional seconds.
109152
110153
say DateTime.new('2012-02-29T12:34:56Z').second; # 56
111154
112155
=head2 method whole-second
113156
157+
Defined as:
158+
114159
method whole-second(DateTime:D:)
115160
161+
Usage:
162+
163+
DATETIME.whole-second
164+
116165
Returns the second component, rounded down to an L<Int|/type/Int>.
117166
118167
say DateTime.new('2012-02-29T12:34:56Z').whole-second; # 56
119168
120169
=head2 method timezone
121170
171+
Defined as:
172+
122173
method timezone(DateTime:D:) returns Int:D
123174
175+
Usage:
176+
177+
DATETIME.timezone
178+
124179
Returns the time zone in seconds as an offset from UTC.
125180
126181
say DateTime.new('2015-12-24T12:23:00+0200').timezone; # 7200
127182
128183
=head2 method offset
129184
185+
Defined as:
186+
130187
method offset(DateTime:D:) returns Int:D
131188
189+
Usage:
190+
191+
DATETIME.offset
192+
132193
Returns the time zone in seconds as an offset from UTC. This is an alias for
133194
L<#method timezone>.
134195
135196
say DateTime.new('2015-12-24T12:23:00+0200').offset; # 7200
136197
137198
=head2 method offset-in-minutes
138199
200+
Defined as:
201+
139202
method offset-in-minutes(DateTime:D:) returns Real:D
140203
204+
Usage:
205+
206+
DATETIME.offset-in-minutes
207+
141208
Returns the time zone in minutes as an offset from UTC.
142209
143210
say DateTime.new('2015-12-24T12:23:00+0200').offset-in-minutes;
144211
# 120
145212
146213
=head2 method offset-in-hours
147214
215+
Defined as:
216+
148217
method offset-in-hours(DateTime:D:) returns Real:D
149218
219+
Usage:
220+
221+
DATETIME.offset-in-hours
222+
150223
Returns the time zone in hours as an offset from UTC.
151224
152225
say DateTime.new('2015-12-24T12:23:00+0200').offset-in-hours;
153226
# 2
154227
155228
=head2 method formatter
156229
230+
Defined as:
231+
157232
method formatter(DateTime:D:)
158233
234+
Usage:
235+
236+
DATETIME.formatter
237+
159238
Returns the formatting function which is used for conversion to
160239
L<Str|/type/Str>. If none was provided at object construction, a
161240
default formatter is used which produces an ISO 8601 timestamp.
@@ -165,29 +244,53 @@ only argument.
165244
166245
=head2 method Str
167246
247+
Defined as:
248+
168249
method Str(DateTime:D:) returns Str:D
169250
251+
Usage:
252+
253+
DATETIME.Str
254+
170255
Returns a string representation of the invocant, as done by
171256
L<the formatter|#method formatter>.
172257
173258
=head2 method Instant
174259
260+
Defined as:
261+
175262
method Instant(DateTime:D:) returns Instant:D
176263
264+
Usage:
265+
266+
DATETIME.Instant
267+
177268
Returns an L<Instant|/type/Instant> object based on the invocant.
178269
179270
=head2 method posix
180271
272+
Defined as:
273+
181274
method posix(DateTime:D: $ignore-timezone = False) returns Int:D
182275
276+
Usage:
277+
278+
DATETIME.posix
279+
183280
Returns the date and time as a POSIX/UNIX timestamp.
184281
185282
say DateTime.new('2015-12-24T12:23:00Z').posix; # 1450959780
186283
187284
=head2 method later
188285
286+
Defined as:
287+
189288
method later(DateTime:D: *%unit)
190289
290+
Usage:
291+
292+
DATETIME.later(DELTA)
293+
191294
Returns a DateTime object based on the current one, but with a time delta
192295
applied. The time delta can be passed as a named argument where the argument
193296
name is the unit.
@@ -211,15 +314,27 @@ that.
211314
212315
=head2 method earlier
213316
317+
Defined as:
318+
214319
method earlier(DateTime:D: *%unit)
215320
321+
Usage:
322+
323+
DATETIME.earlier(DELTA)
324+
216325
Returns a DateTime object based on the current one, but with a time delta
217326
towards the past applied. See L<#method later> for usage.
218327
219328
=head2 method truncated-to
220329
330+
Defined as:
331+
221332
method truncated-to(DateTime:D: Cool $unit)
222333
334+
Usage:
335+
336+
DATETIME.truncated-to(UNIT)
337+
223338
Returns a copy of the invocant, with everything smaller than the specified
224339
unit truncated to the smallest possible value.
225340
@@ -235,32 +350,56 @@ C<.truncated-to('second')>.
235350
236351
=head2 method Date
237352
353+
Defined as:
354+
238355
method Date(DateTime:D:) returns Date:D
239356
357+
Usage:
358+
359+
DATETIME.Date
360+
240361
Returns a L<Date|/type/Date> object for this DateTime object. Which obviously
241362
lacks the time component.
242363
243364
=head2 method utc
244365
366+
Defined as:
367+
245368
method utc(DateTime:D:) returns DateTime:D
246369
370+
Usage:
371+
372+
DATETIME.utc
373+
247374
Returns a DateTime object for the same time, but in time zone UTC.
248375
249376
say DateTime.new('2015-12-24T12:23:00+0200').utc"; # 2015-12-24T10:23:00Z
250377
251378
=head2 method in-timezone
252379
380+
Defined as:
381+
253382
method in-timezone(DateTime:D: $timezone = 0) returns DateTime:D
254383
384+
Usage:
385+
386+
DATETIME.in-timezone
387+
255388
Returns a DateTime object for the same time, but in the specified time zone.
256389
257390
say DateTime.new('2015-12-24T12:23:00Z').in-timezone(3600 + 1800);
258391
# 2015-12-24T13:53:00+0130
259392
260393
=head2 method local
261394
395+
Defined as:
396+
262397
method local(DateTime:D:) returns DateTime:D
263398
399+
Usage:
400+
401+
DATETIME.local
402+
264403
Returns a DateTime object for the same time, but in the local time zone
265404
(C<$*TZ>).
266405

0 commit comments

Comments
 (0)