Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The new calendar types in Elixir 1.3

lau
September 02, 2016

The new calendar types in Elixir 1.3

Elixir 1.3 adds new built-in types for date and time.

Hear about the considerations behind them and how they can improve the quality of your data and software.

When should you use a NaiveDateTime instead of a DateTime? Find out the what best practices are for all the new types. Be it with Ecto, with Phoenix or in Elixir in general.

lau

September 02, 2016
Tweet

Other Decks in Technology

Transcript

  1. Lau Taarnskov Software developer Open source contributor. Creator of Calendar

    for Elixir and tzdata Blog: creativedeletion.com Twitter: @laut Github: lau
  2. Lau Taarnskov - twitter: @LauT iex(1)> 5/2 2.5 iex(2)> 5/"Orlando"

    ** (ArithmeticError) bad argument in arithmetic expression :erlang./(5, "Orlando")
  3. Lau Taarnskov - twitter: @LauT Mars Climate Orbiter Mission cost:

    $327.6 million Mission failure after a 286 day journey to Mars
  4. Lau Taarnskov - twitter: @LauT {5, :lbs_s}, {6, :lbs_s}, {3,

    :lbs_s}, {9, :lbs_s}, {4, :lbs_s}, {5, :lbs_s}…
  5. Lau Taarnskov - twitter: @LauT def process_thruster_data(%{amount: amount, unit: :n_s})

    do # ... end ** (FunctionClauseError) no function clause matching in ThrustProcessor.process_thruster_data/1 thruster.ex:12: ThrustProcessor.process_thruster_data(%ThrusterData{amou nt: 3, unit: :lbs_s}) thruster.ex:17: (file) (elixir) lib/code.ex:363: Code.require_file/2
  6. Lau Taarnskov - twitter: @LauT 2016 2016 September 2016 September

    2nd 2016 September 2nd at 14:01:03 2016-09-02 at 14:01:03 in New York 14:01 14:01:03 14:01:03.9472 ….
  7. Lau Taarnskov - twitter: @LauT Year Year with month Year,

    month, day of month Hour Hour and minute Hour and minute and second …
  8. Lau Taarnskov - twitter: @LauT Types in Calendar in 2014

    Calendar.Date Calendar.Time Calendar.NaiveDateTime Calendar.DateTime
  9. Lau Taarnskov - twitter: @LauT DateTime: year, month, day, hour,

    minute, second, microsecond, time zone, UTC offset, standard offset, zone abbreviation
  10. Lau Taarnskov - twitter: @LauT JAVA 8 Class LocalDate A

    date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.
  11. Lau Taarnskov - twitter: @LauT local |ˈlōk(ə)l| adjective belonging or

    relating to a particular area or neighborhood, typically exclusively so: researching local history | the local post office.
  12. Lau Taarnskov - twitter: @LauT ~N[1970-01-01 00:00:00] |> DateTime.to_unix **

    (FunctionClauseError) no function clause matching in DateTime.to_unix/2 (elixir) lib/calendar.ex:1078: DateTime.to_unix(~N[1970-01-01 00:00:00], :seconds)
  13. Lau Taarnskov - twitter: @LauT Types in Calendar in 2014

    Types in Elixir 1.3 in 2016 Calendar.Date Date Calendar.Time Time Calendar.NaiveDateTime NaiveDateTime Calendar.DateTime DateTime
  14. Lau Taarnskov - twitter: @LauT "2016-09-02 14:15:00.1234” |> NaiveDateTime.from_iso8601! ~N[2016-09-02

    14:15:00.1234] "2016-09-02 14:15:00.1” |> NaiveDateTime.from_iso8601! ~N[2016-09-02 14:15:00.1] Significant fractional seconds
  15. Lau Taarnskov - twitter: @LauT "2016-09-02 14:15:00.1234” |> NaiveDateTime.from_iso8601! |>

    Map.get(:microsecond) {123400, 4} "2016-09-02 14:15:00.10” |> NaiveDateTime.from_iso8601! |> Map.get(:microsecond) {100000, 2} "2016-09-02 14:15:00” |> NaiveDateTime.from_iso8601! |> Map.get(:microsecond) {0, 0} Significant fractional seconds
  16. Lau Taarnskov - twitter: @LauT DateTime.from_unix!(1472836167) %DateTime{calendar: Calendar.ISO, day: 2,

    hour: 17, microsecond: {0, 0}, minute: 9, month: 9, second: 27, std_offset: 0, time_zone: "Etc/UTC", utc_offset: 0, year: 2016, zone_abbr: "UTC"}
  17. Lau Taarnskov - twitter: @LauT DateTime.from_unix!(1472836167) |> Calendar.DateTime.shift_zone!("America/New_York") %DateTime{calendar: Calendar.ISO,

    day: 2, hour: 13, microsecond: {0, 0}, minute: 9, month: 9, second: 27, std_offset: 3600, time_zone: "America/New_York", utc_offset: -18000, year: 2016, zone_abbr: "EDT"}