Skip to content
Jacob Quinn edited this page Jul 26, 2013 · 15 revisions

From the beginning, Julia has had a problem with being greedy. This same greed has driven the development of the Datetime package. With roots in Joda/JS-310, numpy datetime64, lubridate, zoo, and runt, the Datetime package aims to greedily provide a datetime implementation that is not only top in efficiency and performance, but that also contains a full range of types and methods for working with dates, times, periods, and time series of any flavor. Dates and times are notoriously tricky to work with, so Datetime strives for accuracy, clarity, and simplicity. We also realize we're far from perfect, so tire-kicking, feature requests, and bug reports are heartily welcomed and appreciated!

Wiki Content
  • Abstract Types
  • Period Types
  • TimeTypes
  • Date
  • DateTime
  • TimeType Ranges

Calendars/Type Parameters

Following Joda-time's idea of pluggable chronologies, Datetime defines Calendar, an abstract type that can be subtyped for specific calendar implementations and that all Period/TimeTypes take as a parameter. Datetime defines a default Calendar with abstract ISOCalendar <: Calendar which follows ISO 8601 standards. Using Calendar as a type and method parameter is a core principle of the Datetime package; it not only leverages Julia's multiple dispatch for Calendar-specific methods, but also allows for extremely efficient Date, DateTime, and Period types that don't need to store a certain Calendar value/pointer, but simply wrap 32 and 64-bit integers (yep, 4 and 8 bytes!)[1]. The same approach is taken for the abstract types, Offset{n} and TimeZone, which are additional parameters for DateTimes; thus, PST (Pacific Standard Time) is a subtype of TimeZone that DateTime can take as a parameter upon creation and is used in calculating the appropriate offset when showing its value. Let's see some of these in action:

julia> y = year(1)
1 year

julia> typeof(y)
Year{ISOCalendar}

julia> dt = today()
2013-07-26

julia> typeof(dt)
Date{ISOCalendar}

julia> calendar(dt)
ISOCalendar

julia> typeof(calendar(dt))
DataType

julia> super(calendar(dt))
Calendar

julia> dt2 = now(CST)
2013-07-25T23:08:12 CDT

julia> typeof(dt2)
DateTime{ISOCalendar,Zone382}

Zone382 represents the "America/Chicago" or Central Standard Time timezone (for those interested 382 comes directly from the universally used Olson timezone database).

[1]: R = 520 bytes, Python date, datetime classes = 32, 48 bytes, Joda-time = 24-40 bytes,

Period Types

TimeTypes

Datetime currently provides two TimeTypes: Date and DateTime, representing different levels of "precision". The motivation for distinct types is simple, some operations are much simpler, both in terms of code and mental reasoning, when the complexities of greater precision don't have to be dealt with. For example, the Date type has a "day-precision" (i.e. no hours, minutes, or seconds), which means that normal gotchas with time zones, daylight savings/summer time, or leap seconds are nonexistent.

Date
DateTime

TimeType Ranges

Clone this wiki locally