4
4
DocTestSetup = :(using Dates)
5
5
```
6
6
7
- The ` Dates ` module provides two types for working with dates: [ ` Date ` ] ( @ref ) and [ ` DateTime ` ] ( @ref ) ,
8
- representing day and millisecond precision, respectively; both are subtypes of the abstract [ ` TimeType ` ] ( @ref ) .
7
+ The ` Dates ` module provides three types for representing dates and times:
8
+ [ ` Date ` ] ( @ref ) , [ ` DateTime ` ] ( @ref ) , and [ ` Time ` ] ( @ref ) representing
9
+ day, millisecond and nanosecond precision, respectively;
10
+ all are subtypes of the abstract [ ` TimeType ` ] ( @ref ) .
9
11
The motivation for distinct types is simple: some operations are much simpler, both in terms of
10
12
code and mental reasoning, when the complexities of greater precision don't have to be dealt with.
11
13
For example, since the [ ` Date ` ] ( @ref ) type only resolves to the precision of a single date (i.e.
@@ -14,7 +16,7 @@ time, and leap seconds are unnecessary and avoided.
14
16
15
17
Both [ ` Date ` ] ( @ref ) and [ ` DateTime ` ] ( @ref ) are basically immutable [ ` Int64 ` ] ( @ref ) wrappers.
16
18
The single ` instant ` field of either type is actually a ` UTInstant{P} ` type, which
17
- represents a continuously increasing machine timeline based on the UT second [ ^ 1 ] . The
19
+ represents a monotonically increasing machine timeline based on the UT second [ ^ 1 ] . The
18
20
[ ` DateTime ` ] ( @ref ) type is not aware of time zones (* naive* , in Python parlance),
19
21
analogous to a * LocalDateTime* in Java 8. Additional time zone functionality
20
22
can be added through the [ TimeZones.jl package] ( https://github.com/JuliaTime/TimeZones.jl/ ) , which
@@ -26,6 +28,10 @@ The ISO standard, however, states that 1 BC/BCE is year zero, so `0000-12-31` is
26
28
` 0001-01-01 ` , and year ` -0001 ` (yes, negative one for the year) is 2 BC/BCE, year ` -0002 ` is 3
27
29
BC/BCE, etc.
28
30
31
+ The [ ` Time ` ] ( @ref ) is also an immutable [ ` Int64 ` ] ( @ref ) wrapper, also based on the UT second [ ^ 1 ] ,
32
+ but constrained to represent the periodic (cyclic) time of the 24-hour day starting at midnight.
33
+ Note that midnight is represented as 0 hour - 24 hour is out of range.
34
+
29
35
[ ^ 1 ] :
30
36
The notion of the UT second is actually quite fundamental. There are basically two different notions
31
37
of time generally accepted, one based on the physical rotation of the earth (one full rotation
@@ -457,6 +463,18 @@ julia> collect(dr)
457
463
2014-05-29
458
464
2014-06-29
459
465
2014-07-29
466
+
467
+ julia> r = range(Time(0), step = Hour(9), length = 5)
468
+ Time(0):Hour(9):Time(12)
469
+
470
+ julia> collect(r)
471
+ 5-element Vector{Time}:
472
+ 00:00:00
473
+ 09:00:00
474
+ 18:00:00
475
+ 03:00:00
476
+ 12:00:00
477
+
460
478
```
461
479
462
480
## Adjuster Functions
@@ -707,7 +725,7 @@ Dates.UTC
707
725
Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64)
708
726
Dates.DateTime(::Dates.Period)
709
727
Dates.DateTime(::Function, ::Any...)
710
- Dates.DateTime(::Dates.TimeType )
728
+ Dates.DateTime(::Dates.Date )
711
729
Dates.DateTime(::AbstractString, ::AbstractString)
712
730
Dates.format(::Dates.TimeType, ::AbstractString)
713
731
Dates.DateFormat
@@ -716,7 +734,7 @@ Dates.DateTime(::AbstractString, ::Dates.DateFormat)
716
734
Dates.Date(::Int64, ::Int64, ::Int64)
717
735
Dates.Date(::Dates.Period)
718
736
Dates.Date(::Function, ::Any, ::Any, ::Any)
719
- Dates.Date(::Dates.TimeType )
737
+ Dates.Date(::Dates.DateTime )
720
738
Dates.Date(::AbstractString, ::AbstractString)
721
739
Dates.Date(::AbstractString, ::Dates.DateFormat)
722
740
Dates.Time(::Int64::Int64, ::Int64, ::Int64, ::Int64, ::Int64)
0 commit comments