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:org.lamsfoundation.lams.admin.web.action.TimezoneManagementAction.java

/** 
 * Displays list of all JRE available timezones.
 *///from  www . ja v  a2  s  .co m
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    timezoneService = AdminServiceProxy.getTimezoneService(getServlet().getServletContext());
    List<Timezone> defaultTimezones = timezoneService.getDefaultTimezones();

    ArrayList<TimezoneDTO> timezoneDtos = new ArrayList<TimezoneDTO>();
    for (String availableTimezoneId : TimeZone.getAvailableIDs()) {
        boolean isSelected = defaultTimezones.contains(new Timezone(availableTimezoneId));
        TimeZone timeZone = TimeZone.getTimeZone(availableTimezoneId);
        TimezoneDTO timezoneDto = TimezoneDTO.createTimezoneDTO(timeZone, isSelected);
        timezoneDtos.add(timezoneDto);
    }

    request.setAttribute("timezoneDtos", timezoneDtos);
    request.setAttribute("serverTimezone", timezoneService.getServerTimezone().getTimezoneId());

    return mapping.findForward(FORWARD_TIMEZONE_MANAGEMENT);
}

From source file:com.seajas.search.attender.controller.ProfileController.java

/**
 * Available time zones attribute.//www. j ava2s.c o  m
 * 
 * @return List<String>
 */
@ModelAttribute("availableTimeZones")
public List<String> populateAvailableTimeZones() {
    List<String> result = new ArrayList<String>();

    for (String timeZone : TimeZone.getAvailableIDs())
        if (timeZone.contains("/") && !timeZone.startsWith("Etc/"))
            result.add(timeZone);

    // Also incorporate any custom timezones (typically from attender requests)

    for (Profile profile : attenderService.getProfiles())
        for (ProfileSubscriber subscriber : profile.getSubscribers())
            if (!result.contains(subscriber.getTimeZone()))
                result.add(subscriber.getTimeZone());

    Collections.sort(result);

    result.add(0, "UTC");

    return result;
}

From source file:org.vosao.service.back.impl.LimitedUserServiceImpl.java

public List<String> getTimezones() {
    List<String> result = new ArrayList<String>();
    String[] ids = TimeZone.getAvailableIDs();
    Arrays.sort(ids);//  w  w w .j  a v  a2 s.  c  o  m
    for (String id : ids) {
        result.add(id);
    }
    return result;
}

From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java

void loadTzs(Context context) {
    mTimeZones = new ArrayList<>();
    HashSet<String> processedTimeZones = loadTzsInZoneTab(context);
    String[] tzIds = TimeZone.getAvailableIDs();

    if (DEBUG) {/*ww  w  .  j a va2  s  .c  om*/
        Log.e(TAG, "Available time zones: " + tzIds.length);
    }

    for (String tzId : tzIds) {
        if (processedTimeZones.contains(tzId)) {
            continue;
        }

        /*
         * Dropping non-GMT tzs without a country code. They are not really
         * needed and they are dups but missing proper country codes. e.g.
         * WET CET MST7MDT PST8PDT Asia/Khandyga Asia/Ust-Nera EST
         */
        if (!tzId.startsWith("Etc/GMT")) {
            continue;
        }

        final TimeZone tz = TimeZone.getTimeZone(tzId);
        if (tz == null) {
            Log.e(TAG, "Timezone not found: " + tzId);
            continue;
        }

        TimeZoneInfo tzInfo = new TimeZoneInfo(tz, null);

        if (getIdenticalTimeZoneInTheCountry(tzInfo) == -1) {
            if (DEBUG) {
                Log.e(TAG, "# Adding time zone from getAvailId: " + tzInfo.toString());
            }
            mTimeZones.add(tzInfo);
        } else {
            if (DEBUG) {
                Log.e(TAG, "# Dropping identical time zone from getAvailId: " + tzInfo.toString());
            }
            continue;
        }
        //
        // TODO check for dups
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.SHORT, groupIdx, !found);
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.LONG, groupIdx, !found);
        // if (tz.useDaylightTime()) {
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.SHORT, groupIdx,
        // !found);
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.LONG, groupIdx,
        // !found);
        // }
    }

    // Don't change the order of mTimeZones after this sort
    Collections.sort(mTimeZones);

    mTimeZonesByCountry = new LinkedHashMap<>();
    mTimeZonesByOffsets = new SparseArray<>(mHasTimeZonesInHrOffset.length);
    int N = mTimeZones.size();
    mTimeZonesById = new SimpleArrayMap<>(N);
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Lookup map for id -> tz
        mTimeZonesById.put(tz.mTzId, tz);
    }
    populateDisplayNameOverrides(mTimeZonesById, mContext.getResources());

    Date date = new Date(mTimeMillis);
    Locale defaultLocal = Locale.getDefault();

    int idx = 0;
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Populate display name
        if (tz.mDisplayName == null) {
            tz.mDisplayName = tz.mTz.getDisplayName(tz.mTz.inDaylightTime(date), TimeZone.LONG, defaultLocal);
        }

        // /////////////////////
        // Grouping tz's by country for search by country
        IntList group = mTimeZonesByCountry.get(tz.mCountry);
        if (group == null) {
            group = new IntList();
            mTimeZonesByCountry.put(tz.mCountry, group);
        }

        group.add(idx);

        // /////////////////////
        // Grouping tz's by GMT offsets
        indexByOffsets(idx, tz);

        // Skip all the GMT+xx:xx style display names from search
        if (!tz.mDisplayName.endsWith(":00")) {
            mTimeZoneNames.add(tz.mDisplayName);
        } else if (DEBUG) {
            Log.e(TAG, "# Hiding from pretty name search: " + tz.mDisplayName);
        }

        idx++;
    }

    // printTimeZones();
}

From source file:com.aerospike.load.Utils.java

/**
 * Check existence of user provided timezone
 * @param cl//from www .ja  v  a 2 s  . c  o  m
 * @return
 */
protected static boolean checkTimeZoneID(CommandLine cl) {
    String timeZone = cl.getOptionValue("tz");
    boolean sourceTZ = false;
    for (String timezone : TimeZone.getAvailableIDs()) {
        if (timezone.equalsIgnoreCase(timeZone)) {
            sourceTZ = true;
        }
    }
    return sourceTZ;
}

From source file:org.ietf.ietfsched.service.SyncService.java

@Override
public void onCreate() {
    super.onCreate();
    final ContentResolver resolver = getContentResolver();
    mLocalExecutor = new LocalExecutor(getResources(), resolver);

    final HttpClient httpClient = getHttpClient(this);
    mRemoteExecutor = new RemoteExecutor(httpClient);
    if (debbug) {
        Log.d(TAG, "SyncService OnCreate" + this.hashCode());
        String[] tz = TimeZone.getAvailableIDs();
        for (String id : tz) {
            Log.d(TAG, "Available timezone ids: " + id);
        }//  w  w w  .  j  ava  2  s  . co  m
    }
}

From source file:org.jamwiki.utils.DateUtil.java

/**
 * Returns a list of available time zones. The list is used to get the time zone
 * of a user in the user preferences dialog.
 *
 * @return List of time zones//ww w .j  av  a2 s . c  o  m
 */
public static Map<String, String> getTimeZoneMap() {
    Map<String, String> timeZoneMap = new TreeMap<String, String>();
    for (String timeZoneId : TimeZone.getAvailableIDs()) {
        timeZoneMap.put(timeZoneId, timeZoneId);
    }
    return timeZoneMap;
}

From source file:org.elasticsearch.xpack.qa.sql.jdbc.JdbcIntegrationTestCase.java

public static String randomKnownTimeZone() {
    // We use system default timezone for the connection that is selected randomly by TestRuleSetupAndRestoreClassEnv
    // from all available JDK timezones. While Joda and JDK are generally in sync, some timezones might not be known
    // to the current version of Joda and in this case the test might fail. To avoid that, we specify a timezone
    // known for both Joda and JDK
    Set<String> timeZones = new HashSet<>(DateTimeZone.getAvailableIDs());
    timeZones.retainAll(Arrays.asList(TimeZone.getAvailableIDs()));
    List<String> ids = new ArrayList<>(timeZones);
    Collections.sort(ids);//  w  w w . jav  a  2  s .  c om
    return randomFrom(ids);
}

From source file:org.nodatime.tzvalidate.Java7Dump.java

@Override
public Iterable<String> getZoneIds() {
    // TODO: Remove the abbreviation IDs which aren't actually in TZDB.
    return Arrays.asList(TimeZone.getAvailableIDs());
}

From source file:org.vosao.service.back.impl.UserServiceImpl.java

@Override
public List<String> getTimezones() {
    List<String> result = new ArrayList<String>();
    String[] ids = TimeZone.getAvailableIDs();
    Arrays.sort(ids);//w ww .  j  a  v  a 2s .c o m
    for (String id : ids) {
        result.add(id);
    }
    return result;
}