-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Calendar with Sunday as first day of week #4
Comments
@dbernheisel thanks for the issue. I need to think on this a little but I can clarify one thing: There's one bug I will fix, one question I have and one suggestion: :-)
# With year and week
iex> Cldr.Calendar.Interval.week 2020, 1, MyApp.Calendar.US
#DateRange<~D[2020-01-05 MyApp.Calendar.US], ~D[2020-01-11 MyApp.Calendar.US]>
iex> Cldr.Calendar.day_of_week ~D[2020-01-05 MyApp.Calendar.US]
7
# With a date
iex> Cldr.Calendar.Interval.week ~D[2020-04-05 MyApp.Calendar.US]
#DateRange<~D[2020-04-05 MyApp.Calendar.US], ~D[2020-04-11 MyApp.Calendar.US]>
iex> Cldr.Calendar.day_of_week ~D[2020-04-05 MyApp.Calendar.US]
7
An example of output for April 2020 with your calendar: April 2020
|
Ah perfect that's what I was essentially looking for, but building my own HTML formatter without Here's what I have right now: # ./config/config.exs
config :ex_cldr,
default_backend: MyAppWeb.Cldr,
default_locale: "en",
json_library: Jason
# ./lib/my_app_web/cldr.ex
defmodule MyAppWeb.Cldr do
use Cldr,
otp_app: :my_app,
gettext: MyAppWeb.Gettext,
providers: [Cldr.Calendar, Cldr.DateTime, Cldr.Number, Cldr.Unit, Cldr.List, Cldr.Territory]
end
# ./lib/my_app_web/cldr_calendars.ex
defmodule MyAppWeb.Calendar.US do
@moduledoc """
This is the same as a regular Calendar, but with Sunday starting the week.
"""
use Cldr.Calendar.Base.Month,
month_of_year: 1,
min_days_in_first_week: 1,
day_of_week: Cldr.Calendar.sunday(),
cldr_backend: MyAppWeb.Cldr
end
# Usage in iex to test
iex> date = ~D[2020-04-05 MyAppWeb.Calendar.US]
~D[2020-04-05 MyAppWeb.Calendar.US]
iex> Cldr.Calendar.localize(date, :days_of_week)
[
{7, "Sun"},
{1, "Mon"},
{2, "Tue"},
{3, "Wed"},
{4, "Thu"},
{5, "Fri"},
{6, "Sat"}
]
iex> Date.day_of_week(date)
7 But I think Looking at I'm essentially trying to build what you have in your example from the ex_cldr_calendars_format above, but I'm currently using But-- now knowing about |
I'd be very happy to collaborate on improving
Any and all calendars that are based on the Gregorian calendar (which is most but not all of them) delegate to I think its cleaner to use |
Let me know too if you are looking to put events on a calendar. I don't have that functionality but I'm definitely interested to implement it. You would pass a map of |
Aha thanks it's my misunderstanding between "ordinal day of week" vs "day of week". Yes I'm developing a mechanism for displaying events on a calendar; I'd love to contribute upstream to ex_cldr_calendar_format after I find some good patterns. I'll close since you've fully answered the question, and then some! |
I have opened an issue on |
And on a final note ..... as of this commit In addition, the correct defaults for |
This may be more of a "how to use" question than an issue.
In the US, the default calendar starts with the first day of the week as Sunday. How do I use ex_cldr and ex_cldr_calendars to localize the calendar for US users to have the day of the week reflected with Sunday = 1?
The supplemental CLDR data for the territory US has a preference for this, but I'm not sure that's being used or parsed. Since it's territory-specific, I'm not sure if this belongs here or in ex_cldr_territories
https://unicode.org/cldr/charts/latest/supplemental/territory_information.html#US
http://demo.icu-project.org/icu-bin/locexp?d_=en&_=en_US
Ultimately, I'd like to be able to put a locale in as "en-Latn-US", and have the preferred calendar become something like
Cldr.Calendar.EnLatnUS
, or a way to provide a mapping of locales to pre-defined calenadrs (defined either by Cldr or by the application).The closest I can get so far is ordering Sunday first in the list, but the day_of_week still reflects 7 as Sunday instead of 1.
I see that this is straight from the Cldr data; so the missing link (I'm assuming) is the supplemental data.
The text was updated successfully, but these errors were encountered: