Example usage for java.util TimeZone getID

List of usage examples for java.util TimeZone getID

Introduction

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

Prototype

public String getID() 

Source Link

Document

Gets the ID of this time zone.

Usage

From source file:com.microsoft.exchange.DateHelpTest.java

/**
 * Computes the time zone offset for a given {@link XMLGregorianCalendar} and compares to the specified {@link TimeZone}
 * //  ww  w  .  j av  a2  s. c om
 * 
 * 
 * @param xmlGregorianCalendar
 * @param timeZone
 */
public boolean xmlGregorianCalendareMatchesTimeZone(XMLGregorianCalendar xmlGregorianCalendar,
        TimeZone timeZone) {
    int xmlTimeZoneOffsetMinutes = xmlGregorianCalendar.getTimezone();
    TimeZone xmlTimeZone = xmlGregorianCalendar.getTimeZone(xmlTimeZoneOffsetMinutes);
    int jvmRawOffsetMinutes = (timeZone.getRawOffset() / 1000 / 60);
    int jvmDstOffsetMinutes = (timeZone.getDSTSavings() / 1000 / 60);

    int xmlRawOffsetMinutes = (xmlTimeZone.getRawOffset() / 1000 / 60);
    int xmlDstOffsetMinutes = (xmlTimeZone.getDSTSavings() / 1000 / 60);

    //XMLGregorianCalendar only stores an Int for offset, no DST information.  
    //as a result the xmlTimeZone and jvmTimeZone almost never follow the same rules
    if (timeZone.hasSameRules(xmlTimeZone)) {
        log.debug("xmlTimeZoneId=" + xmlTimeZone.getID() + " hasSameRules as jvmTimeZone=" + timeZone.getID());
        return true;
    }

    if (timeZone.useDaylightTime()) {
        //they definately do not when the jvmTimeZone uses DST.
        assertFalse(xmlTimeZone.hasSameRules(timeZone));
        jvmRawOffsetMinutes += jvmDstOffsetMinutes;
    }

    if (xmlTimeZone.useDaylightTime()) {
        xmlRawOffsetMinutes += xmlDstOffsetMinutes;
    }
    if (xmlTimeZoneOffsetMinutes != xmlRawOffsetMinutes) {
        log.info("xmlTimeZoneId=" + xmlTimeZone.getID() + " has weird rules");
    }

    return (jvmRawOffsetMinutes == xmlRawOffsetMinutes);

}

From source file:net.sf.logsaw.tests.ADialectTest.java

/**
 * Creates the log resource to work with.
 * Subsequent calls to <code>getLogResource</code> will return this instance.
 * @param encoding the file encoding//w ww . j a  v a2 s . c o m
 * @param locale the locale to use
 * @param timeZone the timezone to apply
 * @throws IOException if an error occurred
 */
protected final void createLogResource(String encoding, Locale locale, TimeZone timeZone) throws IOException {
    cleanUp(false, true);
    File logFile = getLogFile();
    Assert.isNotNull(logFile, "logFile");
    ILogResourceFactory factory = doGetLogResourceFactory();
    Assert.isNotNull(factory, "factory");
    ILogResource log = factory.createLogResource();
    log.setName(getLogFile().getName());
    log.setDialect(createLogDialect());
    try {
        log.configure(IHasEncoding.OPTION_ENCODING, encoding);
        log.configure(IHasLocale.OPTION_LOCALE, LocaleUtils.getLocaleId(locale));
        log.configure(IHasTimeZone.OPTION_TIMEZONE, timeZone.getID());
        doConfigure(log);
        // That's it
        setLogResource(log);
    } catch (CoreException e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}

From source file:net.sf.logsaw.tests.ADialectTest.java

/**
 * Creates the log resource to work with.
 * Subsequent calls to <code>getLogResource</code> will return this instance.
 * @param encoding the file encoding//  w  w  w .  j  ava  2  s  .  co  m
 * @param locale the locale to use
 * @param timeZone the timezone to apply
 * @throws IOException if an error occurred
 */
protected final void createLogResourceWithPK(String encoding, Locale locale, TimeZone timeZone)
        throws IOException {
    cleanUp(false, true);
    File logFile = getLogFile();
    Assert.isNotNull(logFile, "logFile");
    ILogResourceFactory factory = doGetLogResourceFactory();
    Assert.isNotNull(factory, "factory");
    ILogResource log = factory.createLogResource();
    log.setName(getLogFile().getName());
    log.setDialect(createLogDialect());
    try {
        log.configure(IHasEncoding.OPTION_ENCODING, encoding);
        log.configure(IHasLocale.OPTION_LOCALE, LocaleUtils.getLocaleId(locale));
        log.configure(IHasTimeZone.OPTION_TIMEZONE, timeZone.getID());
        doConfigure(log);
        // Create PK
        IndexPlugin.getDefault().getIndexService().createIndex(log);
        // That's it
        setIndexFile(IndexPlugin.getDefault().getIndexFile(log));
        setLogResource(log);
    } catch (CoreException e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}

From source file:com.blackducksoftware.tools.ccimporter.config.CCIConfigurationManager.java

/**
 * Make sure timezone is set to a valid timezone ID string
 *//*from w  ww .jav a2 s  .  co m*/
private void ensureTimeZoneIsSet() {
    // TODO: Temporary workaround to provide timezones. This
    // handles the case whereby
    // utility is run against a server that is not in the same
    // time zone.
    TimeZone tz;
    String userSpecifiedTimeZone = timeZone;

    if (userSpecifiedTimeZone != null && !userSpecifiedTimeZone.isEmpty()) {
        tz = TimeZone.getTimeZone(userSpecifiedTimeZone);
        log.info("User specified time zone recognized, using: " + tz.getDisplayName());
    } else {
        tz = TimeZone.getDefault();
    }

    setTimeZone(tz.getID());
}

From source file:com.sunrun.crportal.util.CRPortalUtil.java

public static Calendar setNewCalendar(Calendar oldCalendar, TimeZone tz) {

    LOG.debug("* ---------------------------------------------------------- *");
    LOG.debug("* setNewCalendar - Entering                                  *");
    LOG.debug("* ---------------------------------------------------------- *");

    SimpleDateFormat sdf = new SimpleDateFormat(df);
    //sdf.setTimeZone(tz);
    LOG.debug("   setNewCalendar - oldCalendar = " + sdf.format(oldCalendar.getTimeInMillis()));
    LOG.debug("   setNewCalendar - TimeZone    = " + tz.getID());

    Calendar newCalendar = null;// w ww .  j av  a  2 s.  co m

    DateFormat dfm;
    int intDay;
    int intMonth;
    int intYear;
    Date dtRightNow = null;
    String strRightNow;

    intDay = oldCalendar.get(Calendar.DAY_OF_MONTH);
    intMonth = oldCalendar.get(Calendar.MONTH);
    intYear = oldCalendar.get(Calendar.YEAR);

    strRightNow = "";
    strRightNow += intYear;
    strRightNow += "-";
    strRightNow += intMonth + 1;
    strRightNow += "-";
    strRightNow += intDay;
    LOG.debug("   setCalendar - strRightNow = " + strRightNow);
    try {
        dfm = new SimpleDateFormat("yyyy-MM-dd");
        //dfm.setTimeZone(tz);
        dtRightNow = dfm.parse(strRightNow);
        newCalendar = Calendar.getInstance(tz);
        newCalendar.setTime(dtRightNow);
        LOG.debug("   setNewCalendar - newCalendar    = " + sdf.format(newCalendar.getTimeInMillis()));
        LOG.debug("   setNewCalendar - newCalendar TZ = " + newCalendar.getTimeZone().getID());
    } catch (java.text.ParseException e) {
        LOG.warn(e.getMessage());
        LOG.debug("   setNewCalendar - defaultFromDate = null");
    }

    LOG.debug("* ---------------------------------------------------------- *");
    LOG.debug("* setNewCalendar - Exiting                                   *");
    LOG.debug("* ---------------------------------------------------------- *");
    return newCalendar;
}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

public List<NameValuePair> createRequestParams(String[] paramNames, String[] paramValues, boolean withToken,
        Integer appfilter, String userId, String pwd) {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("store", storeId));
    nvps.add(new BasicNameValuePair("aver", sdkVer));
    nvps.add(new BasicNameValuePair("arel", sdkRel));
    nvps.add(new BasicNameValuePair("cver", clientVer));
    nvps.add(new BasicNameValuePair("lang", Locale.getDefault().toString()));
    TimeZone tz = TimeZone.getDefault();
    nvps.add(new BasicNameValuePair("tzid", tz.getID()));
    nvps.add(new BasicNameValuePair("tzrawoffset", "" + tz.getRawOffset()));
    String time = "" + System.currentTimeMillis();
    nvps.add(new BasicNameValuePair("time", time));
    String vstring = storeId + "|" + time;
    if (userId != null && pwd != null) {
        vstring = storeId + "|" + time + "|" + userId + "|" + pwd;
    } else if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) {
        vstring = storeId + "|" + time + "|" + this.credential.getToken();
    } else if (deviceId != null && subscriberId != null && simSerialNumber != null) {
        vstring = storeId + "|" + time + "|" + deviceId + "|" + subscriberId + "|" + simSerialNumber;
    }/*w w  w  .  j a v  a2s . c o  m*/
    L.d("vstring=" + vstring);
    String vsign = "";
    try {
        vsign = Dsa.sign(vstring, this.config.getApiPrivkey());
    } catch (Exception e) {

    }
    nvps.add(new BasicNameValuePair("vsign", vsign));
    nvps.add(new BasicNameValuePair("imei", deviceId));
    nvps.add(new BasicNameValuePair("mac", macAddress));
    nvps.add(new BasicNameValuePair("imsi", subscriberId));
    nvps.add(new BasicNameValuePair("iccid", simSerialNumber));
    nvps.add(new BasicNameValuePair("dvc", Build.MODEL));
    nvps.add(new BasicNameValuePair("wpx", wpx));
    nvps.add(new BasicNameValuePair("hpx", hpx));
    if (appfilter == null) {
        //?appFilter()
        nvps.add(new BasicNameValuePair("appfilter", "" + appFilter));
    } else {
        //?appfilter
        nvps.add(new BasicNameValuePair("appfilter", "" + appfilter));
    }

    //???
    if (this.config.getSnum() != null && this.config.getSnum().length() > 0) {
        nvps.add(new BasicNameValuePair("snum", this.config.getSnum()));
    }

    if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) {
        nvps.add(new BasicNameValuePair("token", this.credential.getToken()));
    }

    if (paramNames == null || paramValues == null) {
        return nvps;
    }

    if (paramNames.length != paramValues.length) {
        throw new IndexOutOfBoundsException("paramNames.length != paramValues.length");
    }

    int count = paramNames.length;
    for (int i = 0; i < count; i++) {
        nvps.add(new BasicNameValuePair(paramNames[i], paramValues[i]));
    }

    return nvps;
}

From source file:org.projectforge.framework.persistence.user.entities.PFUserDO.java

@Transient
public DateTimeZone getDateTimeZone() {
    final TimeZone timeZone = getTimeZoneObject();
    return DateTimeZone.forID(timeZone.getID());
}

From source file:com.thelastcheck.io.base.Field.java

private DateFormat formatForZone(Map<String, DateFormat> map, String format, TimeZone zone) {
    DateFormat df = null;/*  w w  w  . j  av a 2s .  c  o  m*/
    if (zone == null) {
        df = map.get(null);
    } else {
        df = map.get(zone.getID());
    }
    if (df == null) {
        df = new SimpleDateFormat(format);
        if (zone == null) {
            map.put(null, df);
        } else {
            Calendar cal = Calendar.getInstance(zone);
            df.setCalendar(cal);
            map.put(zone.getID(), df);
        }
    }
    return df;
}

From source file:org.kalypso.simulation.ui.calccase.ModelNature.java

private Properties createVariablesForAntLaunch(final IContainer folder) throws CoreException {
    final Properties attributes = new Properties();
    final IProject project = folder.getProject();

    final KalypsoAuthPlugin authPlugin = KalypsoAuthPlugin.getDefault();
    final IKalypsoUser currentUser = authPlugin.getCurrentUser();
    final Date now = new Date();

    final TimeZone kalypsoTimezone = KalypsoCorePlugin.getDefault().getTimeZone();

    // auf x stunden vorher runden! hngt von der Modellspec ab
    final Calendar cal = Calendar.getInstance();
    cal.setTimeZone(kalypsoTimezone);/*from  w w w. jav  a 2  s  . c  om*/
    cal.setTime(now);

    attributes.setProperty("kalypso.currentTime", DatatypeConverter.printDateTime(cal)); //$NON-NLS-1$
    attributes.setProperty("kalypso.timezone", kalypsoTimezone.getID()); //$NON-NLS-1$

    // erstmal auf die letzte Stunde runden
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // jetzt solange ganze stunden abziehen, bis der Wert ins
    // Zeitvalidierungsschema passt
    int count = 0;
    while (!validateTime(cal)) {
        cal.add(Calendar.HOUR_OF_DAY, -1);

        // nach 24h sptestens abbrechen!
        count++;
        if (count == 24)
            throw new CoreException(new Status(IStatus.ERROR, KalypsoSimulationUIPlugin.getID(),
                    Messages.getString("org.kalypso.simulation.ui.calccase.ModelNature.7") + cal)); //$NON-NLS-1$
    }

    attributes.setProperty("kalypso.startforecast", DatatypeConverter.printDateTime(cal)); //$NON-NLS-1$

    // standardzeit abziehen
    final int simDiff = new Integer(m_metadata.getProperty(META_PROP_DEFAULT_SIMHOURS, "120")).intValue(); //$NON-NLS-1$
    cal.add(Calendar.HOUR_OF_DAY, -simDiff);

    attributes.setProperty("kalypso.startsim", DatatypeConverter.printDateTime(cal)); //$NON-NLS-1$

    attributes.setProperty("kalypso.currentUser", currentUser.getUserName()); //$NON-NLS-1$

    attributes.setProperty("simulation_project_loc", project.getLocation().toPortableString()); //$NON-NLS-1$

    attributes.setProperty("calc.dir", folder.getLocation().toPortableString()); //$NON-NLS-1$
    attributes.setProperty("project.dir", project.getLocation().toPortableString()); //$NON-NLS-1$

    attributes.setProperty("calc.path", folder.getFullPath().toPortableString()); //$NON-NLS-1$
    attributes.setProperty("project.path", project.getFullPath().toPortableString()); //$NON-NLS-1$

    try {
        attributes.setProperty("calc.url", ResourceUtilities.createURL(folder).toString()); //$NON-NLS-1$
        attributes.setProperty("project.url", ResourceUtilities.createURL(project).toString()); //$NON-NLS-1$
    } catch (final MalformedURLException e) {
        // should never happen
        e.printStackTrace();
    } catch (final URIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return attributes;
}

From source file:org.apache.falcon.regression.ui.search.ProcessWizardPage.java

public void setTimezone(TimeZone timezone) {
    if (timezone == null) {
        return;/*from   w w  w.ja va2 s  .  c  o  m*/
    }
    String timeZone = timezone.getID();
    getTimezone().selectByValue(timeZone);
}