Merged with internationalization of dates on the web.
does anyone have any good "architecture" for the internationalization of dates? like in english its Monday, chinese: 星期一, dutch: mandaag, jap: 月曜日
So my first idea is to create some sort of class that stores the strings of Monday to Sunday in 59 different languages. Apparently this isn't scalable at all, imagine now I need to display "12:34 A.M, Monday, 1st Jan 2000" i will then need another translation for A.M, P.M, the months (both long and short forms), the ordinals, etc, etc.
It's too much work, what's the solution?
Related
Can anyone help me in converting the below date format into the preferred format?
"Tue Dec 08 18:00:00 IST 2020"
preferred format:
2020-12-08 18:00:00 +05:30
This is not possible because time zone abbreviations are not well defined, and many are not unique.
For example, there are 3 different interpretations of IST:
India Standard Time (UTC+05:30)
Israel Standard Time (UTC+02:00)
Irish Standard Time (UTC+01:00)
You seem to be asking about the first one, but there's no way for a computer to know that when you are considering all of the time zones of the world.
The list of possibilities gets a bit crazy if you start thinking about other details, such as:
Some time zones have more than one abbreviation commonly used.
There are "invented" abbreviations that some people use and others do not.
Many time zones don't have any real abbreviation at all and just use a numeric offset.
There are abbreviations from other languages than just English.
In some languages, your string including the abbreviation might contain non-Latin characters, such as with Asian languages, Cyrillic languages, Hebrew, etc.
Thus, you cannot just convert whatever abbreviation might be in your string to the correct offset. Instead, you need to generate the string such that it already has the offset in it, or you need additional information - such as a time zone identifier (e.g.: "Asia/Kolkata"), or at least a country code and language to help disambiguate the abbreviation.
I'm making booking software for a live show. My performers often send me multiple dates that they're available. I'm dealing with lots of performers and lots of dates where there could be conflicting bookings. I want the app to be able to look at all the dates and find all the conflicts.
I would love it if I could copy and paste their email text into a form field and have jquery find the dates to process them. Is there an existing system for doing this? It would have to be smart. Here are some examples of emails I recieve and the arrays I would like returned from javascript...
I can do: Aug. 29, 2018 Sep. 5, 2018 Sep. 19, 2018
{"2018-08-29","2018-09-05","2018-09-19"}
I'm available 10/9 and 11/2
{"2018-10-09","2018-11-02"}
How about Sept 8 & 15?
{"2018-09-08","2018-09-15"}
Can we do next wednesday and Nov 9?
{"2018-08-29","2018-11-09"}
You formats are way to "open" so finding something that would work for all of these would be tricky. You could look into https://dateparser.io/. They seem to support a wide range of cases as you can see here.
Some examples:
December 15th, 2010, 15th of December, 2010-12-15 ...
Also relative dates:
last friday, today, a day from now etc.
Moment.js does humanized and calendar dates, for example:
moment().calendar()
"Today at 10:17 AM"
which gets a current date object and converts to a calendar date, and
is there any way to do that in reverse? Like if I give it "Today at 10:17 AM", it returns a date object with todays date and 10:17 AM as the time?
date.js can parse human readable dates:
http://www.datejs.com/
SugarJS can also parse natural language dates:
http://sugarjs.com/dates
It can deal with stuff like:
one day before yesterday
2 days after monday
2 weeks from monday
a second ago
25 years from now
last wednesday
Also, see this related question: Is there a natural language parser for date/times in javascript?
Chrono v2
It's the only library I've found that also parses timezones.
Examples
Unfortunately, the only documented way of using is via NPM or as ES6 Module, but I found a way to use the library with the traditional script tag approach.
Non-NPM / non-module usage:
Include this script: https://www.unpkg.com/chrono-node/dist/bundle.js
Use the global variable chrono in your script (available methods here)
E.g. chrono.parseDate('Tomorrow at 4 PM PST')
I am trying to extract different date formats from a text and later compare those dates if they belong in some time span. Let' say time span is from 1.1.2013 to 1.3.2013 . This is DD/MM/YYYY time format.
Now how can I extract different time formats from text. I have here examples of time formats.
Tue Oct 23, 2012 7:59 am
February 19th, 2013, 07:32 PM
Today, 09:22 PM
Yesterday, 09:03 AM
28 February 2013 09:38
Yesterday 16:48
8 Oct 2012 5:41:00 AM
02-18-2013, 03:17 PM
02-01-13, 12:31 PM
12.2.2013 20:43
I understand this is not a simple task to perform but any kind of suggestion can help me.
Also I am aware of this question and answers . This will benefit me later
Compare two dates with JavaScript
Also the guys on chat had this to say.
Uwe Günther
#IceD looks like you need some lib who implements that all :-)
But ih ave noe clue which one does. Better ask the Stack
IMPORTANT
I don't want jQuery in this since I can't implement it in what I am using right now. So only JS solutions for this.
You will need to normalize them to a common, comparable format, most suitably Date objects.
For some of your formats, (some browsers) will be able to Date.parse them, but for others (like "yesterday") you need to do more sophisticated parsing (up to NLP?). It would be best if you knew the format of each snippet so you can pass them to the right parsing algorithm, if not you'll need to apply some heuristics.
I need to display dates in a couple different ways in an app built with jquery.
In some situations, I need the typical "yyyy-mm-dd hh:mma" type of formatting, with all of it's different permutations. In other cases, I need to show dates "pretty printed" similar to how StackOverflow does them:
5 seconds ago
12 minutes ago
3 hours ago
yesterday
2 days ago
My application already uses JQuery UI DatePicker which includes a formatDate() function, but as far as I can tell, there is no way to use it outside of the datepicker. I want to format dates that aren't associated with a datepicker. Is it possible to do this using DatePicker?
The DateJS library can parse dates like "12 minutes ago", but as far as I can tell, it cannot take a Date object and format strings like this. It can format the typical "yyyy-mm-dd" types of formats. This library seems pretty heavy as well.
John Resig's Pretty Dates looks like it can provide the pretty printing ("2 hours ago"), but it doesn't do the standard formatting.
Is there not a single plugin that can do all of this? Is there a way to leverage the DatePicker code so I don't have to load multiple codebases that do the same things?
http://timeago.yarp.com/
Check out prettyDate.
It's made by the same guy that does the jQuery Validation plugin.