Skip to content
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

readable_datetime does not support week #933

Open
BarishNamazov opened this issue Oct 14, 2022 · 4 comments
Open

readable_datetime does not support week #933

BarishNamazov opened this issue Oct 14, 2022 · 4 comments

Comments

@BarishNamazov
Copy link
Contributor

readable_datetime(date, precision?) does not support precision='week'. Internationalization makes this particularly hard to solve (different locales use different start of week, too). I think in any case, weeks are full Monday to Sunday, so something like 10/10/2022-10/17/2022 would be an option (or Oct 10 2022 - Oct 17 2022).

@LeaVerou
Copy link
Member

@DmitrySharabin since this is i18n related, do you have any thoughts?

@DmitrySharabin
Copy link
Member

Since I personally never needed this precision in my apps, I had to research a bit to see what we already have in browser for now to be ready to give a meaningful answer (I hope). 😊

AFAIK, we already have <input type="week" /> for picking weeks (even though it's not fully supported yet).

The corresponding widget has the translation of the word “week” depending on the user's locale set in the OS (I guess).

SCR-20221017-jhf

SCR-20221017-jgn

The value returned by the picker is consistent and looks something like 2022-W42.

So for readable_datetime("2022-10-17", "week") I would expect to see Week 42, 2022 (or Неделя 42, 2022, depending on the user's locale), since I've already seen something similar in the browser.

However, I'm not sure whether it's possible to obtain the translation of the word “week” to format the output this way, since Intl.DateTimeFormat() doesn't have the week value for the dateStyle option. I think, in that case (if we follow this path), we would need to use the Mavo localization system by introducing a new localization string—week.

I think in any case, weeks are full Monday to Sunday, so something like 10/10/2022-10/17/2022 would be an option (or Oct 10 2022 - Oct 17 2022).

I'm not quite sure about this approach. As @BarishNamazov mentioned, different locales use different start of week. So, this week is 17 Oct 2022 — 23 Oct 2022 for me, but 16 Oct 2022 — 22 Oct 2022, for example, for Greek people (@LeaVerou, please correct me if I'm wrong). If the author needs something like this (as a readable form for the current week), they can do this, for example: [readable_datetime($today, "day")] — [readable_datetime($today + 6*days(), "day")] (if $today is the first day of the week).

Btw, I think (for the sake of consistency) we should also support:

Date components

  • week("2022-01-05") which is equal to 1 and week("2022-10-17") --> 42

Date component formatting

  • week("2022-10-17", "full") --> 2022-W42
  • week("2022-10-17", "short") --> W42
  • week("2022-10-17", "numeric") --> 42 (we might also support week("2022-01-05", "00") to get 01)

datetime()

  • datetime("2022-10-17 15:26:34", "week") --> 2022-W42

Not sure about the API though. I just tried to re-use the one we already have.

Oh, and one more thing. Why don't we add precision="quarter" as well? 🤔

@LeaVerou
Copy link
Member

Thank you for the research @DmitrySharabin!

Regardless of localizing the word "week", I do think ranges are more understandable than a week index. Offhand, do you know when Week 42 is? I have no idea!

Knowing the start of a week for a given locale is an open issue for Intl. However, I think even if it's off by one day (for locales where the week starts on Sunday), outputting a range is still far more understandable than a week index. We can always switch to a locale-sensitive week start when that information is available. I also think that for some locales the i18n information doesn't actually match common practice. E.g. you said in Greece weeks start on Sunday? Maybe theoretically (after all, the Greek word for Monday literally means "Second day"), but I don't know anybody that actually treats Sundays as the start of weeks. Colloquially it's always Monday. I wonder how many of these other locales that have different starts of weeks officially are like this.

Instead of outputting two entire dates for a range, I think we should have a readable_datetime_range() function that takes two dates and outputs ranges like "12 - 23 Oct 2022", "23 Oct - 11 Nov 2022", "13 Jun 1986 - 13 Jun 1987" etc. It should probably accept the same precision arguments as readable_datetime().

I agree we should have a week() function that returns the actual week index. This also makes it trivial for someone that actually wants the "Week N" format to use it, by supplying their own word for "week".

We should definitely also make sure our datetime stuff doesn't choke on week date formats like 2022-W42.

@HarshPanchal26
Copy link

Hey I am new to open Source , If do you need any help just let me know , I can help with this .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants