Hi Charizar,
What you're trying to do is actually reasonably hard. While libraries like
ICU and languages like Java and C# provide parsing routines that, for a
given locale and format, can parse a string into a date object (generally an
integer value such as you describe), these parsers are limited in their
ability to deal with the multiple formats that human users might reasonably
input.
In order to do the parsing, you *must* know the language and locale of the
string. Given that information, you can write a parser that tries the
various patterns associated with that locale. You should note that you may
still get false positives (that is, the parser returns a value based on part
of the string that it recognizes).
I've written such a class in Java and you can see it in action (the demo may
be a little confusing) at:
http://www.inter-locale.com/CodesetTesting4.jsp
In my estimation, the best thing you can do is avoid user input of strings
for dates. Use GUI-like controls to input the values and use
locale-independent formats (string or long values) to carry the actual date.
Relying on users to exactly match a pattern may result in odd slips, since
users may not pay close attention to the ordering of day and month (for
example).
One last note: I notice that your example date/time string doesn't include
timezone information. Don't forget timezones in your implementation!
Good luck and best regards,
Addison
Addison P. Phillips
Director, Globalization Architecture
webMethods | Delivering Global Business Visibility
http://www.webMethods.com
Chair, W3C Internationalization (I18N) Working Group
Chair, W3C-I18N-WG, Web Services Task Force
http://www.w3.org/International
Internationalization is an architecture.
It is not a feature.
> -----Original Message-----
> From: namaskar321 [mailto:namaskar321@...]
> Sent: mercredi 17 mars 2004 06:29
> To: i18n-prog@yahoogroups.com
> Subject: [i18n-prog] How to parse Date based on locales for any
> platform???(Similar to COleDateTime::
>
>
> Hi All,
>
> I have a very strange problem. I am writing a function equivalent to
> MFC COleDateTime::ParseDateTime(). In that I get the input string(in
> param to the ParseDateTime function) as date (for example "18
> december 2003 13:00:04")... I need to parse this date -time string
> and return me a double value from 1899 December 30 midnight, similar
> to the way COleDateTime::ParseDateTime() does it.
> There are three problems,
> 1) If the date string comes in various languages for example the
> months can be as per Japanese language or French or German etc,
> depending on the locale, then how do i parse the date.
>
> 2) Also the format in which the date time will come is not fixed. For
> example it might come in as dd mm yyyy or mm dd yyyy or dd mmm yyyy
> or dd mmmm yyyy or any other formats supported by
> COleDateTime::ParseDateTime(). The formats are based on the
> locales.How do i handle such cases.
>
> 3) I cannot use SetLocale() and strptime(), because they are not
> thread safe, and my application is heavily threaded.
>
> I need my emulated class to be platform independent and cannot use
> java's date class. The code should be in C++.
>
> I tried it using IBM ICU library. I could parse the dates for English
> locale, but it unfortunaltely failed for JAPANESE Strings ... Also my
> problem is To recognize the DATE string and format in which it is
> (mm dd yyyy...) ,seprately and Time String Seprately, For which I
> should know how to isolate the strings (i.e. any strings ... May be
> Japanese, Korean, Chinese ...etc), how do I do it?
>
> Please help and also do suggest if any other library except IBM ICU
> is availabe to do the same.
> Please do reply ASAP.
>
> Thanks in Advance.
> Charizar. :))
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>