You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Christofer Dutz <ch...@c-ware.de> on 2014/02/01 17:17:51 UTC

Simple way to parse I18N dates?

Hi,

I am currently sort of stuck with implementing some functionality.

I know I can use a DateFormatter to define a formatted string from a given date, but I couldn't actually find something for the other way around.
The Java equivalent usually has a "parse" and a "format" method allowing to read a date from a string and to return a date and a format to serialize a date to a desired output format. It seems the Flex version is missing the parse part ... What do I have to use for this?

Chris

AW: Simple way to parse I18N dates?

Posted by Christofer Dutz <ch...@c-ware.de>.
Hmmm ... strangely the following expression allways returns null:

DateFormatter.parseDateString("20140227", "YYYYMMDD");

So what am I actually doing wrong?

Chris


-----Ursprüngliche Nachricht-----
Von: Harbs [mailto:harbs.lists@gmail.com] 
Gesendet: Montag, 3. Februar 2014 08:03
An: users@flex.apache.org
Betreff: Re: Simple way to parse I18N dates?

FWIW, it might make sense to deprecate the DateField.dateToString() method in favor of the DateFormatter.parseDateString() one.

On Feb 3, 2014, at 8:20 AM, Harbs wrote:

> Thanks. That's much more robust. It might do what I need.
> 
> Harbs
> 
> On Feb 3, 2014, at 12:26 AM, Justin Mclean wrote:
> 
>> Hi,
>> 
>> You might want to look at parseDateString in DateFormatter.
>> 
>> Thanks,
>> Justin
> 


Re: Simple way to parse I18N dates?

Posted by Harbs <ha...@gmail.com>.
FWIW, it might make sense to deprecate the DateField.dateToString() method in favor of the DateFormatter.parseDateString() one.

On Feb 3, 2014, at 8:20 AM, Harbs wrote:

> Thanks. That's much more robust. It might do what I need.
> 
> Harbs
> 
> On Feb 3, 2014, at 12:26 AM, Justin Mclean wrote:
> 
>> Hi,
>> 
>> You might want to look at parseDateString in DateFormatter.
>> 
>> Thanks,
>> Justin
> 


Re: Simple way to parse I18N dates?

Posted by Harbs <ha...@gmail.com>.
Thanks. That's much more robust. It might do what I need.

Harbs

On Feb 3, 2014, at 12:26 AM, Justin Mclean wrote:

> Hi,
> 
> You might want to look at parseDateString in DateFormatter.
> 
> Thanks,
> Justin


Re: Simple way to parse I18N dates?

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

You might want to look at parseDateString in DateFormatter.

Thanks,
Justin

Re: Simple way to parse I18N dates?

Posted by Harbs <ha...@gmail.com>.
I don't remember a discussion about this, but it could be I was not paying attention.

In my case, I have the luxury of knowing what the locale is supposed to be. Of course there are an incredible number of variables to deal with... :-(

Using Java sounds like an interesting approach. I'll have to look into that...

On Feb 2, 2014, at 1:28 PM, Paul Hastings wrote:

> On 2/2/2014 4:53 PM, Harbs wrote:
>> I just looked at DateField.stringToDate().
>> 
>> It looks like it only supports "M", "D" and "Y". That means it does not support weekdays or any time formatters.
>> 
>> I guess I'm going to have to roll my own function�
> 
> 
> parsing dates is another kind of "hell" i18n developers can fall into. if this is coming from a server might be easiest to use java (icu4j) to do the parsing & pass java epoch offsets back to the flex app to format based on user locale. letting folks enter dates arbitrarily is a tough nut to crack after the fact, especially lacking info about that user's locale.
> 
> btw wasn't there a discussion here last year about this?
> 
> 


Re: Simple way to parse I18N dates?

Posted by Paul Hastings <pa...@gmail.com>.
On 2/2/2014 4:53 PM, Harbs wrote:
> I just looked at DateField.stringToDate().
>
> It looks like it only supports "M", "D" and "Y". That means it does not support weekdays or any time formatters.
>
> I guess I'm going to have to roll my own function�


parsing dates is another kind of "hell" i18n developers can fall into. if this 
is coming from a server might be easiest to use java (icu4j) to do the parsing & 
pass java epoch offsets back to the flex app to format based on user locale. 
letting folks enter dates arbitrarily is a tough nut to crack after the fact, 
especially lacking info about that user's locale.

btw wasn't there a discussion here last year about this?



Re: Simple way to parse I18N dates?

Posted by Harbs <ha...@gmail.com>.
I just looked at DateField.stringToDate().

It looks like it only supports "M", "D" and "Y". That means it does not support weekdays or any time formatters.

I guess I'm going to have to roll my own function…

On Feb 1, 2014, at 8:10 PM, Christofer Dutz wrote:

> Hi Hemadri,
> 
> Thanks for that pointer. Seems to be what I've been looking for.
> 
> How about integrating this functionality into the DateFormat class ... for me this seems to be the most natural place to have it?
> 
> Chris
> 
> -----Ursprüngliche Nachricht-----
> Von: Hemadri Seelamsetty [mailto:hemadri.info@gmail.com] 
> Gesendet: Samstag, 1. Februar 2014 17:49
> An: users@flex.apache.org
> Betreff: Re: Simple way to parse I18N dates?
> 
> Chris,
> 
> You can also use the static methods of mx.controls.DateField Class.
> 
> Below are the signatures of the static methods
> 
> DateField.dateToString(value:Date, outputFormat:String):String DateField.stringToDate(valueString:String, inputFormat:String):Date
> 
> Example: var dob:Date = DateField.stringToDate("02/01/2014", "MM/DD/YYYY");
> 
> It can contain "M","D","Y", and delimiter and punctuation characters
> 
> 
> --
> Hemadri <http://hemadri.com>
> 
> 
> 
> On Sat, Feb 1, 2014 at 7:17 PM, Christofer Dutz
> <ch...@c-ware.de>wrote:
> 
>> Hi,
>> 
>> I am currently sort of stuck with implementing some functionality.
>> 
>> I know I can use a DateFormatter to define a formatted string from a 
>> given date, but I couldn't actually find something for the other way around.
>> The Java equivalent usually has a "parse" and a "format" method 
>> allowing to read a date from a string and to return a date and a 
>> format to serialize a date to a desired output format. It seems the 
>> Flex version is missing the parse part ... What do I have to use for this?
>> 
>> Chris
>> 


Re: Simple way to parse I18N dates?

Posted by Harbs <ha...@gmail.com>.
Funny that I need the same functionality at the same time…

I actually need to parse a date from an unknown format. This is obviously much more complex, because something like 1/2/14 could mean either January 2 or February 1 depending on the locale.

I do think this type of functionality belongs in DateFormat.

Harbs

On Feb 1, 2014, at 8:10 PM, Christofer Dutz wrote:

> Hi Hemadri,
> 
> Thanks for that pointer. Seems to be what I've been looking for.
> 
> How about integrating this functionality into the DateFormat class ... for me this seems to be the most natural place to have it?
> 
> Chris
> 
> -----Ursprüngliche Nachricht-----
> Von: Hemadri Seelamsetty [mailto:hemadri.info@gmail.com] 
> Gesendet: Samstag, 1. Februar 2014 17:49
> An: users@flex.apache.org
> Betreff: Re: Simple way to parse I18N dates?
> 
> Chris,
> 
> You can also use the static methods of mx.controls.DateField Class.
> 
> Below are the signatures of the static methods
> 
> DateField.dateToString(value:Date, outputFormat:String):String DateField.stringToDate(valueString:String, inputFormat:String):Date
> 
> Example: var dob:Date = DateField.stringToDate("02/01/2014", "MM/DD/YYYY");
> 
> It can contain "M","D","Y", and delimiter and punctuation characters
> 
> 
> --
> Hemadri <http://hemadri.com>
> 
> 
> 
> On Sat, Feb 1, 2014 at 7:17 PM, Christofer Dutz
> <ch...@c-ware.de>wrote:
> 
>> Hi,
>> 
>> I am currently sort of stuck with implementing some functionality.
>> 
>> I know I can use a DateFormatter to define a formatted string from a 
>> given date, but I couldn't actually find something for the other way around.
>> The Java equivalent usually has a "parse" and a "format" method 
>> allowing to read a date from a string and to return a date and a 
>> format to serialize a date to a desired output format. It seems the 
>> Flex version is missing the parse part ... What do I have to use for this?
>> 
>> Chris
>> 


AW: Simple way to parse I18N dates?

Posted by Christofer Dutz <ch...@c-ware.de>.
Hi Hemadri,

Thanks for that pointer. Seems to be what I've been looking for.

How about integrating this functionality into the DateFormat class ... for me this seems to be the most natural place to have it?

Chris

-----Ursprüngliche Nachricht-----
Von: Hemadri Seelamsetty [mailto:hemadri.info@gmail.com] 
Gesendet: Samstag, 1. Februar 2014 17:49
An: users@flex.apache.org
Betreff: Re: Simple way to parse I18N dates?

Chris,

You can also use the static methods of mx.controls.DateField Class.

Below are the signatures of the static methods

DateField.dateToString(value:Date, outputFormat:String):String DateField.stringToDate(valueString:String, inputFormat:String):Date

Example: var dob:Date = DateField.stringToDate("02/01/2014", "MM/DD/YYYY");

It can contain "M","D","Y", and delimiter and punctuation characters


--
Hemadri <http://hemadri.com>



On Sat, Feb 1, 2014 at 7:17 PM, Christofer Dutz
<ch...@c-ware.de>wrote:

> Hi,
>
> I am currently sort of stuck with implementing some functionality.
>
> I know I can use a DateFormatter to define a formatted string from a 
> given date, but I couldn't actually find something for the other way around.
> The Java equivalent usually has a "parse" and a "format" method 
> allowing to read a date from a string and to return a date and a 
> format to serialize a date to a desired output format. It seems the 
> Flex version is missing the parse part ... What do I have to use for this?
>
> Chris
>

Re: Simple way to parse I18N dates?

Posted by Hemadri Seelamsetty <he...@gmail.com>.
Chris,

You can also use the static methods of mx.controls.DateField Class.

Below are the signatures of the static methods

DateField.dateToString(value:Date, outputFormat:String):String
DateField.stringToDate(valueString:String, inputFormat:String):Date

Example: var dob:Date = DateField.stringToDate("02/01/2014", "MM/DD/YYYY");

It can contain "M","D","Y", and delimiter and punctuation characters


--
Hemadri <http://hemadri.com>



On Sat, Feb 1, 2014 at 7:17 PM, Christofer Dutz
<ch...@c-ware.de>wrote:

> Hi,
>
> I am currently sort of stuck with implementing some functionality.
>
> I know I can use a DateFormatter to define a formatted string from a given
> date, but I couldn't actually find something for the other way around.
> The Java equivalent usually has a "parse" and a "format" method allowing
> to read a date from a string and to return a date and a format to serialize
> a date to a desired output format. It seems the Flex version is missing the
> parse part ... What do I have to use for this?
>
> Chris
>