defmodule Cldr.DateTime do @moduledoc """ Provides localization and formatting of a `DateTime` struct or any map with the keys `:year`, `:month`, `:day`, `:calendar`, `:hour`, `:minute`, `:second` and optionally `:microsecond`. `Cldr.DateTime` provides support for the built-in calendar `Calendar.ISO` or any calendars defined with [ex_cldr_calendars](https://hex.pm/packages/ex_cldr_calendars) CLDR provides standard format strings for `DateTime` which are reresented by the names `:short`, `:medium`, `:long` and `:full`. This allows for locale-independent formatting since each locale will define the underlying format string as appropriate. """ alias Cldr.DateTime.Format alias Cldr.LanguageTag @format_types [:short, :medium, :long, :full] @default_type :medium @default_style :default defmodule Formats do @moduledoc false defstruct Module.get_attribute(Cldr.DateTime, :format_types) end @doc """ Formats a DateTime according to a format string as defined in CLDR and described in [TR35](http://unicode.org/reports/tr35/tr35-dates.html) ## Arguments * `datetime` is a `%DateTime{}` `or %NaiveDateTime{}`struct or any map that contains the keys `:year`, `:month`, `:day`, `:calendar`. `:hour`, `:minute` and `:second` with optional `:microsecond`. * `backend` is any module that includes `use Cldr` and therefore is a `Cldr` backend module. The default is `Cldr.default_backend/0`. * `options` is a keyword list of options for formatting. ## Options * `:format` is one of `:short`, `:medium`, `:long`, `:full` or a format string or any of the keys returned by `Cldr.DateTime.Format.date_time_available_formats/0`. The default is `:medium`. * `:date_format` is any one of `:short`, `:medium`, `:long`, `:full`. If defined, this option is used to format the date part of the date time. This option is only acceptable if the `:format` option is not specified, or is specified as either `:short`, `:medium`, `:long`, `:full`. If `:date_format` is not specified then the date format is defined by the `:format` option. * `:time_format` is any one of `:short`, `:medium`, `:long`, `:full`. If defined, this option is used to format the time part of the date time. This option is only acceptable if the `:format` option is not specified, or is specified as either `:short`, `:medium`, `:long`, `:full`. If `:time_format` is not specified then the time format is defined by the `:format` option. * `:style` is either `:at` or `:default`. When set to `:at` the datetime is formatted with a localised string representing ` at