[Advanced-java] Daylight saving
dharmendra.sharan@ubs.com
dharmendra.sharan at ubs.com
Fri Jul 18 15:45:30 2003
Hi Venkat,
I think you need to look *closely* at java.util.SimpleTimeZone
The point I need to make is that this class allows you to specify the Daylight Savings Time for any given TimeZone. So, *when* the Daylight Savings takes effect for each TimeZone is not part of the API, it is left to the user to create the appropriate SimpleTimeZone object. SimpleTimeZone API does provide initialization parameters and methods to allow you to specify the Start date and time when Daylight Savings is starts and similary for when the Daylight Savings ends. (which you refer in your email as the "forward" and "backward" dates)
Should Java have all possible DaylightSavings Start date-time and end Date-times for each TimeZone, stored as part of a SimpleTimeZone or some other class? And I think your point of view is yes it should, however even if it doesn't it *does* provide an easy to use API for creating such a TimeZone as required, I don't know the reason why this approach was taken (as I'm not yet involved in the Java Community process!), If I have to take a guess then my guess would be, perhaps the Daylight Savings Time has not been consistent enough *historically* for a given TimeZone to allow for such crisp start/end date-time rules for each TimeZone to be framed within the SimpleTimeZone class. I encourage you to look for answers... If anyone has the reasoning for the same please enlighten us. Thanks!
<snippet>
// examples of creating SimpleTimeZone objects for a given TimeZone
// with start date-time and end date-time rules for Daylight Savings.
// Base GMT offset: -8:00
// DST starts: at 2:00am in standard time
// on the first Sunday in April
// DST ends: at 2:00am in daylight time
// on the last Sunday in October
// Save: 1 hour
SimpleTimeZone(-28800000, // Base GMT offset in milliseconds
"America/Los_Angeles", // given TimeZone for which we are specifying DST rules
Calendar.APRIL, 1, -Calendar.SUNDAY, // Calendar date when Daylight Savings starts
7200000, // time in milliseconds when the Daylight Savings starts
Calendar.OCTOBER, -1, Calendar.SUNDAY, // Calendar date when Daylight Savings ends
7200000, // time in milliseconds when the Daylight Savings starts
3600000) // time in milliseconds to be applied for Daylight savings
</snipper>
note: see http://java.sun.com/j2se/1.4.2/docs/api/java/util/SimpleTimeZone.html for details
Hope this explains.
Regards,
Dharmendra
ps: have a good day!
-----Original Message-----
From: K.P.Venkatakrishnan [mailto:venkatakrishnan.kan@wipro.com]
Sent: Friday, July 18, 2003 12:04 AM
To: Sharan, Dharmendra
Subject: FW: [Advanced-java] Daylight saving
Hi Dharmendra,
What I want is the dates and not the OFFSET. Please see the
explanation I gave to Matt below. Anyway, I have decided to write some
Code of my own to achieve this since Java doesn't provide for it.
Regards,
Venkat.
-----Original Message-----
From: K.P.Venkatakrishnan [mailto:venkatakrishnan.kan@wipro.com]
Sent: Thursday, July 17, 2003 6:28 PM
To: 'Salerno Matthew L Contr HQ SSG/SWDUB'
Subject: RE: [Advanced-java] Daylight saving
Hi Matt,
My code would look something like this.
Timezone tz = Timezone.getTimezone('timezone-name');
Date fwDate = tz.getForwardDaylightSwitchingDay(int year);
Date bwDate = tz.getBackwardDaylightSwitchingDay(int year);
What I expect in these methods is:
Date getForwardDaylightSwitchingDay(int year){
int day usePrivateDateToGetThisDate(int startMonth, int
startDay,
int
startDayOfWeek);
//Note: startMonth, startDay, startDayOfWeek are private members
//of SimpleTimezone, not Timezone
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year,startMonth,day);
Date retDate = cal.getTime();
}
Similar implementation for getBackwardDaylightSwitchingDay(int year).
Hope I am clear.
I am quite surprised that Java doesn't provide such an interface.
Regards,
Venkat.
-----Original Message-----
From: Salerno Matthew L Contr HQ SSG/SWDUB
[mailto:Matthew.Salerno@Gunter.AF.mil]
Sent: Thursday, July 17, 2003 6:07 PM
To: venkatakrishnan.kan@wipro.com
Subject: RE: [Advanced-java] Daylight saving
I have done work with timezones on a project; I am not sure what
exactly you are trying to do... Can you send a code snippet of what you
have now?
Matt
-----Original Message-----
From: advanced-java-bounces@lists.xcf.berkeley.edu
[mailto:advanced-java-bounces@lists.xcf.berkeley.edu] On Behalf Of
K.P.Venkatakrishnan
Sent: Thursday, July 17, 2003 6:16 AM
To: advanced-java@lists.xcf.berkeley.edu
Subject: RE: [Advanced-java] Daylight saving
Yes, I have used them. What I want is the dates and not the duration of
fwd/bwd switch.
Regards,
Venkat.
-----Original Message-----
From: advanced-java-bounces@lists.xcf.berkeley.edu
[mailto:advanced-java-bounces@lists.xcf.berkeley.edu] On Behalf Of Jukka
Sundberg
Sent: Thursday, July 17, 2003 2:47 PM
To: advanced-java@lists.xcf.berkeley.edu
Subject: Re: [Advanced-java] Daylight saving
Have you checked super class methods for SimpleTimeZone,
For example, TimeZone.getTimeZone("GMT-8").getID() returns
"GMT-08:00". and also method
getDSTSavings()
K.P.Venkatakrishnan wrote:
> Hi,
>
> Is it possible to get the forward and backward switching
> 'dates' for a given timezone using Java.
>
> SimpleTimeZone doesn't seem to provide this. We can only
set
> the rules for the timezone (not even
>
> get/read the rule of a timezone) and verify whether a date falls in
DST
> or not.
>
>
>
> Thanks and regards,
>
> Venkat.
>
>
**************************Disclaimer************************************
>
> Information contained in this E-MAIL being proprietary to Wipro
Limited is
> 'privileged' and 'confidential' and intended for use only by the
individual
> or entity to which it is addressed. You are notified that any use,
copying
> or dissemination of the information contained in the E-MAIL in any
manner
> whatsoever is strictly prohibited.
>
>
************************************************************************
***
>
_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
**************************Disclaimer************************************
Information contained in this E-MAIL being proprietary to Wipro Limited
is
'privileged' and 'confidential' and intended for use only by the
individual or entity to which it is addressed. You are notified that
any use, copying
or dissemination of the information contained in the E-MAIL in any
manner
whatsoever is strictly prohibited.
************************************************************************
***
_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
**************************Disclaimer************************************
Information contained in this E-MAIL being proprietary to Wipro Limited is
'privileged' and 'confidential' and intended for use only by the individual
or entity to which it is addressed. You are notified that any use, copying
or dissemination of the information contained in the E-MAIL in any manner
whatsoever is strictly prohibited.
***************************************************************************
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.