Example usage for java.util TimeZone getAvailableIDs

List of usage examples for java.util TimeZone getAvailableIDs

Introduction

In this page you can find the example usage for java.util TimeZone getAvailableIDs.

Prototype

public static synchronized String[] getAvailableIDs() 

Source Link

Document

Gets all the available IDs supported.

Usage

From source file:ch.cyberduck.ui.cocoa.BookmarkController.java

@Action
public void timezonePopupClicked(NSPopUpButton sender) {
    String selected = sender.selectedItem().representedObject();
    if (selected.equals(AUTO)) {
        host.setTimezone(null);//from w  ww  .  ja va 2s  . c  o m
    } else {
        String[] ids = TimeZone.getAvailableIDs();
        for (String id : ids) {
            TimeZone tz;
            if ((tz = TimeZone.getTimeZone(id)).getID().equals(selected)) {
                host.setTimezone(tz);
                break;
            }
        }
    }
    this.itemChanged();
}

From source file:de.codesourcery.eve.apiclient.parsers.HttpAPIClientTest.java

public static void main(String[] args) {
    List<String> ids = new ArrayList<String>();
    for (String id : TimeZone.getAvailableIDs()) {
        ids.add(id);/*from  w  w w.  ja  v  a2s. c o m*/
    }

    Collections.sort(ids);
    for (String id : TimeZone.getAvailableIDs()) {
        System.out.println(id);
    }
}

From source file:org.apache.oozie.servlet.BaseAdminServlet.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private JSONArray availableTimeZonesToJsonArray() {
    JSONArray array = new JSONArray();
    for (String tzId : TimeZone.getAvailableIDs()) {
        // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing
        if (!tzId.startsWith("Etc/GMT")) {
            JSONObject json = new JSONObject();
            TimeZone tZone = TimeZone.getTimeZone(tzId);
            json.put(JsonTags.TIME_ZOME_DISPLAY_NAME,
                    tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")");
            json.put(JsonTags.TIME_ZONE_ID, tzId);
            array.add(json);/*from  w ww  .ja va  2s  . c  o  m*/
        }
    }

    // The combo box this populates cannot be edited, so the user can't type in GMT offsets (like in the CLI), so we'll add
    // in some hourly offsets here (though the user will not be able to use other offsets without editing the cookie manually
    // and they are not in order)
    array.addAll(GMTOffsetTimeZones);

    return array;
}

From source file:main.UIController.java

/************* SETTINGS ****************/

private void fillSettingsForm() {
    UI ui = this.getUi();
    Preferences data = this.getCurrentPreferences();
    /* Country and city */
    String city = data.get(FIELD_CITY, DEF_CITY);
    String country = data.get(FIELD_COUNTRY, DEF_COUNTRY);
    ui.getCity().setText(city);//from   w ww .  j  a v  a 2s  .  c  o m
    ui.getCountry().setText(country);
    /* Lang */
    LangManager langManager = LangManager.getInstance();
    String lang = langManager.getDefinedLang().getShortName();
    JComboBox langsCombo = ui.getLangCombo();
    langsCombo.setSelectedIndex(Arrays.asList(LangManager.getLanguagesShort()).indexOf(lang));
    /* Time Zone */
    String[] tzs = TimeZone.getAvailableIDs();
    Arrays.sort(tzs);
    JList list = ui.getTimeZone();
    list.setListData(tzs);
    String timezone = data.get(FIELD_TIMEZONE, DEF_TIMEZONE);
    list.setSelectedValue(timezone, true);
}

From source file:com.cloud.server.ManagementServerImpl.java

protected ManagementServerImpl() {
    ComponentLocator locator = ComponentLocator.getLocator(Name);
    _configDao = locator.getDao(ConfigurationDao.class);
    _routerDao = locator.getDao(DomainRouterDao.class);
    _eventDao = locator.getDao(EventDao.class);
    _dcDao = locator.getDao(DataCenterDao.class);
    _vlanDao = locator.getDao(VlanDao.class);
    _accountVlanMapDao = locator.getDao(AccountVlanMapDao.class);
    _podVlanMapDao = locator.getDao(PodVlanMapDao.class);
    _hostDao = locator.getDao(HostDao.class);
    _detailsDao = locator.getDao(HostDetailsDao.class);
    _hostPodDao = locator.getDao(HostPodDao.class);
    _jobDao = locator.getDao(AsyncJobDao.class);
    _clusterDao = locator.getDao(ClusterDao.class);
    _nicDao = locator.getDao(NicDao.class);
    _networkDao = locator.getDao(NetworkDao.class);
    _loadbalancerDao = locator.getDao(LoadBalancerDao.class);

    _accountMgr = locator.getManager(AccountManager.class);
    _agentMgr = locator.getManager(AgentManager.class);
    _alertMgr = locator.getManager(AlertManager.class);
    _consoleProxyMgr = locator.getManager(ConsoleProxyManager.class);
    _secStorageVmMgr = locator.getManager(SecondaryStorageVmManager.class);
    _swiftMgr = locator.getManager(SwiftManager.class);
    _storageMgr = locator.getManager(StorageManager.class);
    _publicIpAddressDao = locator.getDao(IPAddressDao.class);
    _consoleProxyDao = locator.getDao(ConsoleProxyDao.class);
    _secStorageVmDao = locator.getDao(SecondaryStorageVmDao.class);
    _userDao = locator.getDao(UserDao.class);
    _userVmDao = locator.getDao(UserVmDao.class);
    _offeringsDao = locator.getDao(ServiceOfferingDao.class);
    _diskOfferingDao = locator.getDao(DiskOfferingDao.class);
    _templateDao = locator.getDao(VMTemplateDao.class);
    _domainDao = locator.getDao(DomainDao.class);
    _accountDao = locator.getDao(AccountDao.class);
    _alertDao = locator.getDao(AlertDao.class);
    _capacityDao = locator.getDao(CapacityDao.class);
    _guestOSDao = locator.getDao(GuestOSDao.class);
    _guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class);
    _poolDao = locator.getDao(StoragePoolDao.class);
    _vmGroupDao = locator.getDao(InstanceGroupDao.class);
    _uploadDao = locator.getDao(UploadDao.class);
    _configs = _configDao.getConfiguration();
    _vmInstanceDao = locator.getDao(VMInstanceDao.class);
    _volumeDao = locator.getDao(VolumeDao.class);
    _asyncMgr = locator.getManager(AsyncJobManager.class);
    _uploadMonitor = locator.getManager(UploadMonitor.class);
    _sshKeyPairDao = locator.getDao(SSHKeyPairDao.class);
    _itMgr = locator.getManager(VirtualMachineManager.class);
    _ksMgr = locator.getManager(KeystoreManager.class);
    _resourceMgr = locator.getManager(ResourceManager.class);
    _configMgr = locator.getManager(ConfigurationManager.class);
    _resourceTagDao = locator.getDao(ResourceTagDao.class);

    _hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);

    _hostAllocators = locator.getAdapters(HostAllocator.class);
    if (_hostAllocators == null || !_hostAllocators.isSet()) {
        s_logger.error("Unable to find HostAllocators");
    }/*from  w  w  w. j a v  a2 s.c o  m*/

    String value = _configs.get("event.purge.interval");
    int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.

    _statsCollector = StatsCollector.getInstance(_configs);

    _purgeDelay = NumbersUtil.parseInt(_configs.get("event.purge.delay"), 0);
    if (_purgeDelay != 0) {
        _eventExecutor.scheduleAtFixedRate(new EventPurgeTask(), cleanup, cleanup, TimeUnit.SECONDS);
    }

    String[] availableIds = TimeZone.getAvailableIDs();
    _availableIdsMap = new HashMap<String, Boolean>(availableIds.length);
    for (String id : availableIds) {
        _availableIdsMap.put(id, true);
    }

    _userAuthenticators = locator.getAdapters(UserAuthenticator.class);
    if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
        s_logger.error("Unable to find an user authenticator.");
    }
}

From source file:org.apache.openmeetings.cli.Admin.java

private void checkAdminDetails() throws Exception {
    cfg.username = cmdl.getOptionValue("user");
    cfg.email = cmdl.getOptionValue("email");
    cfg.group = cmdl.getOptionValue("group");
    if (cfg.username == null || cfg.username.length() < USER_LOGIN_MINIMUM_LENGTH) {
        System.out.println("User login was not provided, or too short, should be at least "
                + USER_LOGIN_MINIMUM_LENGTH + " character long.");
        System.exit(1);//w w  w  .j  a  va  2  s.co  m
    }

    try {
        if (cfg.email == null || !MailUtil.matches(cfg.email)) {
            throw new AddressException("Invalid address");
        }
        new InternetAddress(cfg.email, true);
    } catch (AddressException ae) {
        System.out.println("Please provide non-empty valid email: '" + cfg.email + "' is not valid.");
        System.exit(1);
    }
    if (cfg.group == null || cfg.group.length() < 1) {
        System.out.println(
                "User group was not provided, or too short, should be at least 1 character long: " + cfg.group);
        System.exit(1);
    }
    cfg.password = cmdl.getOptionValue("password");
    ConfigurationDao cfgDao = getApplicationContext().getBean(ConfigurationDao.class);
    if (invalidPassword(cfg.password, cfgDao)) {
        System.out.print("Please enter password for the user '" + cfg.username + "':");
        cfg.password = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)).readLine();
        if (invalidPassword(cfg.password, cfgDao)) {
            System.out.println("Password was not provided, or too short, should be at least "
                    + getMinPasswdLength(cfgDao) + " character long.");
            System.exit(1);
        }
    }
    Map<String, String> tzMap = ImportHelper.getAllTimeZones(TimeZone.getAvailableIDs());
    cfg.ical_timeZone = null;
    if (cmdl.hasOption("tz")) {
        cfg.ical_timeZone = cmdl.getOptionValue("tz");
        cfg.ical_timeZone = tzMap.containsKey(cfg.ical_timeZone) ? cfg.ical_timeZone : null;
    }
    if (cfg.ical_timeZone == null) {
        System.out.println("Please enter timezone, Possible timezones are:");

        for (Map.Entry<String, String> me : tzMap.entrySet()) {
            System.out.println(String.format("%1$-25s%2$s", "\"" + me.getKey() + "\"", me.getValue()));
        }
        System.exit(1);
    }
}

From source file:org.tolven.web.RegisterAction.java

public List<SelectItem> getTimeZones() {
    if (timeZones == null) {
        timeZones = new ArrayList<SelectItem>(30);
        String zones[] = TimeZone.getAvailableIDs();
        timeZones.add(new SelectItem(null, "Use Default"));
        timeZones.add(new SelectItem("Europe/Paris", "Europe/Paris"));
        timeZones.add(new SelectItem("Europe/London", "Europe/London"));
        timeZones.add(new SelectItem("America/New_York", "America/New_York"));
        timeZones.add(new SelectItem("America/Chicago", "America/Chicago"));
        timeZones.add(new SelectItem("America/Denver", "America/Denver"));
        timeZones.add(new SelectItem("America/Phoenix", "America/Phoenix"));
        timeZones.add(new SelectItem("America/Los_Angeles", "America/Los_Angeles"));
        for (String zone : zones) {
            timeZones.add(new SelectItem(zone, zone));
        }/*from w  ww  . j  a v a  2 s . c om*/
    }
    return timeZones;
}

From source file:org.opencastproject.scheduler.endpoint.SchedulerRestService.java

private Response getConflictingEvents(String device, Long startDate, Long endDate, Long duration, String rrule,
        String timezone, boolean asJson) {
    if (StringUtils.isEmpty(device) || startDate == null || endDate == null) {
        logger.warn("Either device, start date or end date were not specified");
        return Response.status(Status.BAD_REQUEST).build();
    }//  w ww .j  av a  2  s  . co m

    if (StringUtils.isNotEmpty(rrule)) {
        try {
            RRule rule = new RRule(rrule);
            rule.validate();
        } catch (Exception e) {
            logger.warn("Unable to parse rrule {}: {}", rrule, e.getMessage());
            return Response.status(Status.BAD_REQUEST).build();
        }

        if (duration == null) {
            logger.warn("If checking recurrence, must include duration.");
            return Response.status(Status.BAD_REQUEST).build();
        }

        if (StringUtils.isNotEmpty(timezone) && !Arrays.asList(TimeZone.getAvailableIDs()).contains(timezone)) {
            logger.warn("Unable to parse timezone: {}", timezone);
            return Response.status(Status.BAD_REQUEST).build();
        }
    }

    try {
        DublinCoreCatalogList events = null;
        if (StringUtils.isNotEmpty(rrule)) {
            events = service.findConflictingEvents(device, rrule, new Date(startDate), new Date(endDate),
                    duration, timezone);
        } else {
            events = service.findConflictingEvents(device, new Date(startDate), new Date(endDate));
        }
        if (!events.getCatalogList().isEmpty()) {
            if (asJson) {
                return Response.ok(events.getResultsAsJson()).build();
            } else {
                return Response.ok(events.getResultsAsXML()).build();
            }
        } else {
            return Response.noContent().build();
        }
    } catch (Exception e) {
        logger.error("Unable to find conflicting events for " + device + ", " + startDate.toString() + ", "
                + endDate.toString() + ", " + duration.toString() + ":", e.getMessage());
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java

public void testDatetimeWithCalendar() throws SQLException {
    trace("test DATETIME with Calendar");
    ResultSet rs;/*  ww w.j  a  v  a2s  .  co  m*/

    stat = conn.createStatement();
    stat.execute("CREATE TABLE test(ID INT PRIMARY KEY, D DATE, T TIME, TS TIMESTAMP)");
    PreparedStatement prep = conn.prepareStatement("INSERT INTO test VALUES(?, ?, ?, ?)");
    Calendar regular = Calendar.getInstance();
    Calendar other = null;
    // search a locale that has a _different_ raw offset
    long testTime = java.sql.Date.valueOf("2001-02-03").getTime();
    for (String s : TimeZone.getAvailableIDs()) {
        TimeZone zone = TimeZone.getTimeZone(s);
        long rawOffsetDiff = regular.getTimeZone().getRawOffset() - zone.getRawOffset();
        // must not be the same timezone (not 0 h and not 24 h difference
        // as for Pacific/Auckland and Etc/GMT+12)
        if (rawOffsetDiff != 0 && rawOffsetDiff != 1000 * 60 * 60 * 24) {
            if (regular.getTimeZone().getOffset(testTime) != zone.getOffset(testTime)) {
                other = Calendar.getInstance(zone);
                break;
            }
        }
    }

    trace("regular offset = " + regular.getTimeZone().getRawOffset() + " other = "
            + other.getTimeZone().getRawOffset());

    prep.setInt(1, 0);
    prep.setDate(2, null, regular);
    prep.setTime(3, null, regular);
    prep.setTimestamp(4, null, regular);
    prep.execute();

    prep.setInt(1, 1);
    prep.setDate(2, null, other);
    prep.setTime(3, null, other);
    prep.setTimestamp(4, null, other);
    prep.execute();

    prep.setInt(1, 2);
    prep.setDate(2, java.sql.Date.valueOf("2001-02-03"), regular);
    prep.setTime(3, java.sql.Time.valueOf("04:05:06"), regular);
    prep.setTimestamp(4, Timestamp.valueOf("2007-08-09 10:11:12.131415"), regular);
    prep.execute();

    prep.setInt(1, 3);
    prep.setDate(2, java.sql.Date.valueOf("2101-02-03"), other);
    prep.setTime(3, java.sql.Time.valueOf("14:05:06"), other);
    prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415"), other);
    prep.execute();

    prep.setInt(1, 4);
    prep.setDate(2, java.sql.Date.valueOf("2101-02-03"));
    prep.setTime(3, java.sql.Time.valueOf("14:05:06"));
    prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415"));
    prep.execute();

    rs = stat.executeQuery("SELECT * FROM test ORDER BY ID");
    assertResultSetMeta(rs, 4, new String[] { "ID", "D", "T", "TS" },
            new int[] { Types.INTEGER, Types.DATE, Types.TIME, Types.TIMESTAMP }, new int[] { 10, 8, 6, 23 },
            new int[] { 0, 0, 0, 10 });

    rs.next();
    assertEquals(0, rs.getInt(1));
    assertTrue(rs.getDate(2, regular) == null && rs.wasNull());
    assertTrue(rs.getTime(3, regular) == null && rs.wasNull());
    assertTrue(rs.getTimestamp(3, regular) == null && rs.wasNull());

    rs.next();
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.getDate(2, other) == null && rs.wasNull());
    assertTrue(rs.getTime(3, other) == null && rs.wasNull());
    assertTrue(rs.getTimestamp(3, other) == null && rs.wasNull());

    rs.next();
    assertEquals(2, rs.getInt(1));
    assertEquals("2001-02-03", rs.getDate(2, regular).toString());
    assertEquals("04:05:06", rs.getTime(3, regular).toString());
    assertFalse(rs.getTime(3, other).toString().equals("04:05:06"));
    assertEquals("2007-08-09 10:11:12.131415", rs.getTimestamp(4, regular).toString());
    assertFalse(rs.getTimestamp(4, other).toString().equals("2007-08-09 10:11:12.131415"));

    rs.next();
    assertEquals(3, rs.getInt("ID"));
    assertFalse(rs.getTimestamp("TS", regular).toString().equals("2107-08-09 10:11:12.131415"));
    assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS", other).toString());
    assertFalse(rs.getTime("T", regular).toString().equals("14:05:06"));
    assertEquals("14:05:06", rs.getTime("T", other).toString());
    // checkFalse(rs.getDate(2, regular).toString(), "2101-02-03");
    // check(rs.getDate("D", other).toString(), "2101-02-03");

    rs.next();
    assertEquals(4, rs.getInt("ID"));
    assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS").toString());
    assertEquals("14:05:06", rs.getTime("T").toString());
    assertEquals("2101-02-03", rs.getDate("D").toString());

    assertFalse(rs.next());
    stat.execute("DROP TABLE test");
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String SetTimeZone(String sTimeZone) {
    String sRet = "Unable to set timezone to " + sTimeZone;
    TimeZone tz = null;//from   ww w.  jav  a 2s  .co m
    AlarmManager amgr = null;

    if ((sTimeZone.length() > 0) && (sTimeZone.startsWith("GMT"))) {
        amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
        if (amgr != null)
            amgr.setTimeZone(sTimeZone);
    } else {
        String[] zoneNames = TimeZone.getAvailableIDs();
        int nNumMatches = zoneNames.length;
        int lcv = 0;

        for (lcv = 0; lcv < nNumMatches; lcv++) {
            if (zoneNames[lcv].equalsIgnoreCase(sTimeZone))
                break;
        }

        if (lcv < nNumMatches) {
            amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
            if (amgr != null)
                amgr.setTimeZone(zoneNames[lcv]);
        }
    }

    if (amgr != null) {
        tz = TimeZone.getDefault();
        Date now = new Date();
        sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG);
    }

    return (sRet);
}