[Dojo-interest] Date Parsing to go with Date Formatting
Aaron Evans
aaronmevans at gmail.com
Fri Apr 28 12:06:35 MDT 2006
No, but ok, then great!
Like I said, as long as I have a parse method that takes a format
string that uses the same format grammar as the dojo.date format
method, I'm happy. If in turn, a lenient parser is developed that
leverages that, then all the better. :)
On 4/28/06, Rick Morrison <rickmorrison at gmail.com> wrote:
> Aaron, have you looked at the loose parser code? That's (the successive
> attempt method) more or less the way it works.
>
>
> Rick
>
>
> On 4/28/06, Aaron Evans <aaronmevans at gmail.com> wrote:
> > Hmm... In that case, I would prefer to go strict. It is easy to make
> > a lenient parser once you have the strict one by successively trying
> > different format strings. It is not so easy to make a lenient parser
> > strict.
> >
> > On 4/28/06, Rick Morrison <rickmorrison at gmail.com> wrote:
> > > No no, I am proposing only the parser as well. A widget like you and I
> have
> > > described would be trivial, once the parser is there.
> > >
> > >
> > > Rick
> > >
> > >
> > > On 4/28/06, Aaron Evans <aaronmevans at gmail.com> wrote:
> > > > Rick,
> > > > Actually, I think we are proposing two different things, both of
> > > > which, IMO, have value. :)
> > > >
> > > > You are proposing and out of the box cool widget to enable users to
> > > > easily enter dates and see that they are interpreted properly right
> > > > away.
> > > >
> > > > I'm proposing an addition to the dojo.date API to serve a developer
> > > > who is building a custom widget (or any client side routine in
> > > > javascript for that matter) that requires date parsing in an arbitrary
> > > > format.
> > > >
> > > > On 4/28/06, Rick Morrison <rickmorrison at gmail.com> wrote:
> > > > > Aaron, I think you and I are actually proposing roughly the same
> thing;
> > > the
> > > > > difference being that your proposal would have a parser that would
> be
> > > strict
> > > > > in its interpretation of date strings, while the one I'm proposing
> would
> > > be
> > > > > looser.
> > > > >
> > > > > Successful parsing of ambiguous dates is, I think, part of a good
> > > > > interface, and what Simon's posting was all about. The downside to a
> > > strict
> > > > > parser is that if forces the user to input the date only in a rigid
> > > format,
> > > > > the upside is that it always parses in an unsurprising way. On the
> loose
> > > > > parser side, the upside is that the user has the freedom to use a
> lot of
> > > > > options for input, and the downside is that it will sometimes guess
> the
> > > > > wrong format and surprise you.
> > > > >
> > > > > I've been using the loose format for several years, and users seem
> to
> > > > > really like it. What I do is accept the loose format, and then use
> an
> > > > > onblur() handler to parse the loose format into a Date() object,
> format
> > > that
> > > > > date according to locale, and then set the .value of the input to
> that
> > > new
> > > > > format. This way, any "surprises" in the parse show up right away on
> the
> > > > > client side. Check out the demo on Simon's site, or the other link
> to
> > > > > Nathaniel's site to see this technique in action.
> > > > >
> > > > > Rick
> > > > >
> > > > >
> > > > > On 4/28/06, Aaron Evans < aaronmevans at gmail.com> wrote:
> > > > > > No, the date object doesn't handle it, you can't specify a format
> > > string.
> > > > > >
> > > > > > Therefore, you will run into problems when parsing ambiguous dates
> > > > > > such as 3/1/2005 (not to mention formats for foreign locales).
> > > > > >
> > > > > > I agree user interfaces are important and that much of the focus
> of
> > > > > > this client side library has to do with the actual UI. However, I
> can
> > > > > > imagine cases where, internal to a widget, you would need this
> API.
> > > > > >
> > > > > > Again, I refer to my original use case, my drop down-date picker,
> > > > > > similar to Dylan's given here:
> > > > > >
> > > > > >
> > > > >
> > >
> http://dojotoolkit.org/~dylan/dojo/tests/widget/demo_DatePicker.html
> > > > > >
> > > > > > This is a widget that uses a text input and a date picker in
> > > > > > combination. I have modified Dylan's demo so that I can
> parameterize
> > > > > > the initial value and the date format by using attributes in the
> div
> > > > > > tag.
> > > > > >
> > > > > > I have designed it this way so that when the server writes the
> page
> > > > > > output, I can detect the user's locale and use a Java resource
> bundle
> > > > > > to decide what date format to use for this particular client.
> > > > > >
> > > > > > So say (as a user) that instead of using the date picker, I edit
> the
> > > > > > value of the text input by hand. Now I need to update the date
> value
> > > > > > of the DatePicker widget so that if I bring it up again, it is set
> to
> > > > > > the date of the text input. So here is a case where I have
> neither a
> > > > > > JSON object, nor a native date object since text inputs hold
> strings.
> > > > > > I have to be able to parse that date using the format for this
> > > > > > specific locale.
> > > > > >
> > > > > > As an aside, "Data Providers" in fact, must provide dates in some
> kind
> > > > > > of encoded string, not a native date object, since HTTP is text
> based.
> > > > > > Client/Server libraries can agree to encode and decode those
> strings
> > > > > > producing native objects at either end, but none-the-less, they
> are
> > > > > > strings in transit.
> > > > > >
> > > > > > What I am doing is instructing the client how to interpret the
> date
> > > > > > string in a grammar that the client library already uses for
> > > > > > formatting.
> > > > > >
> > > > > > In any event, I don't want to get into an argument about it. If I
> am
> > > > > > the minority and people don't see the value in what I am
> proposing,
> > > > > > then that's ok. :)
> > > > > >
> > > > > > I have done enough of an implementation in my dojo extensions to
> > > > > > handle my current requirements (it handles %Y, %y, %m and %d) and
> I'll
> > > > > > simply add other pattern strings as I need them.
> > > > > >
> > > > > > cheers,
> > > > > > aaron
> > > > > >
> > > > > > On 4/28/06, Rick Morrison <rickmorrison at gmail.com > wrote:
> > > > > > >
> > > > > > > Aaron, it seems to me that if what you're looking for is a round
> > > trip,
> > > > > the
> > > > > > > ECMA Date object already does that in native code:
> > > > > > >
> > > > > > > var d = new Date();
> > > > > > > var s = d.toString();
> > > > > > > var d2 = d.parse(s);
> > > > > > > assert(d == d2);
> > > > > > >
> > > > > > > I don't really see the value in round-tripping dates in a
> gadozen
> > > > > string
> > > > > > > formats. Any data provider API will most likely store dates in
> > > native
> > > > > date
> > > > > > > objects or JSON strings, not formatted strings.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > Never mind a user interface, IMO,
> > > > > > > > that is beside the point and these functions/methods are just
> the
> > > > > > >
> > > > > > >
> > > > > > > IMO, user interaction is *entirely* the point. This is main
> purpose
> > > of
> > > > > this
> > > > > > > client-side library, no?
> > > > > > >
> > > > > > >
> > > > > > > Rick
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > _______________________________________________
> > > > > > > Dojo FAQ: http://dojo.jot.com/FAQ
> > > > > > > Dojo-interest at dojotoolkit.org
> > > > > > >
> > > http://dojotoolkit.org/mailman/listinfo/dojo-interest
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > _______________________________________________
> > > > > > Dojo FAQ: http://dojo.jot.com/FAQ
> > > > > > Dojo-interest at dojotoolkit.org
> > > > > >
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
> > > > > >
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > Dojo FAQ: http://dojo.jot.com/FAQ
> > > > > Dojo-interest at dojotoolkit.org
> > > > >
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
> > > > >
> > > > >
> > > > >
> > > > _______________________________________________
> > > > Dojo FAQ: http://dojo.jot.com/FAQ
> > > > Dojo-interest at dojotoolkit.org
> > > > http://dojotoolkit.org/mailman/listinfo/dojo-interest
> > > >
> > >
> > >
> > > _______________________________________________
> > > Dojo FAQ: http://dojo.jot.com/FAQ
> > > Dojo-interest at dojotoolkit.org
> > > http://dojotoolkit.org/mailman/listinfo/dojo-interest
> > >
> > >
> > >
> > _______________________________________________
> > Dojo FAQ: http://dojo.jot.com/FAQ
> > Dojo-interest at dojotoolkit.org
> > http://dojotoolkit.org/mailman/listinfo/dojo-interest
> >
>
>
> _______________________________________________
> Dojo FAQ: http://dojo.jot.com/FAQ
> Dojo-interest at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
More information about the Dojo-interest
mailing list