Skip to content

Commit

Permalink
Add tests for 'at' formats
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jul 7, 2024
1 parent 594dc76 commit 0aee17d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/cldr/backend/date_time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ defmodule Cldr.DateAndTime.Backend do
`: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 `<date> at <time>`. See
`Cldr.DateTime.Format.date_time_at_formats/2`.
* `:style` is either `:at` or `:default`. When set to `:at` the datetime may
be formatted with a localised string representing `<date> at <time>` if such
a format exists. See `Cldr.DateTime.Format.date_time_at_formats/2`.
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of
formats have two variants - one using Unicode spaces (typically non-breaking space) and
Expand Down Expand Up @@ -124,9 +124,9 @@ defmodule Cldr.DateAndTime.Backend do
`: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 `<date> at <time>`. See
`Cldr.DateTime.Format.date_time_at_formats/2`.
* `:style` is either `:at` or `:default`. When set to `:at` the datetime may
be formatted with a localised string representing `<date> at <time>` if such
a format exists. See `Cldr.DateTime.Format.date_time_at_formats/2`.
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of
formats have two variants - one using Unicode spaces (typically non-breaking space) and
Expand All @@ -152,7 +152,7 @@ defmodule Cldr.DateAndTime.Backend do
* `formatted_datetime` or
* raises an exception
* raises an exception.
## Examples
Expand Down
12 changes: 6 additions & 6 deletions lib/cldr/date_time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ defmodule Cldr.DateTime do
`: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 `<date> at <time>`. See
`Cldr.DateTime.Format.date_time_at_formats/2`.
* `:style` is either `:at` or `:default`. When set to `:at` the datetime may
be formatted with a localised string representing `<date> at <time>` if such
a format exists. See `Cldr.DateTime.Format.date_time_at_formats/2`.
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of
formats have two variants - one using Unicode spaces (typically non-breaking space) and
Expand Down Expand Up @@ -252,9 +252,9 @@ defmodule Cldr.DateTime do
any of the keys returned by `Cldr.DateTime.Format.date_time_formats/3`.
The default is `:medium`.
* `:style` is either `:at` or `:default`. When set to `:at` the datetime is
formatted with a localised string representing `<date> at <time>`. See
`Cldr.DateTime.Format.date_time_at_formats/2`.
* `:style` is either `:at` or `:default`. When set to `:at` the datetime may
be formatted with a localised string representing `<date> at <time>` if such
a format exists. See `Cldr.DateTime.Format.date_time_at_formats/2`.
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of datetime
formats have two variants - one using Unicode spaces (typically non-breaking space) and
Expand Down
27 changes: 27 additions & 0 deletions test/cldr_dates_times_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,31 @@ defmodule Cldr.DatesTimes.Test do
":date_format and :time_format cannot be specified if :format is also specified as a " <>
"format id or a format string. Found [time_format: :medium, date_format: :short]"}}
end

test "Pluralized formats" do
datetime = ~U[2024-07-07 21:36:00.440105Z]

assert {:ok, "week 28 of 2024"} = Cldr.DateTime.to_string(~D[2024-07-08], format: :yw)
assert {:ok, "week 2 of July"} = Cldr.DateTime.to_string(~D[2024-07-08], format: :MMMMW)
assert {:ok, "8:11 AM"} = Cldr.DateTime.to_string(~T[08:11:02], format: :hm)
assert {:ok, "Sun 9:36 PM"} = Cldr.DateTime.to_string(datetime, format: :Ehm)
end

test "Unicode or ASCII preference" do
datetime = ~U[2024-07-07 21:36:00.440105Z]

unicode = Cldr.DateTime.to_string(datetime, format: :Ehm, prefer: :unicode)
ascii = Cldr.DateTime.to_string(datetime, format: :Ehm, prefer: :ascii)
assert unicode != ascii
end

test "'at' formats" do
datetime = ~U[2024-07-07 21:36:00.440105Z]

assert {:ok, "July 7, 2024 at 9:36:00 PM UTC"} =
Cldr.DateTime.to_string(datetime, format: :long, style: :at)

assert {:ok, "July 7, 2024, 9:36:00 PM UTC"} =
Cldr.DateTime.to_string(datetime, format: :long, style: :default)
end
end

0 comments on commit 0aee17d

Please sign in to comment.