Skip to content

Commit df4a66f

Browse files
committed
Document DateTime constructors
1 parent 1fbf07c commit df4a66f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

lib/Type/DateTime.pod

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
=begin pod
2+
3+
=TITLE class DateTime
4+
5+
=SUBTITLE A date and time object
6+
7+
class DateTime does Dateish { ... }
8+
9+
For handling points in civil time, a C<DateTime> object stores year, month,
10+
day, hour, minute (all L<Int|/type/Int>), second (potentially fractional) and
11+
a time zone.
12+
13+
It provides methods for calculating with date and time.
14+
15+
C<DateTime> methods are immutable; if you are tempted to modify one, create a
16+
modified copy instead.
17+
18+
Time zones are handled as L<Integers|/type/Int> in B<seconds> offset from UTC.
19+
20+
=head1 Methods
21+
22+
=head2 method new
23+
24+
multi method new(Int :$year!, Int :$month, Int :$day,
25+
Int :$hour, Int :$minute, :$second
26+
:$timezone, :&formatter)
27+
multi method new(Date :$date!,
28+
Int :$hour, Int :$minute, :$second
29+
:$timezone=0, :&formatter)
30+
multi method new(Instant:D $i, :$timezone=0, :&formatter)
31+
multi method new(Int:D $posix, :$timezone=0, :&formatter)
32+
multi method new(Str:D $format, :$timezone=0, :&formatter)
33+
34+
Creates a new C<DateTime> object. One option for creating a new DatTime object
35+
is from the components (year, month, day, hour, ...) separately. Another is to
36+
pass a L<Date|/type/Date> object for the date component, and specify the time
37+
component-wise. Yet another is to obtain the time from an
38+
L<Intstant|/type/Instant>, and only suplly the time zone and formatter. Or
39+
instead of an Instant you can supply an L<Int|/type/Int> as a UNIX timestamp,
40+
or a C<Str|/type/Str> formatted as C<yyyy-mm-ddThh:mm::ssZ> or
41+
C<yyyy-mm-ddThh:mm:ss+0100> (ISO 8601 timestamp notation).
42+
43+
An invalid input string throws and exception of type
44+
L<X::Temporal::InvalidFormat>. If you supply a string that includes a time
45+
zone and supply the C<timezone> named argument, and exception of type
46+
L<X::DateTime:TimezoneClash> is thrown.
47+
48+
=head2 method now
49+
50+
method now(:$timezone=*$TZ, &formatter) returns DateTime:D
51+
52+
Creates a new C<DateTime> object from the current system time, optionally with
53+
a different timezone than the default attached.
54+
55+
=head2 method clone
56+
57+
method clone(:$year, :$month, :$day, :$hour, :$minute, :$second,
58+
:$timezone, :&formatter)
59+
60+
Creates a new C<DateTime> object based on the invocant, but with the given
61+
arguments overriding the values from the invocant.
62+
63+
say DateTime.new('2015-12-24T12:23:00Z').clone(hour => 0);
64+
# 2015-12-24T00:23:00Z
65+
66+
=end pod

0 commit comments

Comments
 (0)