Skip to content

Commit

Permalink
Fix formatting am/pm with format :narrow or :wide. Closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jul 1, 2024
1 parent a67e8bb commit b6f13bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

**Note that `ex_cldr_dates_times` version 2.18.0 and later are supported on Elixir 1.12 and later only.**

## Cldr_Dates_Times v2.18.1

This is the changelog for Cldr_Dates_Times v2.18.1 released on July 1st, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags)

### Bug Fixes

* Fix formatting `am/pm` with format `:narrow` or `:wide`. Thanks to @sysashi for the report. Closes #48.

## Cldr_Dates_Times v2.18.0

This is the changelog for Cldr_Dates_Times v2.18.0 released on May 29th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags)
Expand Down
8 changes: 8 additions & 0 deletions lib/cldr/format/date_time_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,9 @@ defmodule Cldr.DateTime.Formatter do
iex> Cldr.DateTime.Formatter.period_am_pm %{hour: 21, minute: 0}
"PM"
iex> Cldr.DateTime.Formatter.period_am_pm %{hour: 21, minute: 0}, 5
"p"
"""
@spec period_am_pm(Calendar.time(), integer, Keyword.t()) ::
String.t() | {:error, String.t()}
Expand All @@ -1904,6 +1907,11 @@ defmodule Cldr.DateTime.Formatter do

def period_am_pm(time, n, locale, backend, options \\ %{})

def period_am_pm(%{calendar: Calendar.ISO} = time, n, locale, backend, options) do
%{time | calendar: Cldr.Calendar.Gregorian}
|> period_am_pm(n, locale, backend, options)
end

def period_am_pm(time, n, locale, backend, options) when n in 1..3 do
time
|> Cldr.Calendar.localize(:am_pm, :format, :abbreviated, backend, locale)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.DatesTimes.Mixfile do
use Mix.Project

@version "2.18.0"
@version "2.18.1"

def project do
[
Expand Down

0 comments on commit b6f13bf

Please sign in to comment.