Skip to content

Commit c6a0748

Browse files
authored
Merge pull request JuliaLang#40540 from JuliaLang/jn/31979
add some docs for Dates formatters
2 parents e37e98a + 8105252 commit c6a0748

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

stdlib/Dates/docs/src/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,15 @@ Months of the Year:
858858
| `November` | `Nov` | 11 |
859859
| `December` | `Dec` | 12 |
860860

861+
#### Common Date Formatters
862+
863+
```@docs
864+
ISODateTimeFormat
865+
ISODateFormat
866+
ISOTimeFormat
867+
RFC1123Format
868+
```
869+
861870
```@meta
862871
DocTestSetup = nothing
863872
```

stdlib/Dates/src/io.jl

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ When parsing a time with a `p` specifier, any hour (either `H` or `I`) is interp
367367
as a 12-hour clock, so the `I` code is mainly useful for output.
368368
369369
Creating a DateFormat object is expensive. Whenever possible, create it once and use it many times
370-
or try the `dateformat""` string macro. Using this macro creates the DateFormat object once at
371-
macro expansion time and reuses it later. see [`@dateformat_str`](@ref).
370+
or try the [`dateformat""`](@ref @dateformat_str) string macro. Using this macro creates the DateFormat
371+
object once at macro expansion time and reuses it later. There are also several [pre-defined formatters](@ref
372+
Common-Date-Formatters), listed later.
372373
373374
See [`DateTime`](@ref) and [`format`](@ref) for how to use a DateFormat object to parse and write Date strings
374375
respectively.
@@ -443,14 +444,63 @@ macro dateformat_str(str)
443444
end
444445

445446
# Standard formats
447+
448+
"""
449+
Dates.ISODateTimeFormat
450+
451+
Describes the ISO8601 formatting for a date and time. This is the default value for `Dates.format`
452+
of a `DateTime`.
453+
454+
# Example
455+
```jldoctest
456+
julia> Dates.format(DateTime(2018, 8, 8, 12, 0, 43, 1), ISODateTimeFormat)
457+
"2018-08-08T12:00:43.001"
458+
```
459+
"""
446460
const ISODateTimeFormat = DateFormat("yyyy-mm-dd\\THH:MM:SS.s")
461+
default_format(::Type{DateTime}) = ISODateTimeFormat
462+
463+
"""
464+
Dates.ISODateFormat
465+
466+
Describes the ISO8601 formatting for a date. This is the default value for `Dates.format` of a `Date`.
467+
468+
# Example
469+
```jldoctest
470+
julia> Dates.format(Date(2018, 8, 8), ISODateFormat)
471+
"2018-08-08"
472+
```
473+
"""
447474
const ISODateFormat = DateFormat("yyyy-mm-dd")
475+
default_format(::Type{Date}) = ISODateFormat
476+
477+
"""
478+
Dates.ISOTimeFormat
479+
480+
Describes the ISO8601 formatting for a time. This is the default value for `Dates.format` of a `Time`.
481+
482+
# Example
483+
```jldoctest
484+
julia> Dates.format(Time(12, 0, 43, 1), ISOTimeFormat)
485+
"12:00:43.001"
486+
```
487+
"""
448488
const ISOTimeFormat = DateFormat("HH:MM:SS.s")
489+
default_format(::Type{Time}) = ISOTimeFormat
490+
491+
"""
492+
Dates.RFC1123Format
493+
494+
Describes the RFC1123 formatting for a date and time.
495+
496+
# Example
497+
```jldoctest
498+
julia> Dates.format(DateTime(2018, 8, 8, 12, 0, 43, 1), RFC1123Format)
499+
"Wed, 08 Aug 2018 12:00:43"
500+
```
501+
"""
449502
const RFC1123Format = DateFormat("e, dd u yyyy HH:MM:SS")
450503

451-
default_format(::Type{DateTime}) = ISODateTimeFormat
452-
default_format(::Type{Date}) = ISODateFormat
453-
default_format(::Type{Time}) = ISOTimeFormat
454504

455505
### API
456506

0 commit comments

Comments
 (0)