日期

  1. DocTestSetup = :(using Dates)

Dates 模块提供了两种类型来处理日期:DateDateTime,分别精确到日和毫秒;两者都是抽象类型 TimeType 的子类型。区分类型的动机很简单:不必处理更高精度所带来的复杂性时,一些操作在代码和思维推理上都更加简单。例如,由于 Date 类型仅精确到日(即没有时、分或秒),因此避免了时区、夏令时和闰秒等不必要的通常考虑。

DateDateTime 类型都是基本不可变类型 Int64 的包装类。这两种类型的单个 instant 字段实际上属于 UTInstant{P} 类型。这种类型表示的是一种基于世界时间(UT)持续增长的机器时间 [^1]。DateTime 类型并不考虑时区(用 Python 的话讲,它是 naive 的),与 Java 8 中的 LocalDateTime 类似。如果需要附加时区功能,可以通过 TimeZones.jl 包 实现,其汇编了来自 IANA 时区数据库 的数据。DateDateTime 都基于 ISO 8601 标准,遵循公历(格里高利历)。 值得注意的是,ISO 8601 标准对公元前的日期需要特别处理。通常来说,公元前的最后一天是公元前 1 年的 12 月 31 日,接下来的一天是公元 1 年的 1 月 1 日,公元 0 年是不存在的。但是,在 ISO 8601 标准中,公元前 1 年被表示为 0 年,即 0001-01-01 的前一天是 0000-12-31,而 -0001(没错,年数为-1)的那一年则实际上是公元前 2 年,-0002 则表示公元前 3 年,以此类推。

[^1]: The notion of the UT second is actually quite fundamental. There are basically two different notions of time generally accepted, one based on the physical rotation of the earth (one full rotation = 1 day), the other based on the SI second (a fixed, constant value). These are radically different! Think about it, a “UT second”, as defined relative to the rotation of the earth, may have a different absolute length depending on the day! Anyway, the fact that Date and DateTime are based on UT seconds is a simplifying, yet honest assumption so that things like leap seconds and all their complexity can be avoided. This basis of time is formally called UT or UT1. Basing types on the UT second basically means that every minute has 60 seconds and every day has 24 hours and leads to more natural calculations when working with calendar dates.

构造函数

DateDateTime 类型可以通过整数或 Period 类型,解析,或调整器来构造(稍后会详细介绍):

  1. julia> DateTime(2013)
  2. 2013-01-01T00:00:00
  3. julia> DateTime(2013,7)
  4. 2013-07-01T00:00:00
  5. julia> DateTime(2013,7,1)
  6. 2013-07-01T00:00:00
  7. julia> DateTime(2013,7,1,12)
  8. 2013-07-01T12:00:00
  9. julia> DateTime(2013,7,1,12,30)
  10. 2013-07-01T12:30:00
  11. julia> DateTime(2013,7,1,12,30,59)
  12. 2013-07-01T12:30:59
  13. julia> DateTime(2013,7,1,12,30,59,1)
  14. 2013-07-01T12:30:59.001
  15. julia> Date(2013)
  16. 2013-01-01
  17. julia> Date(2013,7)
  18. 2013-07-01
  19. julia> Date(2013,7,1)
  20. 2013-07-01
  21. julia> Date(Dates.Year(2013),Dates.Month(7),Dates.Day(1))
  22. 2013-07-01
  23. julia> Date(Dates.Month(7),Dates.Year(2013))
  24. 2013-07-01

Date or DateTime parsing is accomplished by the use of format strings. Format strings work by the notion of defining delimited or fixed-width “slots” that contain a period to parse and passing the text to parse and format string to a Date or DateTime constructor, of the form Date("2015-01-01",dateformat"y-m-d") or DateTime("20150101",dateformat"yyyymmdd").

有分隔的插入点是通过指定解析器在两个时段之间的分隔符来进行标记的。例如,"y-m-d" 会告诉解析器,一个诸如 "2014-07-16" 的时间字符串,应该在第一个和第二个插入点之间查找 - 字符。ymd 字符则告诉解析器每一个插入点对应的时段名称。

As in the case of constructors above such as Date(2013), delimited DateFormats allow for missing parts of dates and times so long as the preceding parts are given. The other parts are given the usual default values. For example, Date("1981-03", dateformat"y-m-d") returns 1981-03-01, whilst Date("31/12", dateformat"d/m/y") gives 0001-12-31. (Note that the default year is 1 AD/CE.) Consequently, an empty string will always return 0001-01-01 for Dates, and 0001-01-01T00:00:00.000 for DateTimes.

Fixed-width slots are specified by repeating the period character the number of times corresponding to the width with no delimiter between characters. So dateformat"yyyymmdd" would correspond to a date string like "20140716". The parser distinguishes a fixed-width slot by the absence of a delimiter, noting the transition "yyyymm" from one period character to the next.

Support for text-form month parsing is also supported through the u and U characters, for abbreviated and full-length month names, respectively. By default, only English month names are supported, so u corresponds to “Jan”, “Feb”, “Mar”, etc. And U corresponds to “January”, “February”, “March”, etc. Similar to other name=>value mapping functions dayname and monthname, custom locales can be loaded by passing in the locale=>Dict{String,Int} mapping to the MONTHTOVALUEABBR and MONTHTOVALUE dicts for abbreviated and full-name month names, respectively.

The above examples used the dateformat"" string macro. This macro creates a DateFormat object once when the macro is expanded and uses the same DateFormat object even if a code snippet is run multiple times.

  1. julia> for i = 1:10^5
  2. Date("2015-01-01", dateformat"y-m-d")
  3. end

Or you can create the DateFormat object explicitly:

  1. julia> df = DateFormat("y-m-d");
  2. julia> dt = Date("2015-01-01",df)
  3. 2015-01-01
  4. julia> dt2 = Date("2015-01-02",df)
  5. 2015-01-02

Alternatively, use broadcasting:

  1. julia> years = ["2015", "2016"];
  2. julia> Date.(years, DateFormat("yyyy"))
  3. 2-element Vector{Date}:
  4. 2015-01-01
  5. 2016-01-01

For convenience, you may pass the format string directly (e.g., Date("2015-01-01","y-m-d")), although this form incurs performance costs if you are parsing the same format repeatedly, as it internally creates a new DateFormat object each time.

As well as via the constructors, a Date or DateTime can be constructed from strings using the parse and tryparse functions, but with an optional third argument of type DateFormat specifying the format; for example, parse(Date, "06.23.2013", dateformat"m.d.y"), or tryparse(DateTime, "1999-12-31T23:59:59") which uses the default format. The notable difference between the functions is that with tryparse, an error is not thrown if the string is in an invalid format; instead nothing is returned. Note however that as with the constructors above, empty date and time parts assume default values and consequently an empty string ("") is valid for any DateFormat, giving for example a Date of 0001-01-01. Code relying on parse or tryparse for Date and DateTime parsing should therefore also check whether parsed strings are empty before using the result.

A full suite of parsing and formatting tests and examples is available in stdlib/Dates/test/io.jl.

Durations/Comparisons

Finding the length of time between two Date or DateTime is straightforward given their underlying representation as UTInstant{Day} and UTInstant{Millisecond}, respectively. The difference between Date is returned in the number of Day, and DateTime in the number of Millisecond. Similarly, comparing TimeType is a simple matter of comparing the underlying machine instants (which in turn compares the internal Int64 values).

  1. julia> dt = Date(2012,2,29)
  2. 2012-02-29
  3. julia> dt2 = Date(2000,2,1)
  4. 2000-02-01
  5. julia> dump(dt)
  6. Date
  7. instant: Dates.UTInstant{Day}
  8. periods: Day
  9. value: Int64 734562
  10. julia> dump(dt2)
  11. Date
  12. instant: Dates.UTInstant{Day}
  13. periods: Day
  14. value: Int64 730151
  15. julia> dt > dt2
  16. true
  17. julia> dt != dt2
  18. true
  19. julia> dt + dt2
  20. ERROR: MethodError: no method matching +(::Date, ::Date)
  21. [...]
  22. julia> dt * dt2
  23. ERROR: MethodError: no method matching *(::Date, ::Date)
  24. [...]
  25. julia> dt / dt2
  26. ERROR: MethodError: no method matching /(::Date, ::Date)
  27. julia> dt - dt2
  28. 4411 days
  29. julia> dt2 - dt
  30. -4411 days
  31. julia> dt = DateTime(2012,2,29)
  32. 2012-02-29T00:00:00
  33. julia> dt2 = DateTime(2000,2,1)
  34. 2000-02-01T00:00:00
  35. julia> dt - dt2
  36. 381110400000 milliseconds

Accessor Functions

Because the Date and DateTime types are stored as single Int64 values, date parts or fields can be retrieved through accessor functions. The lowercase accessors return the field as an integer:

```jldoctest tdate julia> t = Date(2014, 1, 31) 2014-01-31

julia> Dates.year(t) 2014

julia> Dates.month(t) 1

julia> Dates.week(t) 5

julia> Dates.day(t) 31

  1. While propercase return the same value in the corresponding [`Period`]($zh_CN-stdlib-Dates-docs-src-@ref) type:
  2. ```jldoctest tdate
  3. julia> Dates.Year(t)
  4. 2014 years
  5. julia> Dates.Day(t)
  6. 31 days

Compound methods are provided because it is more efficient to access multiple fields at the same time than individually:

```jldoctest tdate julia> Dates.yearmonth(t) (2014, 1)

julia> Dates.monthday(t) (1, 31)

julia> Dates.yearmonthday(t) (2014, 1, 31)

  1. One may also access the underlying `UTInstant` or integer value:
  2. ```jldoctest tdate
  3. julia> dump(t)
  4. Date
  5. instant: Dates.UTInstant{Day}
  6. periods: Day
  7. value: Int64 735264
  8. julia> t.instant
  9. Dates.UTInstant{Day}(Day(735264))
  10. julia> Dates.value(t)
  11. 735264

Query Functions

Query functions provide calendrical information about a TimeType. They include information about the day of the week:

```jldoctest tdate2 julia> t = Date(2014, 1, 31) 2014-01-31

julia> Dates.dayofweek(t) 5

julia> Dates.dayname(t) “Friday”

julia> Dates.dayofweekofmonth(t) # 5th Friday of January 5

  1. Month of the year:
  2. ```jldoctest tdate2
  3. julia> Dates.monthname(t)
  4. "January"
  5. julia> Dates.daysinmonth(t)
  6. 31

As well as information about the TimeType‘s year and quarter:

```jldoctest tdate2 julia> Dates.isleapyear(t) false

julia> Dates.dayofyear(t) 31

julia> Dates.quarterofyear(t) 1

julia> Dates.dayofquarter(t) 31

  1. The [`dayname`]($zh_CN-stdlib-Dates-docs-src-@ref) and [`monthname`]($zh_CN-stdlib-Dates-docs-src-@ref) methods can also take an optional `locale` keyword
  2. that can be used to return the name of the day or month of the year for other languages/locales.
  3. There are also versions of these functions returning the abbreviated names, namely
  4. [`dayabbr`]($zh_CN-stdlib-Dates-docs-src-@ref) and [`monthabbr`]($zh_CN-stdlib-Dates-docs-src-@ref).
  5. First the mapping is loaded into the `LOCALES` variable:
  6. ```jldoctest tdate2
  7. julia> french_months = ["janvier", "février", "mars", "avril", "mai", "juin",
  8. "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
  9. julia> french_monts_abbrev = ["janv","févr","mars","avril","mai","juin",
  10. "juil","août","sept","oct","nov","déc"];
  11. julia> french_days = ["lundi","mardi","mercredi","jeudi","vendredi","samedi","dimanche"];
  12. julia> Dates.LOCALES["french"] = Dates.DateLocale(french_months, french_monts_abbrev, french_days, [""]);

The above mentioned functions can then be used to perform the queries:

```jldoctest tdate2 julia> Dates.dayname(t;locale=”french”) “vendredi”

julia> Dates.monthname(t;locale=”french”) “janvier”

julia> Dates.monthabbr(t;locale=”french”) “janv”

  1. Since the abbreviated versions of the days are not loaded, trying to use the
  2. function `dayabbr` will error.
  3. ```jldoctest tdate2
  4. julia> Dates.dayabbr(t;locale="french")
  5. ERROR: BoundsError: attempt to access 1-element Vector{String} at index [5]
  6. Stacktrace:
  7. [...]

TimeType-Period Arithmetic

It’s good practice when using any language/date framework to be familiar with how date-period arithmetic is handled as there are some tricky issues to deal with (though much less so for day-precision types).

The Dates module approach tries to follow the simple principle of trying to change as little as possible when doing Period arithmetic. This approach is also often known as calendrical arithmetic or what you would probably guess if someone were to ask you the same calculation in a conversation. Why all the fuss about this? Let’s take a classic example: add 1 month to January 31st, 2014. What’s the answer? Javascript will say March 3 (assumes 31 days). PHP says March 2 (assumes 30 days). The fact is, there is no right answer. In the Dates module, it gives the result of February 28th. How does it figure that out? Consider the classic 7-7-7 gambling game in casinos.

Now just imagine that instead of 7-7-7, the slots are Year-Month-Day, or in our example, 2014-01-31. When you ask to add 1 month to this date, the month slot is incremented, so now we have 2014-02-31. Then the day number is checked if it is greater than the last valid day of the new month; if it is (as in the case above), the day number is adjusted down to the last valid day (28). What are the ramifications with this approach? Go ahead and add another month to our date, 2014-02-28 + Month(1) == 2014-03-28. What? Were you expecting the last day of March? Nope, sorry, remember the 7-7-7 slots. As few slots as possible are going to change, so we first increment the month slot by 1, 2014-03-28, and boom, we’re done because that’s a valid date. On the other hand, if we were to add 2 months to our original date, 2014-01-31, then we end up with 2014-03-31, as expected. The other ramification of this approach is a loss in associativity when a specific ordering is forced (i.e. adding things in different orders results in different outcomes). For example:

  1. julia> (Date(2014,1,29)+Dates.Day(1)) + Dates.Month(1)
  2. 2014-02-28
  3. julia> (Date(2014,1,29)+Dates.Month(1)) + Dates.Day(1)
  4. 2014-03-01

What’s going on there? In the first line, we’re adding 1 day to January 29th, which results in 2014-01-30; then we add 1 month, so we get 2014-02-30, which then adjusts down to 2014-02-28. In the second example, we add 1 month first, where we get 2014-02-29, which adjusts down to 2014-02-28, and then add 1 day, which results in 2014-03-01. One design principle that helps in this case is that, in the presence of multiple Periods, the operations will be ordered by the Periods’ types, not their value or positional order; this means Year will always be added first, then Month, then Week, etc. Hence the following does result in associativity and Just Works:

  1. julia> Date(2014,1,29) + Dates.Day(1) + Dates.Month(1)
  2. 2014-03-01
  3. julia> Date(2014,1,29) + Dates.Month(1) + Dates.Day(1)
  4. 2014-03-01

Tricky? Perhaps. What is an innocent Dates user to do? The bottom line is to be aware that explicitly forcing a certain associativity, when dealing with months, may lead to some unexpected results, but otherwise, everything should work as expected. Thankfully, that’s pretty much the extent of the odd cases in date-period arithmetic when dealing with time in UT (avoiding the “joys” of dealing with daylight savings, leap seconds, etc.).

As a bonus, all period arithmetic objects work directly with ranges:

  1. julia> dr = Date(2014,1,29):Day(1):Date(2014,2,3)
  2. Date("2014-01-29"):Day(1):Date("2014-02-03")
  3. julia> collect(dr)
  4. 6-element Vector{Date}:
  5. 2014-01-29
  6. 2014-01-30
  7. 2014-01-31
  8. 2014-02-01
  9. 2014-02-02
  10. 2014-02-03
  11. julia> dr = Date(2014,1,29):Dates.Month(1):Date(2014,07,29)
  12. Date("2014-01-29"):Month(1):Date("2014-07-29")
  13. julia> collect(dr)
  14. 7-element Vector{Date}:
  15. 2014-01-29
  16. 2014-02-28
  17. 2014-03-29
  18. 2014-04-29
  19. 2014-05-29
  20. 2014-06-29
  21. 2014-07-29

Adjuster Functions

As convenient as date-period arithmetic is, often the kinds of calculations needed on dates take on a calendrical or temporal nature rather than a fixed number of periods. Holidays are a perfect example; most follow rules such as “Memorial Day = Last Monday of May”, or “Thanksgiving = 4th Thursday of November”. These kinds of temporal expressions deal with rules relative to the calendar, like first or last of the month, next Tuesday, or the first and third Wednesdays, etc.

The Dates module provides the adjuster API through several convenient methods that aid in simply and succinctly expressing temporal rules. The first group of adjuster methods deal with the first and last of weeks, months, quarters, and years. They each take a single TimeType as input and return or adjust to the first or last of the desired period relative to the input.

  1. julia> Dates.firstdayofweek(Date(2014,7,16)) # Adjusts the input to the Monday of the input's week
  2. 2014-07-14
  3. julia> Dates.lastdayofmonth(Date(2014,7,16)) # Adjusts to the last day of the input's month
  4. 2014-07-31
  5. julia> Dates.lastdayofquarter(Date(2014,7,16)) # Adjusts to the last day of the input's quarter
  6. 2014-09-30

The next two higher-order methods, tonext, and toprev, generalize working with temporal expressions by taking a DateFunction as first argument, along with a starting TimeType. A DateFunction is just a function, usually anonymous, that takes a single TimeType as input and returns a Bool, true indicating a satisfied adjustment criterion. For example:

  1. julia> istuesday = x->Dates.dayofweek(x) == Dates.Tuesday; # Returns true if the day of the week of x is Tuesday
  2. julia> Dates.tonext(istuesday, Date(2014,7,13)) # 2014-07-13 is a Sunday
  3. 2014-07-15
  4. julia> Dates.tonext(Date(2014,7,13), Dates.Tuesday) # Convenience method provided for day of the week adjustments
  5. 2014-07-15

This is useful with the do-block syntax for more complex temporal expressions:

  1. julia> Dates.tonext(Date(2014,7,13)) do x
  2. # Return true on the 4th Thursday of November (Thanksgiving)
  3. Dates.dayofweek(x) == Dates.Thursday &&
  4. Dates.dayofweekofmonth(x) == 4 &&
  5. Dates.month(x) == Dates.November
  6. end
  7. 2014-11-27

The Base.filter method can be used to obtain all valid dates/moments in a specified range:

  1. # Pittsburgh street cleaning; Every 2nd Tuesday from April to November
  2. # Date range from January 1st, 2014 to January 1st, 2015
  3. julia> dr = Dates.Date(2014):Day(1):Dates.Date(2015);
  4. julia> filter(dr) do x
  5. Dates.dayofweek(x) == Dates.Tue &&
  6. Dates.April <= Dates.month(x) <= Dates.Nov &&
  7. Dates.dayofweekofmonth(x) == 2
  8. end
  9. 8-element Vector{Date}:
  10. 2014-04-08
  11. 2014-05-13
  12. 2014-06-10
  13. 2014-07-08
  14. 2014-08-12
  15. 2014-09-09
  16. 2014-10-14
  17. 2014-11-11

Additional examples and tests are available in stdlib/Dates/test/adjusters.jl.

Period Types

Periods are a human view of discrete, sometimes irregular durations of time. Consider 1 month; it could represent, in days, a value of 28, 29, 30, or 31 depending on the year and month context. Or a year could represent 365 or 366 days in the case of a leap year. Period types are simple Int64 wrappers and are constructed by wrapping any Int64 convertible type, i.e. Year(1) or Month(3.0). Arithmetic between Period of the same type behave like integers, and limited Period-Real arithmetic is available. You can extract the underlying integer with Dates.value.

  1. julia> y1 = Dates.Year(1)
  2. 1 year
  3. julia> y2 = Dates.Year(2)
  4. 2 years
  5. julia> y3 = Dates.Year(10)
  6. 10 years
  7. julia> y1 + y2
  8. 3 years
  9. julia> div(y3,y2)
  10. 5
  11. julia> y3 - y2
  12. 8 years
  13. julia> y3 % y2
  14. 0 years
  15. julia> div(y3,3) # mirrors integer division
  16. 3 years
  17. julia> Dates.value(Dates.Millisecond(10))
  18. 10

Rounding

Date and DateTime values can be rounded to a specified resolution (e.g., 1 month or 15 minutes) with floor, ceil, or round:

  1. julia> floor(Date(1985, 8, 16), Dates.Month)
  2. 1985-08-01
  3. julia> ceil(DateTime(2013, 2, 13, 0, 31, 20), Dates.Minute(15))
  4. 2013-02-13T00:45:00
  5. julia> round(DateTime(2016, 8, 6, 20, 15), Dates.Day)
  6. 2016-08-07T00:00:00

Unlike the numeric round method, which breaks ties toward the even number by default, the TimeTyperound method uses the RoundNearestTiesUp rounding mode. (It’s difficult to guess what breaking ties to nearest “even” TimeType would entail.) Further details on the available RoundingMode s can be found in the API reference.

Rounding should generally behave as expected, but there are a few cases in which the expected behaviour is not obvious.

Rounding Epoch

In many cases, the resolution specified for rounding (e.g., Dates.Second(30)) divides evenly into the next largest period (in this case, Dates.Minute(1)). But rounding behaviour in cases in which this is not true may lead to confusion. What is the expected result of rounding a DateTime to the nearest 10 hours?

  1. julia> round(DateTime(2016, 7, 17, 11, 55), Dates.Hour(10))
  2. 2016-07-17T12:00:00

That may seem confusing, given that the hour (12) is not divisible by 10. The reason that 2016-07-17T12:00:00 was chosen is that it is 17,676,660 hours after 0000-01-01T00:00:00, and 17,676,660 is divisible by 10.

As Julia Date and DateTime values are represented according to the ISO 8601 standard, 0000-01-01T00:00:00 was chosen as base (or “rounding epoch”) from which to begin the count of days (and milliseconds) used in rounding calculations. (Note that this differs slightly from Julia’s internal representation of Date s using Rata Die notation; but since the ISO 8601 standard is most visible to the end user, 0000-01-01T00:00:00 was chosen as the rounding epoch instead of the 0000-12-31T00:00:00 used internally to minimize confusion.)

The only exception to the use of 0000-01-01T00:00:00 as the rounding epoch is when rounding to weeks. Rounding to the nearest week will always return a Monday (the first day of the week as specified by ISO 8601). For this reason, we use 0000-01-03T00:00:00 (the first day of the first week of year 0000, as defined by ISO 8601) as the base when rounding to a number of weeks.

Here is a related case in which the expected behaviour is not necessarily obvious: What happens when we round to the nearest P(2), where P is a Period type? In some cases (specifically, when P <: Dates.TimePeriod) the answer is clear:

  1. julia> round(DateTime(2016, 7, 17, 8, 55, 30), Dates.Hour(2))
  2. 2016-07-17T08:00:00
  3. julia> round(DateTime(2016, 7, 17, 8, 55, 30), Dates.Minute(2))
  4. 2016-07-17T08:56:00

This seems obvious, because two of each of these periods still divides evenly into the next larger order period. But in the case of two months (which still divides evenly into one year), the answer may be surprising:

  1. julia> round(DateTime(2016, 7, 17, 8, 55, 30), Dates.Month(2))
  2. 2016-07-01T00:00:00

Why round to the first day in July, even though it is month 7 (an odd number)? The key is that months are 1-indexed (the first month is assigned 1), unlike hours, minutes, seconds, and milliseconds (the first of which are assigned 0).

This means that rounding a DateTime to an even multiple of seconds, minutes, hours, or years (because the ISO 8601 specification includes a year zero) will result in a DateTime with an even value in that field, while rounding a DateTime to an even multiple of months will result in the months field having an odd value. Because both months and years may contain an irregular number of days, whether rounding to an even number of days will result in an even value in the days field is uncertain.

See the API reference for additional information on methods exported from the Dates module.

API reference

Dates and Time Types

  1. Dates.Period
  2. Dates.CompoundPeriod
  3. Dates.Instant
  4. Dates.UTInstant
  5. Dates.TimeType
  6. Dates.DateTime
  7. Dates.Date
  8. Dates.Time
  9. Dates.TimeZone
  10. Dates.UTC

Dates Functions

  1. Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64)
  2. Dates.DateTime(::Dates.Period)
  3. Dates.DateTime(::Function, ::Any...)
  4. Dates.DateTime(::Dates.TimeType)
  5. Dates.DateTime(::AbstractString, ::AbstractString)
  6. Dates.format(::Dates.TimeType, ::AbstractString)
  7. Dates.DateFormat
  8. Dates.@dateformat_str
  9. Dates.DateTime(::AbstractString, ::Dates.DateFormat)
  10. Dates.Date(::Int64, ::Int64, ::Int64)
  11. Dates.Date(::Dates.Period)
  12. Dates.Date(::Function, ::Any, ::Any, ::Any)
  13. Dates.Date(::Dates.TimeType)
  14. Dates.Date(::AbstractString, ::AbstractString)
  15. Dates.Date(::AbstractString, ::Dates.DateFormat)
  16. Dates.Time(::Int64::Int64, ::Int64, ::Int64, ::Int64, ::Int64)
  17. Dates.Time(::Dates.TimePeriod)
  18. Dates.Time(::Function, ::Any...)
  19. Dates.Time(::Dates.DateTime)
  20. Dates.Time(::AbstractString, ::AbstractString)
  21. Dates.Time(::AbstractString, ::Dates.DateFormat)
  22. Dates.now()
  23. Dates.now(::Type{Dates.UTC})
  24. Base.eps(::Union{Type{DateTime}, Type{Date}, Type{Time}, TimeType})

Accessor Functions

  1. Dates.year
  2. Dates.month
  3. Dates.week
  4. Dates.day
  5. Dates.hour
  6. Dates.minute
  7. Dates.second
  8. Dates.millisecond
  9. Dates.microsecond
  10. Dates.nanosecond
  11. Dates.Year(::Dates.TimeType)
  12. Dates.Month(::Dates.TimeType)
  13. Dates.Week(::Dates.TimeType)
  14. Dates.Day(::Dates.TimeType)
  15. Dates.Hour(::DateTime)
  16. Dates.Minute(::DateTime)
  17. Dates.Second(::DateTime)
  18. Dates.Millisecond(::DateTime)
  19. Dates.Microsecond(::Dates.Time)
  20. Dates.Nanosecond(::Dates.Time)
  21. Dates.yearmonth
  22. Dates.monthday
  23. Dates.yearmonthday

Query Functions

  1. Dates.dayname
  2. Dates.dayabbr
  3. Dates.dayofweek
  4. Dates.dayofmonth
  5. Dates.dayofweekofmonth
  6. Dates.daysofweekinmonth
  7. Dates.monthname
  8. Dates.monthabbr
  9. Dates.daysinmonth
  10. Dates.isleapyear
  11. Dates.dayofyear
  12. Dates.daysinyear
  13. Dates.quarterofyear
  14. Dates.dayofquarter

Adjuster Functions

  1. Base.trunc(::Dates.TimeType, ::Type{Dates.Period})
  2. Dates.firstdayofweek
  3. Dates.lastdayofweek
  4. Dates.firstdayofmonth
  5. Dates.lastdayofmonth
  6. Dates.firstdayofyear
  7. Dates.lastdayofyear
  8. Dates.firstdayofquarter
  9. Dates.lastdayofquarter
  10. Dates.tonext(::Dates.TimeType, ::Int)
  11. Dates.toprev(::Dates.TimeType, ::Int)
  12. Dates.tofirst
  13. Dates.tolast
  14. Dates.tonext(::Function, ::Dates.TimeType)
  15. Dates.toprev(::Function, ::Dates.TimeType)

Periods

  1. Dates.Period(::Any)
  2. Dates.CompoundPeriod(::Vector{<:Dates.Period})
  3. Dates.value
  4. Dates.default
  5. Dates.periods

Rounding Functions

Date and DateTime values can be rounded to a specified resolution (e.g., 1 month or 15 minutes) with floor, ceil, or round.

  1. Base.floor(::Dates.TimeType, ::Dates.Period)
  2. Base.ceil(::Dates.TimeType, ::Dates.Period)
  3. Base.round(::Dates.TimeType, ::Dates.Period, ::RoundingMode{:NearestTiesUp})

Most Period values can also be rounded to a specified resolution:

  1. Base.floor(::Dates.ConvertiblePeriod, ::T) where T <: Dates.ConvertiblePeriod
  2. Base.ceil(::Dates.ConvertiblePeriod, ::Dates.ConvertiblePeriod)
  3. Base.round(::Dates.ConvertiblePeriod, ::Dates.ConvertiblePeriod, ::RoundingMode{:NearestTiesUp})

The following functions are not exported:

  1. Dates.floorceil
  2. Dates.epochdays2date
  3. Dates.epochms2datetime
  4. Dates.date2epochdays
  5. Dates.datetime2epochms

Conversion Functions

  1. Dates.today
  2. Dates.unix2datetime
  3. Dates.datetime2unix
  4. Dates.julian2datetime
  5. Dates.datetime2julian
  6. Dates.rata2datetime
  7. Dates.datetime2rata

Constants

Days of the Week:

Variable Abbr. Value (Int)
Monday Mon 1
Tuesday Tue 2
Wednesday Wed 3
Thursday Thu 4
Friday Fri 5
Saturday Sat 6
Sunday Sun 7

Months of the Year:

Variable Abbr. Value (Int)
January Jan 1
February Feb 2
March Mar 3
April Apr 4
May May 5
June Jun 6
July Jul 7
August Aug 8
September Sep 9
October Oct 10
November Nov 11
December Dec 12

Common Date Formatters

  1. ISODateTimeFormat
  2. ISODateFormat
  3. ISOTimeFormat
  4. RFC1123Format
  1. DocTestSetup = nothing