Joda equivalent of getDSTSavings

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

Joda equivalent of getDSTSavings

Matthew McCawley

I searched through the mailer archives, but I couldn't find anything about this. It was also asked here with no answer. http://stackoverflow.com/questions/4870637/what-is-the-joda-time-equivalent-of-few-jdk-timezone-functions 

I'd rather not use the method at all, but I'm trying to retrofit Joda to some legacy code that uses it. Subtracting the time zone's DST and standard offsets would get the equivalent (and probably be more accurate, anyway), but I can't find a clean way to get the DST offset without having to go through transitions and check.

On a related note, does getStandardOffset return the same value regardless of the instant passed in? If so, why does it take an argument?

Thanks,
Matthew McCawley
------------------------------------------------------------------------------
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/
_______________________________________________
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: Joda equivalent of getDSTSavings

jodastephen
On 2 May 2012 15:10, Matthew McCawley <[hidden email]> wrote:
> I searched through the mailer archives, but I couldn't find anything about
> this. It was also asked here with no answer.
> http://stackoverflow.com/questions/4870637/what-is-the-joda-time-equivalent-of-few-jdk-timezone-functions
>
> I'd rather not use the method at all, but I'm trying to retrofit Joda to
> some legacy code that uses it. Subtracting the time zone's DST and standard
> offsets would get the equivalent (and probably be more accurate, anyway),
> but I can't find a clean way to get the DST offset without having to go
> through transitions and check.

Well, getDSTSavings() is the difference between getStandardOffset()
and getOffset() for any given instant.

> On a related note, does getStandardOffset return the same value regardless
> of the instant passed in? If so, why does it take an argument?

The standard offset can and does changes over time. For example, if
the UK moved to have its clocks on the same time as France and
Germany, the standard offset would change from zero to one hour.

Stephen

------------------------------------------------------------------------------
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/
_______________________________________________
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: Joda equivalent of getDSTSavings

Matthew McCawley

Stephen Colebourne <[hidden email]> wrote on 05/04/2012 12:42:28 PM:

> Well, getDSTSavings() is the difference between getStandardOffset()
> and getOffset() for any given instant.

From the TimeZone source:

public int getDSTSavings()
{
    return useDaylightTime () ? 3600000 : 0;
}

Not accurate by any means, but it's the amount by which the offset will change (in most cases). It is not influenced by the current instant. This is what I came up with for joda to accomplish the same thing.

public static int getDSTSavings(String tz)
{
    DateTimeZone dtz = DateTimeZone.forID( tz );
    DateTime dt = new DateTime( dtz );
    if ( dtz.isStandardOffset( dt.getMillis() ) ) {
        int dstoffset = dtz.getOffset( dtz.nextTransition( dt.getMillis() ) );
        return dstoffset - dtz.getStandardOffset( dt.getMillis() );
    } else
        return dtz.getOffset( dt ) - dtz.getStandardOffset( dt.getMillis() );
}

> The standard offset can and does changes over time. For example, if
> the UK moved to have its clocks on the same time as France and
> Germany, the standard offset would change from zero to one hour.

That makes sense.

Matthew
------------------------------------------------------------------------------
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/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Loading...