Opened 12 years ago

Last modified 7 years ago

#6008 closed enhancement

dojo.date.get() detect any kind of date (string, object, etc) — at Version 9

Reported by: wolfram Owned by: wolfram
Priority: low Milestone: future
Component: Dojox Version: 1.0
Keywords: needsreview Cc: Neil Roberts
Blocked By: Blocking:

Description (last modified by Adam Peller)

I was missing a general functionality to detect any kind of date and properly convert it, so I wrote quite a simple first version of it. Interesting for dojo?

    // Return a Date object for the various inputs
    dojo.date.get(new Date());
    dojo.date.get("2009-11-11 11:12:13")
    dojo.date.get("now");
    dojo.date.get("yesterday");
    dojo.date.get("3 days ago");
    dojo.date.get("3 weeks ago");

and I am sure that a lot of things could be interesting to be done, like "+3 days", "-1 week", etc. (next Tuesday, a week from tomorrow, etc)

The actual idea came from http://trac.dojotoolkit.org/browser/dojox/trunk/dtl/filter/dates.js?rev=12531#L9 where a date needs to be detected and converted, so i thought generalize it and make this patch.

Change History (11)

comment:1 Changed 12 years ago by wolfram

Type: defectenhancement

Changed 12 years ago by wolfram

Attachment: date_get.patch added

comment:2 Changed 12 years ago by wolfram

Description: modified (diff)

comment:3 Changed 12 years ago by wolfram

Description: modified (diff)

comment:4 Changed 12 years ago by wolfram

Description: modified (diff)

Changed 12 years ago by wolfram

Attachment: dtl_dates.patch added

This patch shows how i.e. the dojox.dtl.filter.dates would benefit from dojo.date.get()

comment:5 Changed 12 years ago by wolfram

Cc: Neil Roberts added

comment:6 Changed 12 years ago by Adam Peller

Component: DateDojox

this isn't localized, so it can't go in dojo. Perhaps we could look into localization, but the nls stuff is hard to do right. The JSDate project has code to do this, though it didn't seem like it was precise where localization was concerned. A non-localized version like you have could go into dojox.strings or something, I suppose, though I don't personally endorse it... yet.

I'm not sure what's accomplished by the Date object input, and the ISO-like thing ought to be close enough to dojo.date.stamp that it's not necessary. With the ISO dates, wouldn't you usually be restricted to that type?

Possibly a dup of #1646

comment:7 Changed 12 years ago by dylan

Milestone: 1.2

comment:8 Changed 12 years ago by Adam Peller

Description: modified (diff)
Owner: changed from Adam Peller to wolfram

Given the state of the patch, I'm not sure if this should be marked 1.2.

This is ok as long as it goes into dojox and is marked experimental and not localized (though it would be really interesting to see if a localized version of this could be accomplished -- some of the strings might even be available in dojo.cldr)

I'd suggest not using the Date() constructor to parse, since it's not specified and varies across browsers. Also, if you must compare the constructor value for validity, check with isNaN, not == "Invalid Date".

ISO stamps in dojo.date require "T". If you want, you can provide a dojox.date routine that just does a replace " " -> "T" then pass to dojo.date.stamp.

comment:9 Changed 12 years ago by Adam Peller

Description: modified (diff)
Note: See TracTickets for help on using tickets.