DST Start date

R

Roedy Green

Is there a simpler way to find out when DST starts in a given year
than stepping through the year day by day calling
TimeZone.inDaylightTime( Date )?
--
Roedy Green Canadian Mind Products
http://mindprod.com

When you can’t find a bug, you are probably looking in the wrong place. When you can’t find your glasses, you don’t keep scanning the same spot because you are convinced that is where you left them.
~ Roedy
 
A

Arne Vajhøj

Roedy said:
Is there a simpler way to find out when DST starts in a given year
than stepping through the year day by day calling
TimeZone.inDaylightTime( Date )?

No, that information is private in the SimpleTimeZone class.

Arne
 
E

Eric Sosman

Roedy said:
Is there a simpler way to find out when DST starts in a given year
than stepping through the year day by day calling
TimeZone.inDaylightTime( Date )?

"Simpler?" Probably not. "Quicker?" Well, you could
do a kind of binary search, starting with the assumption that
DST begins in the first half of the year. 7 < lg(183) < 8.
 
R

Roedy Green

"Simpler?" Probably not. "Quicker?" Well, you could
do a kind of binary search, starting with the assumption that
DST begins in the first half of the year. 7 < lg(183) < 8.

There is the complication of the southern hemisphere. In this case
speed is not a concern.

code is posted at
https://wush.net/websvn/mindprod/fi...om/mindprod/holidays/DaylightSavingStart.java
https://wush.net/websvn/mindprod/fi.../com/mindprod/holidays/DaylightSavingEnd.java

It is a bit cryptic. It fits into a template for describing holidays
in general. It uses BigDate.
--
Roedy Green Canadian Mind Products
http://mindprod.com

When you can’t find a bug, you are probably looking in the wrong place. When you can’t find your glasses, you don’t keep scanning the same spot because you are convinced that is where you left them.
~ Roedy
 
J

John B. Matthews

Arne Vajhøj said:
No, that information is private in the SimpleTimeZone class.

This is correct, but one can examine the values in the private
simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
meaning of the parameters are a function of which SimpleTimeZone
constructor was used to create the ZoneInfo, as described here:

<http://www.docjar.com/html/api/sun/util/calendar/ZoneInfo.java.html>

<method>
private static void printTzParams (String id) {
TimeZone tz = TimeZone.getTimeZone(id);
String name = "simpleTimeZoneParams";
final Field fields[] = tz.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (name.equals(fields.getName())) {
try {
fields.setAccessible(true);
int[] ia = (int[]) fields.get(tz);
System.out.print("Params for "
+ tz.getID() + ": ");
for (int j = 0; j < ia.length; j++) {
System.out.print(ia[j] + " ");
}
System.out.println();
}
catch (IllegalAccessException e) {
System.err.println("IllegalAccess: " + name);
}
}
}
}
</method>

<example>
Params for Europe/London: 2 -1 1 3600000 2 9 -1 1 3600000 2
Params for Europe/Zurich: 2 -1 1 3600000 2 9 -1 1 3600000 2
Params for US/Eastern: 2 8 -1 7200000 10 1 -1 7200000
Params for US/Pacific: 2 8 -1 7200000 10 1 -1 7200000
</example>
 
D

Dr J R Stockton

In comp.lang.java.programmer message <[email protected]
september.org>, Sat, 3 Oct 2009 21:48:51, Eric Sosman <esosman@ieee-dot-
org.invalid> posted:
"Simpler?" Probably not. "Quicker?" Well, you could
do a kind of binary search, starting with the assumption that
DST begins in the first half of the year. 7 < lg(183) < 8.

I do similar, in JavaScript, calling the misnamed getTimezoneOffset(),
in <URL:http://www.merlyn.demon.co.uk/js-date5.htm> and its include
files, to get the change to the nearest few seconds then rounded to the
minute. Call it first for January 1 and July 1; if they are the same,
there's no Summer time; if they differ the sign tells the hemisphere.

It may be unwise, though, to assume that the apparent time status only
changes twice a year in all locations and all systems. At least one
JavaScript browser makes six changes per year, outside 1970 to 2038.
 
R

Roedy Green

This is correct, but one can examine the values in the private
simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
meaning of the parameters are a function of which SimpleTimeZone
constructor was used to create the ZoneInfo, as described here:

Was the idea to make the timezone info table driven, but leave a hole
open in case there were ever a case the table scheme could not handle?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Smart data structures and dumb code works a lot better than the other way around.
~ Eric S. Raymond The Cathedral and the Bazaar
 
R

Roedy Green

At least one
JavaScript browser makes six changes per year, outside 1970 to 2038.

What timezone is that?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Smart data structures and dumb code works a lot better than the other way around.
~ Eric S. Raymond The Cathedral and the Bazaar
 
J

John B. Matthews

Roedy Green said:
Was the idea to make the timezone info table driven, but leave a hole
open in case there were ever a case the table scheme could not handle?

I guess that's possible. I thought it was to simplify SimpleTimeZone,
which "cannot handle historical changes in the offset from GMT and the
daylight saving schedule," while still supplying historical daylight
saving time information to TimeZone#getOffset() and
Calendar#get(Calendar.ZONE_OFFSET), when implemented.

<http://java.sun.com/javase/6/docs/api/java/util/TimeZone.html>
<http://java.sun.com/javase/6/docs/api/java/util/Calendar.html>
 
D

Dr J R Stockton

In comp.lang.java.programmer message <dd0kc5tovakakhorujt5db4l0s9ssia7ov
@4ax.com>, Mon, 5 Oct 2009 07:25:09, Roedy Green <[email protected]
om.invalid> posted:
What timezone is that?

GMT+0, perhaps only GMT+0 - and of course excluding Iceland & Africa.
See <URL:http://www.merlyn.demon.co.uk/js-datex.htm>, and that page's
links to forestall other queries.

One should really test all systems for the middle of every quarter-hour
within the date range of interest, and a reasonable number of samples
outside that range; and do so for all distinct locations and with the
computer "in" both Summer & Winter. With a modern machine, that should
not take all that long for a single location. I've added it.
 
A

Arne Vajhøj

John said:
Arne Vajhøj said:
No, that information is private in the SimpleTimeZone class.

This is correct, but one can examine the values in the private
simpleTimeZoneParams array of sun.util.calendar.ZoneInfo. The number and
meaning of the parameters are a function of which SimpleTimeZone
constructor was used to create the ZoneInfo, as described here:

<http://www.docjar.com/html/api/sun/util/calendar/ZoneInfo.java.html>

<method>
private static void printTzParams (String id) {
TimeZone tz = TimeZone.getTimeZone(id);
String name = "simpleTimeZoneParams";
final Field fields[] = tz.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (name.equals(fields.getName())) {
try {
fields.setAccessible(true);
int[] ia = (int[]) fields.get(tz);
System.out.print("Params for "
+ tz.getID() + ": ");
for (int j = 0; j < ia.length; j++) {
System.out.print(ia[j] + " ");
}
System.out.println();
}
catch (IllegalAccessException e) {
System.err.println("IllegalAccess: " + name);
}
}
}
}
</method>

<example>
Params for Europe/London: 2 -1 1 3600000 2 9 -1 1 3600000 2
Params for Europe/Zurich: 2 -1 1 3600000 2 9 -1 1 3600000 2
Params for US/Eastern: 2 8 -1 7200000 10 1 -1 7200000
Params for US/Pacific: 2 8 -1 7200000 10 1 -1 7200000
</example>


It should also be possible to do the same for SimpleTimeZone,
but given that a usable workaround exists, then I would avoid
that type of code.

Arne
 
J

John B. Matthews

[Introspective approach omitted]
It should also be possible to do the same for SimpleTimeZone,
but given that a usable workaround exists, then I would avoid
that type of code.

On reflection*, you're right. The implementation is private, perhaps
because it may change. Peeking under the hood is instructive, but
probably not dependable.

*In the sense of having thought about it, as well as the technique.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top