Skip to content

Commit 1a05fd1

Browse files
committed
Update :prefer docs
1 parent 58ca64f commit 1a05fd1

19 files changed

+510
-129
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

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

5-
## Cldr_Dates_Times v2.19.3
5+
## Cldr_Dates_Times v2.20.0
66

7-
This is the changelog for Cldr_Dates_Times v2.19.3 released on _____, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags)
7+
This is the changelog for Cldr_Dates_Times v2.20.0 released on July 26th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags)
88

99
### Bug Fixes
1010

1111
* Fix `Cldr.Time.available_formats/3` when the locale parameter is a binary.
1212

1313
### Enhancements
1414

15-
* Modify the `:prefer` option of `to_string/2` to take a list of preferences. Time formats may sometimes have a `:unicode` or `:ascii` preference. Date formats may have a `:default` or `:variant` preference. The `:prefer` option can no be specified with one or both of these options.
15+
* Modify the `:prefer` option of `to_string/2` to take a list of preferences. Time formats may sometimes have a `:unicode` or `:ascii` preference. Date and datetime formats may have a `:default` or `:variant` preference. The `:prefer` option can now be specified with one or both of these options.
1616

1717
## Cldr_Dates_Times v2.19.2
1818

lib/cldr/backend/formatter.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Cldr.DateTime.Formatter.Backend do
3434
* `format` is a valid format string, for example `yy/MM/dd hh:MM`
3535
3636
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
37-
or a `Cldr.LanguageTag` struct. The default is `Cldr.get_locale/0`
37+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `Cldr.get_locale/0`
3838
3939
* `options` is a keyword list of options.
4040

lib/cldr/backend/interval.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule Cldr.Interval.Backend do
7373
for each of the date and time part is used
7474
7575
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
76-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
76+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
7777
7878
* `number_system:` a number system into which the formatted date digits should
7979
be transliterated
@@ -184,7 +184,7 @@ defmodule Cldr.Interval.Backend do
184184
for each of the date and time part is used
185185
186186
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
187-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
187+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
188188
189189
* `number_system:` a number system into which the formatted date digits should
190190
be transliterated.
@@ -315,7 +315,7 @@ defmodule Cldr.Interval.Backend do
315315
for each of the date and time part is used.
316316
317317
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
318-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
318+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
319319
320320
* `number_system:` a number system into which the formatted date digits should
321321
be transliterated.
@@ -427,7 +427,7 @@ defmodule Cldr.Interval.Backend do
427427
for each of the date and time part is used.
428428
429429
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
430-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
430+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
431431
432432
* `number_system:` a number system into which the formatted date digits should
433433
be transliterated.

lib/cldr/backend/interval/date.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defmodule Cldr.Date.Interval.Backend do
6262
and `:year_and_month`. The default is `:date`.
6363
6464
* `:locale` is any valid locale name returned by `Cldr.known_locale_names/0`
65-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
65+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
6666
6767
* `:number_system` a number system into which the formatted date digits should
6868
be transliterated
@@ -176,7 +176,7 @@ defmodule Cldr.Date.Interval.Backend do
176176
and `:year_and_month`. The default is `:date`.
177177
178178
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
179-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
179+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
180180
181181
* `number_system:` a number system into which the formatted date digits should
182182
be transliterated
@@ -281,7 +281,7 @@ defmodule Cldr.Date.Interval.Backend do
281281
and `:year_and_month`. The default is `:date`.
282282
283283
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
284-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
284+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
285285
286286
* `number_system:` a number system into which the formatted date digits should
287287
be transliterated
@@ -392,7 +392,7 @@ defmodule Cldr.Date.Interval.Backend do
392392
and `:year_and_month`. The default is `:date`.
393393
394394
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
395-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
395+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
396396
397397
* `number_system:` a number system into which the formatted date digits should
398398
be transliterated.

lib/cldr/backend/interval/date_time.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ defmodule Cldr.DateTime.Interval.Backend do
5656
format. The default is `:medium`.
5757
5858
* `:locale` is any valid locale name returned by `Cldr.known_locale_names/0`
59-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
59+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
6060
6161
* `:number_system` a number system into which the formatted datetime
6262
digits should be transliterated
@@ -129,7 +129,7 @@ defmodule Cldr.DateTime.Interval.Backend do
129129
format. The default is `:medium`.
130130
131131
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
132-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
132+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
133133
134134
* `number_system:` a number system into which the formatted date digits should
135135
be transliterated
@@ -219,7 +219,7 @@ defmodule Cldr.DateTime.Interval.Backend do
219219
format. The default is `:medium`.
220220
221221
* `:locale` is any valid locale name returned by `Cldr.known_locale_names/0`
222-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`
222+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`
223223
224224
* `:number_system` a number system into which the formatted datetime
225225
digits should be transliterated
@@ -293,7 +293,7 @@ defmodule Cldr.DateTime.Interval.Backend do
293293
format. The default is `:medium`.
294294
295295
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
296-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
296+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
297297
298298
* `number_system:` a number system into which the formatted date digits should
299299
be transliterated.

lib/cldr/backend/interval/time.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defmodule Cldr.Time.Interval.Backend do
5353
and `:flex`. The default is `:time`.
5454
5555
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
56-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
56+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
5757
5858
* `number_system:` a number system into which the formatted date digits should
5959
be transliterated.
@@ -163,7 +163,7 @@ defmodule Cldr.Time.Interval.Backend do
163163
and `:flex`. The default is `:time`.
164164
165165
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
166-
or a `Cldr.LanguageTag` struct. The default is `#{backend}.get_locale/0`.
166+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `#{backend}.get_locale/0`.
167167
168168
* `number_system:` a number system into which the formatted date digits should
169169
be transliterated.

lib/cldr/date.ex

+49-13
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,35 @@ defmodule Cldr.Date do
7474
* `:number_system` a number system into which the formatted date digits
7575
should be transliterated.
7676
77-
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of
78-
formats have two variants - one using Unicode spaces (typically non-breaking space) and
79-
another using only ASCII whitespace. The `:ascii` format is primarily to support legacy
80-
use cases and is not recommended. See `Cldr.Date.available_formats/3`
81-
to see which formats have these variants. Currently no date-specific
82-
formats have such variants but they may in the future.
77+
* `:prefer` expresses the preference for one of the possible alternative
78+
sub-formats. See the variant preference notes below.
8379
8480
* `:era` which, if set to `:variant`, will use a variant for the era if one
8581
is available in the requested locale. In the `:en` locale, for example, `era: :variant`
8682
will return `CE` instead of `AD` and `BCE` instead of `BC`.
8783
84+
### Variant Preference
85+
86+
* A small number of formats have one of two different alternatives, each with their own
87+
preference specifier. The preferences are specified with the `:prefer` option to
88+
`Cldr.Date.to_string/3`. The preference is expressed as an atom, or a list of one or two
89+
atoms with one atom being either `:unicode` or `:ascii` and one atom being either
90+
`:default` or `:variant`.
91+
92+
* Some formats (at the time of publishng only time formats but that
93+
may change in the future) have `:unicode` and `:ascii` versions of the format. The
94+
difference is the use of ascii space (0x20) as a separateor in the `:ascii` verison
95+
whereas the `:unicode` version may use non-breaking or other space characters. The
96+
default is `:unicode` and this is the strongly preferred option. The `:ascii` format
97+
is primarily to support legacy use cases and is not recommended. See
98+
`Cldr.Date.available_formats/3` to see which formats have these variants.
99+
100+
* Some formats (at the time of publishing, only date and datetime formats) have
101+
`:default` and `:variant` versions of the format. These variant formats are only
102+
included in a small number of locales. For example, the `:"en-CA"` locale, which has
103+
a `:default` format respecting typical Canadian formatting and a `:variant` that is
104+
more closely aligned to US formatting. The default is `:default`.
105+
88106
### Returns
89107
90108
* `{:ok, formatted_string}` or
@@ -201,22 +219,40 @@ defmodule Cldr.Date do
201219
for more information about specifying formats.
202220
203221
* `:locale` is any valid locale name returned by `Cldr.known_locale_names/0`
204-
or a `Cldr.LanguageTag` struct. The default is `Cldr.get_locale/0`.
222+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `Cldr.get_locale/0`.
205223
206224
* `:number_system` a number system into which the formatted date digits should
207225
be transliterated.
208226
209-
* `:prefer` is either `:unicode` (the default) or `:ascii`. A small number of
210-
formats have two variants - one using Unicode spaces (typically non-breaking space) and
211-
another using only ASCII whitespace. The `:ascii` format is primarily to support legacy
212-
use cases and is not recommended. See `Cldr.Date.available_formats/3`
213-
to see which formats have these variants. Currently no date-specific
214-
formats have such variants but they may in the future.
227+
* `:prefer` expresses the preference for one of the possible alternative
228+
sub-formats. See the variant preference notes below.
215229
216230
* `:era` which, if set to `:variant`, will use a variant for the era if one
217231
is available in the requested locale. In the `:en` locale, for example, `era: :variant`
218232
will return `CE` instead of `AD` and `BCE` instead of `BC`.
219233
234+
### Variant Preference
235+
236+
* A small number of formats have one of two different alternatives, each with their own
237+
preference specifier. The preferences are specified with the `:prefer` option to
238+
`Cldr.Date.to_string/3`. The preference is expressed as an atom, or a list of one or two
239+
atoms with one atom being either `:unicode` or `:ascii` and one atom being either
240+
`:default` or `:variant`.
241+
242+
* Some formats (at the time of publishng only time formats but that
243+
may change in the future) have `:unicode` and `:ascii` versions of the format. The
244+
difference is the use of ascii space (0x20) as a separateor in the `:ascii` verison
245+
whereas the `:unicode` version may use non-breaking or other space characters. The
246+
default is `:unicode` and this is the strongly preferred option. The `:ascii` format
247+
is primarily to support legacy use cases and is not recommended. See
248+
`Cldr.Date.available_formats/3` to see which formats have these variants.
249+
250+
* Some formats (at the time of publishing, only date and datetime formats) have
251+
`:default` and `:variant` versions of the format. These variant formats are only
252+
included in a small number of locales. For example, the `:"en-CA"` locale, which has
253+
a `:default` format respecting typical Canadian formatting and a `:variant` that is
254+
more closely aligned to US formatting. The default is `:default`.
255+
220256
### Returns
221257
222258
* `formatted_date` or

lib/cldr/date_time.ex

+44
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ defmodule Cldr.DateTime do
148148
one is available in the locale. For example, in the `:en` locale `period: :variant` will
149149
return "pm" instead of "PM".
150150
151+
### Variant Preference
152+
153+
* A small number of formats have one of two different alternatives, each with their own
154+
preference specifier. The preferences are specified with the `:prefer` option to
155+
`Cldr.Date.to_string/3`. The preference is expressed as an atom, or a list of one or two
156+
atoms with one atom being either `:unicode` or `:ascii` and one atom being either
157+
`:default` or `:variant`.
158+
159+
* Some formats (at the time of publishng only time formats but that
160+
may change in the future) have `:unicode` and `:ascii` versions of the format. The
161+
difference is the use of ascii space (0x20) as a separateor in the `:ascii` verison
162+
whereas the `:unicode` version may use non-breaking or other space characters. The
163+
default is `:unicode` and this is the strongly preferred option. The `:ascii` format
164+
is primarily to support legacy use cases and is not recommended. See
165+
`Cldr.Time.available_formats/3` to see which formats have these variants.
166+
167+
* Some formats (at the time of publishing, only date and datetime formats) have
168+
`:default` and `:variant` versions of the format. These variant formats are only
169+
included in a small number of locales. For example, the `:"en-CA"` locale, which has
170+
a `:default` format respecting typical Canadian formatting and a `:variant` that is
171+
more closely aligned to US formatting. The default is `:default`.
172+
151173
### Notes
152174
153175
* If the provided `datetime` contains only date fields, the call is delegated to
@@ -290,6 +312,28 @@ defmodule Cldr.DateTime do
290312
one is available in the locale. For example, in the `:en` locale `period: :variant` will
291313
return "pm" instead of "PM".
292314
315+
### Variant Preference
316+
317+
* A small number of formats have one of two different alternatives, each with their own
318+
preference specifier. The preferences are specified with the `:prefer` option to
319+
`Cldr.Date.to_string/3`. The preference is expressed as an atom, or a list of one or two
320+
atoms with one atom being either `:unicode` or `:ascii` and one atom being either
321+
`:default` or `:variant`.
322+
323+
* Some formats (at the time of publishng only time formats but that
324+
may change in the future) have `:unicode` and `:ascii` versions of the format. The
325+
difference is the use of ascii space (0x20) as a separateor in the `:ascii` verison
326+
whereas the `:unicode` version may use non-breaking or other space characters. The
327+
default is `:unicode` and this is the strongly preferred option. The `:ascii` format
328+
is primarily to support legacy use cases and is not recommended. See
329+
`Cldr.Time.available_formats/3` to see which formats have these variants.
330+
331+
* Some formats (at the time of publishing, only date and datetime formats) have
332+
`:default` and `:variant` versions of the format. These variant formats are only
333+
included in a small number of locales. For example, the `:"en-CA"` locale, which has
334+
a `:default` format respecting typical Canadian formatting and a `:variant` that is
335+
more closely aligned to US formatting. The default is `:default`.
336+
293337
### Notes
294338
295339
* If the provided `datetime` contains only date fields, the call is delegated to

lib/cldr/format/date_time_format.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ defmodule Cldr.DateTime.Format do
7777
## Arguments
7878
7979
* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
80-
or a `Cldr.LanguageTag` struct. The default is `Cldr.get_locale/0`.
80+
or a `t:Cldr.LanguageTag.t/0` struct. The default is `Cldr.get_locale/0`.
8181
8282
* `backend` is any module that includes `use Cldr` and therefore
8383
is a `Cldr` backend module. The default is `Cldr.default_backend/0`.

0 commit comments

Comments
 (0)