Earlier quoted context omitted.
I agree. I really like how the `time` crate[0] in the rust world handles this[1]. with your example: > format_description!("[year]/[month]/[day]") 0: https://crates.io/crates/time 1: https://time-rs.github.io/book/api/format-description.html
This is easier to read but not descriptive enough since there are different kinds year, month, day. Year can be 2 digits, 4 digits, regular or week year. Month can have leading zero or not, long name, short, name. Day could be Julian, leading zero or not, day of the week, etc
Do not use 'week year': YYYY
31–40 of 94 posts
Re: Do not use 'week year': YYYY
#32Re: Do not use 'week year': YYYY
#33I understand that "week year" is basically a payroll creation, but I am a bit concerned about the last few days of 2021 were logged as 2022, and Jan 1st 2022 was even logged as 2023. The last few days of 2021 logged as 2022 makes sense for payroll, but how the heck is Jan 1st 2022 put in the 2023 year?
Re: Do not use 'week year': YYYY
#34Where can I file a bug report that the class name is wrong "SimpleDateFormat" ;-)
Re: Do not use 'week year': YYYY
#35Earlier quoted context omitted.
> Is it just me for thinking that using format strings instead of some strongly typed interface with verbose names for this is not great? Yes, but it would not have helped with the bug in question. The parallel bug for a strongly typed interface would be "year()" returning this monstrosity, while "iso_year()" or some other poorly named variant returning the expected year. No API is immune to footguns and bad design d…
It's harder to make that bug. The common case is "year of era", so it is likely to be used for "year()". On the other hand the much less often used "year of week" would be named "year_of_week()" and hence it is clear to everyone that's not likely what you want.
That would be the sane thing to do. But the same applies to `YYYY`: it should be used for "year of era". But it hasn't been and that's the problem here. For contrast in moment.js, YYYY and yyyy do what you expect and "week year" is GGGG or gggg.
Re: Do not use 'week year': YYYY
#36Is it just me for thinking that using format strings instead of some strongly typed interface with verbose names for this is not great? I would take `format(year(), '/', month(), '/', day())` over ad-hoc format strings by various APIs. Reading the docs further this also stands out: > For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some cent…
Re: Do not use 'week year': YYYY
#37Is it just me for thinking that using format strings instead of some strongly typed interface with verbose names for this is not great? I would take `format(year(), '/', month(), '/', day())` over ad-hoc format strings by various APIs. Reading the docs further this also stands out: > For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some cent…
When I write code that needs to format in different formats I always create well named, perhaps verbose but I don't care as it's now readable, functions such as this (ignore HN butchering the code):
/\*
\* Formats Date into "twelve hour time". For example, 3:23. This is "h:mm" format from date-fns.
\* @param { Date } date The date.
\* @returns { string } The formatted string.
\*/
export const formatAsTwelveHourTime = (date: Date) => format(date, 'h:mm');Re: Do not use 'week year': YYYY
#38I understand that "week year" is basically a payroll creation, but I am a bit concerned about the last few days of 2021 were logged as 2022, and Jan 1st 2022 was even logged as 2023. The last few days of 2021 logged as 2022 makes sense for payroll, but how the heck is Jan 1st 2022 put in the 2023 year?
> but how the heck is Jan 1st 2022 put in the 2023 year? This only happened shortly after midnight on January 1st. So I guess this is somehow related to different time zones/offsets.
Re: Do not use 'week year': YYYY
#39I understand that "week year" is basically a payroll creation, but I am a bit concerned about the last few days of 2021 were logged as 2022, and Jan 1st 2022 was even logged as 2023. The last few days of 2021 logged as 2022 makes sense for payroll, but how the heck is Jan 1st 2022 put in the 2023 year?
First off, I think you have a typo(?) with the "2023"? Because:
* https://www.epochconverter.com/weeks/2022
The reason(s) why the week system was designed:
> * All weeks have exactly 7 days, i.e. there are no fractional weeks.
> * Every week belongs to a single year, i.e. there are no ambiguous or double-assigned weeks.
> * The date directly tells the weekday.
> * All week-numbering years start with a Monday and end with a Sunday.
> * When used by itself without using the concept of month, all week-numbering years are the same except that some years have a week 53 at the end.
* https://en.wikipedia.org/wiki/ISO_week_date#Advantages
This makes perfect sense if your role is in bookkeeping / accounting / finance. Your life is based on pay periods and not on day-of-year/month. A particular pay day "belonging" to a particular year is a meaningless affectation: people need to get paid every two weeks come hell or high water, and anything that can complicate the smooth running of that process is discarded.
As for the algorithm:
> The ISO 8601 definition for week 01 is the week with the first Thursday of the Gregorian year (i.e. of January) in it. The following definitions based on properties of this week are mutually equivalent, since the ISO week starts with Monday: […]
Re: Do not use 'week year': YYYY
#40Is it just me for thinking that using format strings instead of some strongly typed interface with verbose names for this is not great? I would take `format(year(), '/', month(), '/', day())` over ad-hoc format strings by various APIs. Reading the docs further this also stands out: > For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some cent…
> Is it just me for thinking that using format strings instead of some strongly typed interface with verbose names for this is not great? Yes, but it would not have helped with the bug in question. The parallel bug for a strongly typed interface would be "year()" returning this monstrosity, while "iso_year()" or some other poorly named variant returning the expected year. No API is immune to footguns and bad design d…