You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/temporal.pod6
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,10 @@ X<|Date and time functions>
8
8
9
9
Raku includes several classes that deal with temporal information: L<Date|/type/Date>, L<DateTime|/type/DateTime>, L<Instant|/type/Instant> and L<Duration|/type/Duration>. The three first are I<dateish>, so they mix in the L<Dateish|/type/Dateish> role, which defines all methods and properties that classes that deal with date should assume. It also includes a class hierarchy of exceptions rooted in L<X::Temporal|/type/X::Temporal>.
10
10
11
-
We will try to illustrate these classes in the next (somewhat extended) example, which can be used to process all files in a directory (by default C<.>) with a particular extension (by default C<.p6>) in a directory, sort them according to their age, and compute how many files have been created per month and how many were modified in certain periods expressed in ranges of months:
11
+
We will try to illustrate these classes in the next (somewhat extended) example, which can be used to process all files in a directory (by default C<.>) with a particular extension (by default C<.raku>) in a directory, sort them according to their age, and compute how many files have been created per month and how many were modified in certain periods expressed in ranges of months:
C<DateTime> is used in line 2 to contain the current date and time returned by L<C<now>|/routine/now>.
60
60
61
-
A CATCH phaser is declared in lines 7 to 11. Its main mission is to distinguish between C<DateTime>-related exceptions and other types. These kind of exception can arise from L<invalid formats|/type/X::Temporal::InvalidFormat> or L<timezone clashes|/type/X::DateTime::TimezoneClash>. Barring some corruption of the file attributes, both are impossible, but in any case they should be caught and separated from other types of exceptions.
61
+
A CATCH phaser is declared in lines 7 to 11. Its main mission is to distinguish between C<DateTime>-related exceptions and other types. These kinds of exception can arise from L<invalid formats|/type/X::Temporal::InvalidFormat> or L<timezone clashes|/type/X::DateTime::TimezoneClash>. Barring some corruption of the file attributes, both are impossible, but in any case they should be caught and separated from other types of exceptions.
62
62
63
-
We use L<Instant|/type/Instant>s in lines 12-13 to represent the moment in which the files where accessed and modified. An Instant is measured in atomic seconds, and is a very low-level description of a time event; however, the L<Duration|/type/Duration> declared in line 14 represent the time transcurred among two different C<Instant>s, and we will be using it to represent the age.
63
+
We use L<Instant|/type/Instant>s in lines 12-13 to represent the moment in which the files where accessed and modified. An Instant is measured in atomic seconds and is a very low-level description of a time event; however, the L<Duration|/type/Duration> declared in line 14 represents the time transcurred among two different C<Instant>s and we will be using it to represent the age.
64
64
65
-
For some variables we might be interested in dealing with them with some I<dateish> traits. C<$time-of-day> contains the time of the day the file was changed; C<changed> will return an Instant, but it is converted into a Date (which is C<Dateish> while C<Instant> is not) and then the time of day is extracted from that. C<$time-of-day> will have C< «Str+{Dateish}» > type.
65
+
For some variables, we might be interested in dealing with them with some I<dateish> traits. C<$time-of-day> contains the time of the day the file was changed; C<changed> will return an Instant, but it is converted into a Date (which is C<Dateish> while C<Instant> is not) and then the time of day is extracted from that. C<$time-of-day> will have C< «Str+{Dateish}» > type.
66
66
67
67
X<|Date ranges>
68
68
We will use the date in this variable to find out the period when the files were changed.
0 commit comments