Problem with parseDateTime and daylight in Brazil

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem with parseDateTime and daylight in Brazil

Leandro Ferro Luzia
Hi.
I'm getting the following error when I try to run the code

public static void main(String[] args) {
        // -Duser.timezone=Brazil/East
        DateTimeFormatter dtf = DateTimeFormat.forPattern( "dd/MM/yyyy" );
       
        LocalDate b = dtf.parseDateTime( args[0] ).toLocalDate();
       
        System.out.println( b );
}

Exception in thread "main" java.lang.IllegalArgumentException: Cannot parse "19/10/2008": Illegal instant due to time zone offset transition (America/Sao_Paulo)
    at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:336)
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:662)
    at joda.Teste.main(Teste.java:22)


The argument to the program is 19/10/2008, the day in which our daylight starts here.

I can't figure out how to fix this.
Is there any  way to parse a date other than that?

Thanks!

--
-----------------------------------------
Leandro Ferro Luzia
C.Computação - USP - 2004
-----------------------------------------
"Computer science is no more about computers than astronomy is about telescopes." - Dijkstra

"There's nothing remarkable about it.
All one has to do is hit the right keys at the right time and the instrument  plays itself" - Bach

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with parseDateTime and daylight in Brazil

Youngkin, Richard Shaffer (Rich)

Leandro,

 

Chances are your code tries to create Oct 19 2008 at Midnight, which happens to be when the Sao Paulo daylight savings time transition occurs.  This error is telling you that this time (instant) doesn’t exist.  At the DST transition to time moves from Oct 18 23:59:50 to Oct 18 01:00:00, midnight is skipped.  I suspect your input argument equals Oct 18 00:00:00.  Check out the thread at http://sourceforge.net/mailarchive/message.php?msg_id=52BAF2247695064397E0B142F7B372980142DF70%40306181ANEX3.global.avaya.com.  This may provide some more insight into how to resolve your problem.

 

Hope this helps.


Cheers,
Rich

 


From: Leandro Ferro Luzia [mailto:[hidden email]]
Sent: Thursday, October 16, 2008 8:23 AM
To: [hidden email]
Subject: [Joda-interest] Problem with parseDateTime and daylight in Brazil

 

Hi.
I'm getting the following error when I try to run the code

public static void main(String[] args) {
        // -Duser.timezone=Brazil/East
        DateTimeFormatter dtf = DateTimeFormat.forPattern( "dd/MM/yyyy" );
       
        LocalDate b = dtf.parseDateTime( args[0] ).toLocalDate();
       
        System.out.println( b );
}

Exception in thread "main" java.lang.IllegalArgumentException: Cannot parse "19/10/2008": Illegal instant due to time zone offset transition (America/Sao_Paulo)
    at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:336)
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:662)
    at joda.Teste.main(Teste.java:22)


The argument to the program is 19/10/2008, the day in which our daylight starts here.

I can't figure out how to fix this.
Is there any  way to parse a date other than that?

Thanks!

--
-----------------------------------------
Leandro Ferro Luzia
C.Computação - USP - 2004
-----------------------------------------
"Computer science is no more about computers than astronomy is about telescopes." - Dijkstra

"There's nothing remarkable about it.
All one has to do is hit the right keys at the right time and the instrument  plays itself" - Bach


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...