You don't need libraries for internationalization of dates
time2hack.com
time2hack.com
You can use Date.prototype.toLocaleString and its customizable API to get the localized output easily. Like in the following example, we will use the Locale String to easily get the Readable Date desired by the user
Actual content: "... you might not need any of these libraries [moment, dayjs, date-fns] to have some basic Formatting and Localization on the Date Objects."
Lets get rid of all date-time formats except the iso(YYY-MM-DD) one...
It is simple to think that this format would work but the people who are not familiar with this format will be completely lost with it. People who are not educated but somehow learnt to follow one format; ask them to learn a new format; it will be so complicated.
Sigh...
You're not even from the United States, so you should full well know how important standardisation is across country borders. There are literally only three countries that haven't adopted metric, zero that haven't adopted the standard 24 hour / 60 minute day, and only four that haven't adopted the Gregorian calendar[1].
So why is it so hard to accept the one consistent date format? Seriously? Why?
Tell you what: If you can tell me which day the following date represents, I'll give you USD 100. Seriously. I'm not even kidding.
03/04/05
Go ahead. Guess.(1) standard probabilities apply.
But seriously, yes. I am French and write the date as 2009-03-01 and get weird looks.
I work in a French company and some people seem to assume that it is fancy to use a US format for the dates. I refuse to read a document which did not have an obvious format.
Heck, even MAR/01/2020 could be acceptable but why? Why?
You haven't though because there isn't a locale setting in the browser.
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ti...
If a user sees some random date, such as 3/4/xxxx, they have absolutely no way to distinguish if this is in their format or not.
If you're in the US, you might assume that this is in your backwards M/D/Y format, meaning it's April 3rd, and you'd be right much of the time.
However, if you're outside the US, then there are two indistinguishable possibilities:
It's a US server ignoring your time format, so this date represents April 3rd.
OR
It's a server correctly showing you a date in your preferred format, so it's actually the 4th of March.
At a glance, these aren't distinguishable. I easily click through 200-500 pages a day! I'm not going to sit down and try to work out which of those hundreds of pages a day, and thousands of pages a week are designed for humans, or just Americans.
If you're in the US, you might assume that this is in your backwards M/D/Y format, meaning it's April 3rd, and you'd be right much of the time.
If I, in the US, see 3/4/xxxx, its meaning is March 4th, definitely not April 3rd.
But the fact that you got your example wrong only proves your overall point that it's a mess!
Also, I don't believe you can rely on a browser having a particular locale available. I'm not sure how reliable time zone data will be either, if you need to show something in a different time zone.
I think for some general use-cases this will work well. But there's still a lot of weird issues around this stuff in the browser.
That would all be possible without third party libraries, but often you want to subtract 2 weeks from a date and that is just a pain in the arse with timestamps. You also might want to import/export dates to databases, which can be picky about the format.
I am no web developer, so others might have better opinions. And I think the author is correct that people not used to certain libraries should try the standard ones first.
Yes, obviously you can forego DRY and write and maintain a bunch of boilerplate for date manipulation, or write and maintain your own date library, but for most uses itmakes a lot more sense to use an existing library. For new uses, probably not momentjs, though—probably date-fns, or luxon, or...
Recently learned that you can internationalize dates right in your Postgres queries/functions! tps://stackoverflow.com/a/59632278/741970. Postgres has great date functionality in general, but with Linux locales installed you can use it for just about anything date related.
So yes, you do.
I wound up switching to Luxon because of this. Which is too bad, because date-fns is a fine library otherwise.
People like reading nice dates and nice words. They're easy to parse for human brains. Sure, "1e6" is nice and short but typing out "a million" is much easier to understand. Giving someone a notification that they have an appointment "next Thursday (2020-02-27)" is a lot clearer than just stating the date. It saves people from having to look up the current date and doing mental math to find out how much time is in between those dates.
Nit everyone is a programmer and not everyone likes short and concise data notation. Date localisation exists for a reason and it's not because people like to make developers' lives impossible.
Use ISO8601 because of its technical superiority if you want, but don't think it's the final answer to the date/time problem.
How is 2020-02-27not nice?
> Sure, "1e6" is nice and short but typing out "a million" is much easier to understand
IMHO 1 000 000 is the easiest (sure the 1e6 from is better for bigger numbers). As for "a million" I don't understand anything bigger described this way (billions, trillions etc) - tell me 1 trillion and 2 billions and I have absolutely no idea how much is that. It wouldn't be a problem for me to memorize unless there were not the long and the short system as I rarely have a clue which one is being used.
> "next Thursday (2020-02-27)" is a lot clearer than just stating the date
Sure, but something like 02.27,2020 is no way better than 2020-02-27, it's just a matter of habit particularly easy to change.
Habits are not easy to change and changing them gets harder as you get older. Microsoft changing the icon of the start menu got me many questions from people anywhere between 20 and 80 back when I did tech support. These people were smart enough to use a computer yet a tiny change confused them. When Windows changed their start menu to something new, people didn't want to change the way they did things and tools like Classic Start was born. If clicking an icon on a computer is too hard a habit to change, how do you think telling the world to change their date notation will go down?
And why should we all go do stuff differently because someone has come up with a way that makes lexicographical sorting of dates possible?
Furthermore, "next Thursday" is already part of internationalisation code (Thursday needs to be translated and the concept of what the literal translation of "next Thursday" means changes between languages and cultures). Why not also put the full date into the correct locale as well while you're at it?
Just because I think metric measurements are superior to imperial measurements doesn't mean I don't need to translate those units of measurement to American when I publish an app that uses them. Anyone capable of counting to ten can understand the metric system but that doesn't mean I can get away with providing metric-only information and input fields for everything.
There's a difference between what academics and engineers use and what the general public uses. If you don't make a general product for the general public then you don't make a very good product.
It's a very common way to denote date, and you would have to be borderline retarded to not understand it.
> If you're used to the usual date notations (day before month)
This is not usual at all! You've just handwaved away the #1 stupidity of localized date formats: the special flower that is the United States and their crazy M/D/Y shorthand that means that nobody can ever parse these "common" date formats unambiguously, anywhere. Not humans, not computers, not even hyper intelligent AIs of the future. Critical information is being thrown away, and can never ever be recovered.
> Habits
What habits? I just assume that any site showing me a date like 3/4/5 could be either the 4th of March or April 3rd. It's like a Quantum Date, in a superposition of possibilities. That's the habit I'm currently used to.
If you're not confused, then you probably live in the US, which is a 4.25% minority of the world population, so it's a small group that I think we all agree can be safely ignored.
> And why should we all go do stuff differently because someone has come up with a way that makes lexicographical sorting of dates possible?
Why would you not "do stuff" when as a bonus you get trivially sortable dates on top of having unambiguous dates that both humans and computers can interpret correctly?
Doesn't it drive you crazy that randomly things just don't work because some twat left a Windows servers on en-US so that CSV export or import just shreds data? Or if you're in the states, you get data sent to you and you can't figure out why there are sales in the future? Doesn't it drive you crazy that when you see a security hotfix saying 3/4/5 you have no idea if it's next month or the month after?
> Clicking an icon on a computer is too hard a habit to change
It isn't, people just like to whine.
One of the few smart CIOs once told me: Don't worry about the icon changing. Don't even bother telling anyone. We're not paying $100K to people too retarded to do their job because the colour of the icon changed.
> metric-only information and input fields for everything.
This actually happens all the time, and people figured it out without their brains leaking out of their ears.
What nobody can get used to is a single number on a webpage showing a measurement without units.
If I tell you to buy a "5" screw or dig a "7 deep hole", you would have no clue what that means. You can't possibly. No matter what.
A date in a format like 3/4/5 is exactly the same thing: meaningless numbers without units or context.
A date in the format of 2020-04-03 or 2020-03-04 have only one interpretation.
> There's a difference between what academics and engineers use and what the general public uses.
Yeah well, academics came up with the Metric system and 95.75% of the world population loves it.
You mean the great majority of them, including official math notation?