User:Connel MacKenzie/timezones

For an IRC chatbot, I needed to lookup what timezones existed. This proved to be much more challenging than one might expect. The "timezone name" allowed is an overlapping of several (conflicting) standards, apparently. The chatbot wants only the longest of those names (region/city.) Sigh. Well, very surprising to see missing TLAs in this list. Dunno if we want the ones containing slashes - on Wiktionary those are positively not allowed, yet this is (presumably) how people might look them up. --Connel MacKenzie 04:39, 13 January 2008 (UTC)

Code

edit

Java

edit
import java.util.TimeZone;
class timezones {
  public static void main(String args[]) {
    String[] zoneIds = TimeZone.getAvailableIDs();
    for (int i=0; i<zoneIds.length; i++) {
      System.out.println( zoneIds[i] );
    }
  }
}

Groovy

edit
def tzs = TimeZone.availableIDs.collect { TimeZone.getTimeZone(it) }
tzs.each { tz ->
    println "* [[$tz.ID]]"
    def names = [] as SortedSet
    [ TimeZone.SHORT, TimeZone.LONG ].each { style ->
        names << tz.getDisplayName(false, style)
        if (tz.useDaylightTime()) {
            names << tz.getDisplayName(true, style)
        }
    }
    names.each { name ->
        println "** [[$name]]"
    }
}

Results

edit