Daylight Savings Calculation: Off by a hour?

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

Daylight Savings Calculation: Off by a hour?

Mei Chan
My daylight savings calculation using Joda seems to be off by hour and was wondering if someone could enlighten me on what the issue may be.  I'm using joda version 2.0
 
Date newDate = new DateTime(System.currentTimeMillis()).plusWeeks(12).toDate();
 
I would of expected something like the following the newly calculated date to be (taking in account that we would be in daylight savings)
Tue May 22 01:49:16 PDT 2012
 
However, I get the following instead which seems to be off by an hour.
Tue May 22 00:49:16 PDT 2012

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Daylight Savings Calculation: Off by a hour?

jodastephen
On 24 February 2012 09:08, Mei Chan <[hidden email]> wrote:

> My daylight savings calculation using Joda seems to be off by hour and was
> wondering if someone could enlighten me on what the issue may be.  I'm using
> joda version 2.0
>
> Date newDate = new
> DateTime(System.currentTimeMillis()).plusWeeks(12).toDate();
>
> I would of expected something like the following the newly calculated date
> to be (taking in account that we would be in daylight savings)
> Tue May 22 01:49:16 PDT 2012
>
> However, I get the following instead which seems to be off by an hour.
> Tue May 22 00:49:16 PDT 2012

Any time that you convert from a Joda-Time object to a java.util.Date
you add uncertainty. j.u.Date uses the JDK time-zone data, whereas
Joda-Time has its own separate data. Also, j.u.Date always prints the
time in the default time zone.

Try printing out the results of
- DateTimeZone.getDefault()
- TimeZone.getDefault()
- the DateTime you create
- the value of getZone() on the DateTime

Somewhere there will be a difference.

Stephen

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Daylight Savings Calculation: Off by a hour?

Mei Chan
But even without the conversion toDate(), the time still looks to be off by an hour since 12 weeks later, we will be in daylight savings time therefore the second value should of been an hour ahead, or am I missing something here?
 
DateTime currentTime = new DateTime(System.currentTimeMillis());      
     2012-02-24T08:42:38.770-08:00
currentTime.plusWeeks(12);
     2012-05-22T08:42:38.770-07:00
 
Interesting enough everything looks to be the same, here is the information printed out:
 
DateTimeZone.getDefault(): America/Los_Angeles
    TimeZone.getDefault(): sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
   (DateTime).getZone(): America/Los_Angeles

From: Stephen Colebourne <[hidden email]>
To: Mei Chan <[hidden email]>; Discussion of the Joda project <[hidden email]>
Sent: Friday, February 24, 2012 2:50 AM
Subject: Re: [Joda-interest] Daylight Savings Calculation: Off by a hour?

On 24 February 2012 09:08, Mei Chan <[hidden email]> wrote:

> My daylight savings calculation using Joda seems to be off by hour and was
> wondering if someone could enlighten me on what the issue may be.  I'm using
> joda version 2.0
>
> Date newDate = new
> DateTime(System.currentTimeMillis()).plusWeeks(12).toDate();
>
> I would of expected something like the following the newly calculated date
> to be (taking in account that we would be in daylight savings)
> Tue May 22 01:49:16 PDT 2012
>
> However, I get the following instead which seems to be off by an hour.
> Tue May 22 00:49:16 PDT 2012

Any time that you convert from a Joda-Time object to a java.util.Date
you add uncertainty. j.u.Date uses the JDK time-zone data, whereas
Joda-Time has its own separate data. Also, j.u.Date always prints the
time in the default time zone.

Try printing out the results of
- DateTimeZone.getDefault()
- TimeZone.getDefault()
- the DateTime you create
- the value of getZone() on the DateTime

Somewhere there will be a difference.

Stephen



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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: Daylight Savings Calculation: Off by a hour?

Mark Carroll
On 02/24/2012 12:32 PM, Mei Chan wrote:
> But even without the conversion toDate(), the time still looks to be off
> by an hour since 12 weeks later, we will be in daylight savings time
> therefore the second value should of been an hour ahead, or am I missing
> something here?
> DateTime currentTime = new DateTime(System.currentTimeMillis());
> 2012-02-24T08:42:38.770-08:00
> currentTime.plusWeeks(12);
> 2012-05-22T08:42:38.770-07:00

plusWeeks will try to avoid messing with the time fields if possible: it
thinks in terms of calendar days. plusHours(12*7*24) may do what you
expected.

Mark

--
Mark Carroll
Software Engineer
[hidden email]
http://www.vecna.com/

Cambridge Research Laboratory
Vecna Medical
36 Cambridge Park Drive
Cambridge, MA 02140
Phone: (617) 864-0636
Fax: (617) 864-0638

Better Technology, Better World (TM)

The contents of this message may be privileged and confidential.
Therefore, if this message has been received in error, please delete it
without reading it. Your receipt of this message is not intended to
waive any applicable privilege. Please do not disseminate this message
without the permission of the author.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...