Date.js culture info is confusing me - javascript

I'm including date.js (from datejs.com) and the en-IE culture info script.
If I call alert(Date.CultureInfo.dateElementOrder) I see the correct dmy, but if I try to interpret the date 02/03/01 I get 3 Jan 2001 and not 2 Feb 2001. I'm not sure whether this is a bug in date.js or a problem with me.

The documentation was confusing me (or I hadn't read it right).
I thought I should include date.js and en-IE.js. In fact, the right thing to do is to include date-en-IE.js, a file I hadn't even noticed existed before.
As usual with datejs, the downloadable file on the front of the site is a year or so out of date, but a live version exists if you dig for it in the svn trunk.

Related

Date/Time on Articles <time>

This is a fairly simple question. While I'll certainly accept and appreciate a detailed answer, guidance in the right direction is all I'm looking for as I have no qualms about learning. I still consider myself an amatuer so please forgive me if you find this trivial.
I'm sure you've all seen what I'm looking for here if you've read a blog or any type of news site. Articles usually have some type of heading with "1 Year Ago", "28 Minutes Ago", etc to reflect the difference in time from when an article was published to the current time you are looking at it. What I'm trying to figure out is how that is accomplished?
I learned today that a tag exists but so far I haven't been able to determine how the attributes you can assign to (e.g. datetime="2015-04-27 20:00") it turn into a readable "1 Year Ago". In my head, I'm imagining some ways I might be able to do this with JavaScript but I'm wondering if this is how it's typically done.
Thanks in advance.
What you might have read is that the "special attributes" actually are pseudo-attributes in some front end framework like Angular, React or Vue etc.
In angular they are known as custom directives. Where you can define custom attribute to pass some data into angular code and get some thing back in this case the humanized form of a date.
What you probably want is moment.js and some way to pass the the date into moment.js to parse it if your not using Angular or other frameworks. Since you are nt so descriptive about your code behind I leave it here on how to work that thing out.
A simple example to demonstrate Moment.js Time from now
moment([2007, 0, 29]).fromNow(); // 4 years ago

In Moment.js, why doesn't subtract by 'week' work?

I'm using Moment.js and following line of code doesn't seem to actually do anything:
moment().subtract('week', 1)
In the documentation, it shows an example of subtract being used with 'days' but it doesn't specify that it's the only string you can use. In most of the other functions, it's an option where you can use 'days', 'weeks', 'months', so I'm not sure if I'm doing something wrong or 'weeks' just isn't supported:
Moment.js Subtract Documentation
Here's the example of subtracting days:
moment().subtract('days', 7);
It's also what I ended up using instead of 'weeks' but I'm still curious why 'weeks' aren't supported.
You have it backwards from the Moment API.
moment().subtract(1, 'week');
This is a bit old question but it appears that even back then it was relevant.
Definetely nowadays is even more relevant to consider parse.com moment.js version (1.7.2) to the current moment.js version (2.8.4) and the only API doc that parse.com makes reference to
Check an answer to this in a previous post in Trouble using the Moment module
I would suggest to work always with latest moment.js so you can properly work with the provided documentation (during my search I was not able to find 1.7.2 documentation.. beside you will miss many great features working with the version provided in parse.com.
Add the new version as indicated in the same post in the accepted answer.

Chronic for Javascript?

I'm looking for something like the Ruby Chronic library, but for Javascript. The main things I need to be able to do is parse natural time entry, not dates. For example:
Typing Would Give
------ ----------
8a 08:00
8:30p 20:30
8:01 AM 08:01
21:22 21:22
noon 12:00
midnight 00:00
I could write it myself, but before I go off and tackle it, I wanted to know if there was something already available.
I'm using jQuery already, so if there's a plugin, that would be hoopy too.
Thanks!
In place of my previous answer recommending Date.js, I'd like to update my answer by recommending Moment.js instead. It's a stable project that is still under active development. In addition, it is far more feature-filled and has a superior API. :)
Date.JS is a wonderful JS library for working with dates and times.
Comparison support for Ruby Chronic.com date and time input formats.
Check this out
http://www.datejs.com/test/ruby_chronic/index.html

Time Zone Sensitive Date and Time Display in Web Applications?

I am looking for recommendations on displaying times in a web application in a time zone other than the user's current time zone.
We store our dates/times in UTC/GMT in the database, so it is not an issue to format the time for UTC/GMT or the user's current time zone. However, in other situations we need to display the time from the point of view of an arbitrary time zone (i.e. every date/time on this page is in Eastern, regardless of whether or not the user is in West Coast, Central, Eastern, etc.).
In the past we have stored offsets or time zone info, then done the calculations in server code in .Net or else we have done some client-side manipulations in javascript that I would prefer to avoid, since it all becomes very dependent on javascript and the user's browser. I'd like to know the best way to do this in a more client-side/MVC type application.
Here is an example:
Date stored in db: 1302790667 (Thu, 14 Apr 2011 14:17:47 GMT)
Converted date displayed for a client in Central time zone: Thu Apr 14 09:17:47 2011
Date I actually want to display, always in Eastern time zone: Thu Apr 14 10:17:47 2011
In the above example, it's easy to get the time in UTC (#1) or the user's current time zone (#2) but it is more difficult to get #3. My options seem to be:
Store offsets or time zones in the db and do calculations on the client - this is what we've done in the past with .Net but it seems even messier in client side code is the path we are currently trying to avoid.
Do the conversion on the server and send down a full date for display to the client - client receives a string ("Thu Apr 14 10:17:47 2011"). This works but it's not very flexible.
Do the conversion on the server, break it into parts and send those down to the client, then put them back together. ("{DayOfWeek:Thu, Month:Apr, Day:14, Hour:10, Minute:17}"). This gives us the correct data and gives us more flexibility in formatting the date but it feels a little wrong for this scenario.
Any other options ideas? How do others handle similar situations? Thanks.
Our results:
I tried out a few libraries like Datejs, MS Ajax, etc. and I was never very happy with them. Datejs didn't work at all in a few of my test cases, is not actively maintained, and seemed to focus a lot on syntactic sugar that we don't need (date.today().first().thursday(), etc.)
We do use jQuery for some basic date/time parsing.
I came across a lot of "roll-your-own" client-side date conversion "hacks", most of which only addressed the conversion to UTC, started off working fine, and then eventually fell apart on some edge case. This one was the 90% solution for a lot of standard UTC conversion but didn't solve our "arbitrary timezone" issue.
Between the code complexity the conversion routines added and the bugs they seemed to cause, we decided to avoid client side date processing most of the time. We do the date conversions on the server with our existing date handling routines and pass the formatted dates or info down as properties to be used by the view. If we need a separate date, we just add another property. There are usually only a few properties that we need at a time (i.e. EventDateUTC, EventDateLocal, EventDateAlwaysAustralia, and EventDayOfWeek).
I offer the suggestion that you look into the Datejs library. It offers a bunch of extensions to basic JavaScript date manipulation, including a "setTimezone()" method and flexible ways to convert a date into a formatted string for display.
I usually hesitate to suggest libraries when their use is not explicitly allowed for in questions, but Datejs isn't very large and it's pretty solid (even though it's called an "alpha" release). If you'd prefer not to rely on something like that, you might want to look at it anyway just to see the basics of how its extensions were implemented.

how to convert Hijari date into Gregorian date in javascript?

I am using intalio editor in that I want to convert the Hijri date into a Gregorian date or vice-versa. we write code in javascript using jsx3 so please help me.
For Gregorian->Hijiri, see here
Bidirectional C# version here that could be converted to Javascript
EDIT: An excellent page and convertors can be found here. That page says:
All calculations are done in
JavaScript executed in your own
browser; complete source code is
embedded in or linked to this page,
and you're free to download these
files to your own computer and use
them even when not connected to the
Internet.
which suggests to me you can use the code, but you probably want to check with the page author
It helps to know that muslims refer to the Gregorian calendar as Masihi. Googling for "hijrah to masihi converter" turns up this page as the second hit: http://www.islamicity.com/PrayerTimes/defaultHijriConv.asp
The javascript is code contains two functions GregToIsl and IslToGreg that does what you want.
There is a copyright notice on that page so you shouldn't simply copy-paste the code. But the functions are short enough for you to extract the relevant maths out of.
The maths/algorithm itself is almost a thousand years old so it shouldn't have any legal restriction.
Try dojox.date.islamic
In Javascript the correct way for such conversion is to use Intl object (read more) as following:
a = new Date();
localeFormat= 'ar-SA-islamic-umalqura';
Intl.DateTimeFormat(localeFormat).format(a)

Categories

Resources