Java Code Examples for org.joda.time.DateTimeZone#getAvailableIDs()

The following examples show how to use org.joda.time.DateTimeZone#getAvailableIDs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHiveUtil.java    From presto with Apache License 2.0 5 votes vote down vote up
public static DateTimeZone nonDefaultTimeZone()
{
    String defaultId = DateTimeZone.getDefault().getID();
    for (String id : DateTimeZone.getAvailableIDs()) {
        if (!id.equals(defaultId)) {
            DateTimeZone zone = DateTimeZone.forID(id);
            if (zone.getStandardOffset(0) != 0) {
                return zone;
            }
        }
    }
    throw new IllegalStateException("no non-default timezone");
}
 
Example 2
Source File: JiraProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
NativeImageResourceBuildItem nativeImageResources() {
    // Add Joda timezone resources into the native image as it is required by com.atlassian.jira.rest.client.internal.json.JsonParseUtil
    List<String> timezones = new ArrayList<>();
    for (String timezone : DateTimeZone.getAvailableIDs()) {
        String[] zoneParts = timezone.split("/");
        if (zoneParts.length == 2) {
            timezones.add(String.format("org/joda/time/tz/data/%s/%s", zoneParts[0], zoneParts[1]));
        }
    }
    return new NativeImageResourceBuildItem(timezones);
}
 
Example 3
Source File: ParseTime.java    From h2o-2 with Apache License 2.0 5 votes vote down vote up
public static void setTimezone(String tz) {
  Set<String> idSet = DateTimeZone.getAvailableIDs();
  if(idSet.contains(tz))
    _timezone = DateTimeZone.forID(tz);
  else
    Log.err("Attempted to set unrecognized timezone: "+ tz);
}
 
Example 4
Source File: ParseTime.java    From h2o-2 with Apache License 2.0 5 votes vote down vote up
public static String listTimezones() {
  DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter();
  Set<String> idSet = DateTimeZone.getAvailableIDs();
  Map<String, String> tzMap = new TreeMap();
  Iterator<String>  it = idSet.iterator();
  String id, cid, offset, key, output;
  DateTimeZone tz;
  int i = 0;
  long millis = System.currentTimeMillis();


  // collect canonical and alias IDs into a map
  while (it.hasNext()) {
    id = it.next();
    tz = DateTimeZone.forID(id);
    cid = tz.getID();
    offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis));
    key = offset + " " + cid;
    if (id == cid) { // Canonical ID
      if (!tzMap.containsKey(key)) tzMap.put(key, "");
    }  else {// alias ID
      if (!tzMap.containsKey(key)) tzMap.put(key, id);
      else tzMap.put(key,  tzMap.get(key) + ", " + id);
    }
  }

  // assemble result
  output = "StandardOffset CanonicalID, Aliases\n";
  for (Map.Entry<String, String> e : tzMap.entrySet())
    output += e.getKey() + e.getValue()+"\n";

  return output;
}
 
Example 5
Source File: SetTimezone.java    From h2o-2 with Apache License 2.0 5 votes vote down vote up
@Override protected void execImpl() {
  Set<String> idSet = DateTimeZone.getAvailableIDs();
  if(!idSet.contains(tz))
    throw new IllegalArgumentException("Unacceptable timezone name given.  For a list of acceptable names, use listTimezone().");

  SetTimezoneTask task = new SetTimezoneTask();
  task._tz = tz;
  task.invokeOnAllNodes();
}
 
Example 6
Source File: CalendarTimeZone.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Set<String> getAvailableIDs() {
  return DateTimeZone.getAvailableIDs();
}
 
Example 7
Source File: TimeZoneTable.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Set idSet = DateTimeZone.getAvailableIDs();
    ZoneData[] zones = new ZoneData[idSet.size()];
    
    {
        Iterator it = idSet.iterator();
        int i = 0;
        while (it.hasNext()) {
            String id = (String) it.next();
            zones[i++] = new ZoneData(id, DateTimeZone.forID(id));
        }
        Arrays.sort(zones);
    }

    PrintStream out = System.out;

    out.println("<table>");

    out.println("<tr>" +
                "<th align=\"left\">Standard Offset</th>" +
                "<th align=\"left\">Canonical ID</th>" +
                "<th align=\"left\">Aliases</th>" +
                "</tr>");

    ZoneData canonical = null;
    List<ZoneData> aliases = new ArrayList<ZoneData>();

    for (int i=0; i<zones.length; i++) {
        ZoneData zone = zones[i];

        if (!zone.isCanonical()) {
            aliases.add(zone);
            continue;
        }

        if (canonical != null) {
            printRow(out, canonical, aliases);
        }

        canonical = zone;
        aliases.clear();
    }

    if (canonical != null) {
        printRow(out, canonical, aliases);
    }

    out.println("</table>");
}
 
Example 8
Source File: TimeZoneTable.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Set idSet = DateTimeZone.getAvailableIDs();
    ZoneData[] zones = new ZoneData[idSet.size()];
    
    {
        Iterator it = idSet.iterator();
        int i = 0;
        while (it.hasNext()) {
            String id = (String) it.next();
            zones[i++] = new ZoneData(id, DateTimeZone.forID(id));
        }
        Arrays.sort(zones);
    }

    PrintStream out = System.out;

    out.println("<table>");

    out.println("<tr>" +
                "<th align=\"left\">Standard Offset</th>" +
                "<th align=\"left\">Canonical ID</th>" +
                "<th align=\"left\">Aliases</th>" +
                "</tr>");

    ZoneData canonical = null;
    List aliases = new ArrayList();

    for (int i=0; i<zones.length; i++) {
        ZoneData zone = zones[i];

        if (!zone.isCanonical()) {
            aliases.add(zone);
            continue;
        }

        if (canonical != null) {
            printRow(out, canonical, aliases);
        }

        canonical = zone;
        aliases.clear();
    }

    if (canonical != null) {
        printRow(out, canonical, aliases);
    }

    out.println("</table>");
}