Skip to content

Commit d81e22b

Browse files
committed
Document missing DateTime methods.
also correct some signatures, and remove from WANTED file
1 parent 1d442c2 commit d81e22b

File tree

2 files changed

+81
-16
lines changed

2 files changed

+81
-16
lines changed

WANTED

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Tutorials:
1515
* Exceptions
1616

1717
API docs:
18-
* DateTime
1918
* MOP
2019
* Scheduler
2120
* Thread

lib/Type/DateTime.pod

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,106 @@ Note that this can lead to invalid dates in some circumstances:
7171
7272
=head2 method hour
7373
74-
method hour(DateTime:D) returns Int:D
74+
method hour(DateTime:D:) returns Int:D
7575
7676
Returns the hour component.
7777
7878
say DateTime.new('2012-02-29T12:34:56Z').hour; # 12
7979
8080
=head2 method minute
8181
82-
method minute(DateTime:D) returns Int:D
82+
method minute(DateTime:D:) returns Int:D
8383
8484
Returns the minute component.
8585
8686
say DateTime.new('2012-02-29T12:34:56Z').minute; # 34
8787
8888
=head2 method second
8989
90-
method second(DateTime:D)
90+
method second(DateTime:D:)
9191
9292
Returns the second component, including potentially fractional seconds.
9393
9494
say DateTime.new('2012-02-29T12:34:56Z').second; # 56
9595
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+
96157
=head2 method Instant
97158
98-
method Instant() returns Instant:D
159+
method Instant(DateTime:D:) returns Instant:D
99160
100161
Returns an L<Instant|/type/Instant> object based on the invocant.
101162
102163
=head2 method posix
103164
104-
method posix($ignore-timezone = False) returns Int:D
165+
method posix(DateTime:D: $ignore-timezone = False) returns Int:D
105166
106167
Returns the date and time as a POSIX/UNIX timestamp.
107168
108169
say DateTime.new('2015-12-24T12:23:00Z').posix; # 1450959780
109170
110171
=head2 method later
111172
112-
method later(*%unit)
173+
method later(DateTime:D: *%unit)
113174
114175
Returns a DateTime object based on the current one, but with a time delta
115176
applied. The time delta can be passed as a named argument where the argument
@@ -134,14 +195,14 @@ that.
134195
135196
=head2 method earlier
136197
137-
method earlier(*%unit)
198+
method earlier(DateTime:D: *%unit)
138199
139200
Returns a DateTime object based on the current one, but with a time delta
140201
towards the past applied. See L<#method later> for usage.
141202
142203
=head2 method truncated-to
143204
144-
method truncated-to(Cool $unit)
205+
method truncated-to(DateTime:D: Cool $unit)
145206
146207
Returns a copy of the invocant, with everything smaller than the specified
147208
unit truncated to the smallest possible value.
@@ -158,31 +219,36 @@ C<.truncated-to('second')>.
158219
159220
=head2 method Date
160221
161-
method Date() returns Date:D
222+
method Date(DateTime:D:) returns Date:D
162223
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.
164226
165227
=head2 method utc
166228
167-
method utc() returns DateTime:D
229+
method utc(DateTime:D:) returns DateTime:D
168230
169231
Returns a DateTime object for the same time, but in time zone UTC.
170232
171233
say DateTime.new('2015-12-24T12:23:00+0200').utc"; # 2015-12-24T10:23:00Z
172234
173235
=head2 method in-timezone
174236
175-
method in-timezone($timezone = 0) returns DateTime:D
237+
method in-timezone(DateTime:D: $timezone = 0) returns DateTime:D
176238
177239
Returns a DateTime object for the same time, but in the specified time zone.
178240
179241
say DateTime.new('2015-12-24T12:23:00Z').in-timezone(3600 + 1800);
180242
# 2015-12-24T13:53:00+0130
181243
182-
=begin comment
244+
=head2 method local
183245
184-
TODO: offset, offset-in-minutes, offset-in-hours, whole-second, local, Str
246+
method local(DateTime:D:) returns DateTime:D
185247
186-
=end comment
248+
Returns a DateTime object for the same time, but in the local time zone
249+
(C<$*TZ>).
187250
251+
my $*TZ = -3600;
252+
say DateTime.new('2015-12-24T12:23:00+0200').local;
253+
# 2015-12-24T09:23:00-0100
188254
=end pod

0 commit comments

Comments
 (0)