Re: Simplified TimeZone
In article
<1675602a-585a-4b9d-a08b-294d109066e1@k30g2000hse.googlegroups.com>,
Dr J R Stockton <J.R.Stockton@physics.org> wrote:
On Sep 27, 7:36?pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
I am disappointed that the class does not offer getStartYear().
A routine getStartYear() can hardly be entirely satisfactory of
itself.
Yes, I was motivated more by curiosity than practical benefit. Indeed,
on my implementation, the code below reveals that startYear is zero
throughout. Moreover, reflection shows that the (private) TimeZone
parameters do not include a year.
[...]
other locales will change in the future. I would expect your
software vendor to offer updates, accordingly. Such updates would be
essential to correct operation, irrespective of when you use your
computer.
Not entirely irrespective; one might choose to keep one's computer on
permanent GMT, regardless of locality.
Well, if you live "near London, UK" you already do! I mean if you want
to ring up a friend in an unfamiliar time zone. You ask your computer
what time it is there. The wrong answer will wake the whole house. :-)
<code>
import java.lang.reflect.Field;
import java.util.regex.*;
import java.util.*;
//import sun.util.calendar.ZoneInfo;
public class Timezone {
public static void main(String[] args) {
String[] tza = TimeZone.getAvailableIDs();
Arrays.sort(tza, new Comparator<String>() {
public int compare(String s1, String s2) {
return s1.compareTo(s2);
}
});
Pattern sy = Pattern.compile("^.*(startYear=\\d).*$");
for (int i = 0; i < tza.length; i++) {
TimeZone tz = TimeZone.getTimeZone(tza[i]);
String abbr = tz.getDisplayName(false, TimeZone.SHORT);
String name = tz.getDisplayName(false, TimeZone.LONG);
Matcher m = sy.matcher(tz.toString());
if (m.find()) {
System.out.println(tza[i]
+ " : " + abbr
+ " : " + name
+ " : " + m.group(1));
}
}
printTzParams("Europe/London");
printTzParams("Europe/Zurich");
printTzParams("US/Eastern");
printTzParams("US/Pacific");
}
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[i].getName())) {
try {
fields[i].setAccessible(true);
int[] ia = (int[]) fields[i].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);
}
}
}
}
}
</code>
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews