It looks setLenient(FALSE) works. Thank you very much for your help,
/yasu
On Sep 18, 2012, at 11:41 AM, Steven R. Loomis wrote:
> If you add:
>
> format_obj.setLenient(FALSE);
>
> It will disable leniency concerning the separators and your parse will fail. The separators are not ignored, however, in lenient mode (the default), ICU may select equivalent grouping separators. so ##/##/#### vs ##.##.#### vs ##-##-#### etc.
>
> Hope this helps,
> -steven
>
> On Tue, Sep 18, 2012 at 7:51 AM, Yasuhiro Hara <Yasuhiro.Hara@...> wrote:
> Hi,
>
> We used to use ICU 4.4.2, and we have just upgraded to 49.1.2. Then I noticed that SimpleDateFormat::parse() changed its behavior. I am wondering if it is expected behavior or not.
>
> Here is what I saw.
> I tried to parse "10/11/2013" with "dd-MM-yyyy" using SimpleDateFormat::parse(). The parse operation failed with 4.4.2, but it succeeded with 49.1.2. It seems 4.4.2 respects the separator character in the pattern, but 49.1.2 sometimes ignore it.
>
> << 49.1.2 >>
> Parsing 10/11/2013 with dd-MM-yyyy
> Nov 10, 2013 12:00:00 AM <== different result
>
> Parsing 10/11/2013 with dd-mm-yyyy
> Parse failure
>
> << 4.4.2 >>
> Parsing 10/11/2013 with dd-MM-yyyy
> Parse failure
>
> Parsing 10/11/2013 with dd-mm-yyyy
> Parse failure
>
> I listed some other cases as the following.
>
> << 49.1.2 >>
> Parsing 09:05:54 with hh:mm:ss
> Jan 1, 1970 9:05:54 AM
>
> Parsing 09:05:54 with hh/mm/ss
> Jan 1, 1970 9:05:54 AM <== different result
>
> Parsing 10:11:2013 with dd/mm/yyyy
> Parse failure
>
> Parsing 10:11:2013 with dd/MM/yyyy
> Parse failure
>
> Parsing 10.11.2013 with dd/mm/yyyy
> Jan 10, 2013 12:11:00 AM <== different result
>
> Parsing 10.11.2013 with dd/MM/yyyy
> Nov 10, 2013 12:00:00 AM <== different result
>
> << 4.4.2 >>
> Parsing 09:05:54 with hh:mm:ss
> Jan 1, 1970 9:05:54 AM
>
> Parsing 09:05:54 with hh/mm/ss
> Parse failure
>
> Parsing 10:11:2013 with dd/mm/yyyy
> Parse failure
>
> Parsing 10:11:2013 with dd/MM/yyyy
> Parse failure
>
> Parsing 10.11.2013 with dd/mm/yyyy
> Parse failure
>
> Parsing 10.11.2013 with dd/MM/yyyy
> Parse failure
>
>
> I attached the simplified example code for this experiment. By the way, it looks like the behavior was already changed in 4.8.1.
>
> Best reagards,
> /yasu
>
>
> void parse_data(const std::string &format, const std::string &data)
> {
> std::cout << std::endl << "Parsing " << data << " with " << format << std::endl;
>
> UnicodeString dt_format(format.c_str());
> UnicodeString dt_data(data.c_str());
>
> UErrorCode status = U_ZERO_ERROR;
> SimpleDateFormat format_obj(dt_format, Locale::getUS(), status);
> if (U_FAILURE(status))
> {
> std::cout << "SimpleDateFormat object creation failure" << std::endl;
> return;
> }
>
> status = U_ZERO_ERROR;
> UDate dt = format_obj.parse(dt_data, status);
> if (U_FAILURE(status))
> {
> std::cout << "Parse failure" << std::endl;
> return;
> }
>
> print_data(dt); // no code added in this message
> return;
> }
>
> int main()
> {
> std::string date_data("10/11/2013");
> parse_data("dd-MM-yyyy", date_data);
> parse_data("dd-mm-yyyy", date_data);
>
> return 0;
> }
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> icu-support mailing list - icu-support@...
> To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support
> Archives/Project Info: http://site.icu-project.org/contacts
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
> icu-support mailing list - icu-support@...
> To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support
> Archives/Project Info: http://site.icu-project.org/contacts
|