Example usage for java.util TimeZone getDefault

List of usage examples for java.util TimeZone getDefault

Introduction

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

Prototype

public static TimeZone getDefault() 

Source Link

Document

Gets the default TimeZone of the Java virtual machine.

Usage

From source file:com.funambol.LDAP.admin.LDAPSyncSourceConfigPanel.java

/**
 * Load the current syncSource showing the name, uri and type in the panel's
 * fields./*from w  ww  .  ja  va2 s  . c om*/
 */
public void updateForm() {
    if (!(getSyncSource() instanceof LDAPContactsSyncSource)) {
        notifyError(new AdminException("This is not an " + LDAPContactsSyncSource.class.getName()
                + " Unable to process SyncSource values (" + getSyncSource() + ")."));
        return;
    }

    LDAPContactsSyncSource syncSource = (LDAPContactsSyncSource) getSyncSource();

    if (getState() == STATE_INSERT) {
        confirmButton.setText("Add");
    } else if (getState() == STATE_UPDATE) {
        confirmButton.setText("Save");
    }

    syncSource.setInfo(new SyncSourceInfo(supportedTypes, typeValue.getSelectedIndex()));
    sourceUriValue.setText(syncSource.getSourceURI());
    nameValue.setText(syncSource.getName());
    typeValue.setSelectedIndex(syncSource.getInfo().getPreferred());

    if (syncSource.getServerTimeZone() != null) {
        timeZoneValue.setSelectedItem(syncSource.getServerTimeZone().getID());
    } else {
        timeZoneValue.setSelectedItem(TimeZone.getDefault().getID());
    }

    daoNameValue.setSelectedItem(syncSource.getDaoName());
    followReferralValue.setSelected(syncSource.isFollowReferral());
    connectionPoolingValue.setSelected(syncSource.isConnectionPooling());
    providerUrlValue.setText(syncSource.getProviderUrl());

    //   bindAsUserValue.setSelected(syncSource.getBindAsUser());

    ldapBaseValue.setText(syncSource.getLdapBase());
    entryFilterValue.setText(syncSource.getEntryFilter());
    ldapUserValue.setText(syncSource.getLdapUser());
    ldapPassValue.setText(syncSource.getLdapPass());

    dbNameValue.setText(StringUtils.defaultIfEmpty(syncSource.getDbName(), "fnblds"));

    if (syncSource.getSourceURI() != null) {
        sourceUriValue.setEditable(false);
    }

    ldapServerValue.setSelectedItem(syncSource.getLdapInterfaceClassName());
}

From source file:org.adempiere.webui.dashboard.CalendarWindow.java

private void setTimeZone() {
    String alternateTimeZone = MSysConfig.getValue(MSysConfig.CALENDAR_ALTERNATE_TIMEZONE, "Pacific Time=PST",
            Env.getAD_Client_ID(Env.getCtx()));
    TimeZone defaultTimeZone = TimeZone.getDefault();
    calendars.addTimeZone(defaultTimeZone.getDisplayName(), defaultTimeZone);
    if (!Util.isEmpty(alternateTimeZone, true)) {
        if (!alternateTimeZone.equalsIgnoreCase(defaultTimeZone.getDisplayName())) {
            String[] pair = alternateTimeZone.split("=");
            calendars.addTimeZone(pair[0].trim(), pair[1].trim());
        }//from  w  ww.ja va2  s. c  o m
    }
}

From source file:edu.harvard.iq.safe.lockss.impl.DaemonStatusDataUtil.java

public static String getJVMTimezoneOffset() {
    String jvmTzOffset = null;//ww  w  .  j  a  v  a2 s  . c o  m

    Long jvmOffsetMins = TimeUnit.MILLISECONDS.toMinutes(TimeZone.getDefault().getRawOffset());
    logger.log(Level.FINE, "This JVM's  timezone offset in min={0}", jvmOffsetMins);

    Long jvmHourPart = jvmOffsetMins / 60L;
    // remove the sign from the min part to avoid a case like -04-30
    Long jvmMinPart = Math.abs(jvmOffsetMins % 60L);

    logger.log(Level.FINE, "jvmHourPart={0}", jvmHourPart);
    logger.log(Level.FINE, "jvmMinPart={0}", jvmMinPart);

    jvmTzOffset = getUTCOffsetString(jvmHourPart, jvmMinPart);
    if (StringUtils.isBlank(jvmTzOffset)) {
        logger.log(Level.WARNING, "JVM's timezone is NOT available: using the GMT+0000");
        jvmTzOffset = TIMEZONE_GMT0;
    }
    logger.log(Level.FINE, "This JVM's  timezone offset={0}", jvmTzOffset);
    return jvmTzOffset;
}

From source file:edu.dlnu.liuwenpeng.EachMintueTransactionSupport.SegmentedTimeline.java

/**    
* Returns the milliseconds for midnight of the first Monday after    
* 1-Jan-1900, ignoring daylight savings.    
*    /*from   w ww .j a  v a2  s . co m*/
* @return The milliseconds.    
*    
* @since 1.0.7    
*/
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to    
    // current locale    
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();    
    // preceding code won't work with JDK 1.3    
    return cal.getTime().getTime();
}

From source file:edu.dlnu.liuwenpeng.EachMintueTransactionSupport.SegmentedTimeline.java

/**    
* Constructs a new segmented timeline, optionaly using another segmented    
* timeline as its base. This chaining of SegmentedTimelines allows further    
* segmentation into smaller timelines.    
*    /*www .ja va2  s.c  o  m*/
* If a base    
*    
* @param segmentSize the size of a segment in ms. This time unit will be    
*        used to compute the included and excluded segments of the    
*        timeline.    
* @param segmentsIncluded Number of consecutive segments to include.    
* @param segmentsExcluded Number of consecutive segments to exclude.    
*/
public SegmentedTimeline(long segmentSize, int segmentsIncluded, int segmentsExcluded) {

    this.segmentSize = segmentSize;
    this.segmentsIncluded = segmentsIncluded;
    this.segmentsExcluded = segmentsExcluded;

    this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
    this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
    this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
    this.segmentsGroupSize = this.segmentsIncludedSize + this.segmentsExcludedSize;
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
    this.workingCalendarNoDST = new GregorianCalendar(z, Locale.getDefault());
}

From source file:com.iisigroup.cap.batch.handler.BatchHandler.java

/**
 * ?/*  ww w . j a v a  2 s.  c om*/
 * 
 * @param request
 *            IRequest
 * @return IResult
 */
public Result executionRestart(Request request) {
    AjaxFormResult result = new AjaxFormResult();
    try {
        String jobName = request.get("jobId");
        long jobInstanceId = Long.parseLong(request.get("jobInsId"));
        Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(jobName,
                jobInstanceId);
        new JobInfo(jobName, jobExecutions.size() + 1);
        JobExecution jobExecution = jobExecutions.iterator().next();
        new JobExecutionInfo(jobExecution, TimeZone.getDefault());

        Long jobExecutionId = jobExecution.getId();

        try {

            jobExecution = jobService.restart(jobExecutionId);
            new JobExecutionInfo(jobExecution, TimeZone.getDefault());

        } catch (NoSuchJobExecutionException e) {
            throw new CapMessageException("msg.job.noSuchJob", getClass());
        } catch (JobExecutionAlreadyRunningException e) {
            throw new CapMessageException("msg.job.alreadyRunning", getClass());
        } catch (JobRestartException e) {
            throw new CapMessageException("msg.job.restartExecption", getClass())
                    .setExtraInformation(new Object[] { jobName });
        } catch (JobInstanceAlreadyCompleteException e) {
            throw new CapMessageException("msg.job.alreadyComplete", getClass());
        } catch (JobParametersInvalidException e) {
            throw new CapMessageException("msg.job.parametersInvalid", getClass())
                    .setExtraInformation(new Object[] { jobName });
        }
    } catch (NoSuchJobException e) {
        throw new CapMessageException("msg.job.noSuchJob", getClass());
    }
    return result;
}

From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java

@Test
public void testYearlyNextRun() throws Exception {
    TimeZone tz = TimeZone.getDefault();

    // an event that runs every day at midnight
    String ical = "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "BEGIN:VEVENT\n"
            + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20140701T220000\n" + "RRULE:FREQ=YEARLY\n"
            + "SUMMARY:My Task\n"
            + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Action','properties':{'message':'Test'}}]\n"
            + "END:VEVENT\n" + "END:VCALENDAR";

    // start the scheduler when the task should have run
    MockScheduledTaskExecutor executor = new MockScheduledTaskExecutor();
    MockActionManager actionManager = new MockActionManager();
    ICalTaskProvider s = new ICalTaskProvider("pluginId", null, null, tz);
    s.setScheduleExecutor(executor);// w  ww .  j  av a 2  s  .c  om
    s.setActionManager(actionManager);
    s.loadICSStream(new ByteArrayInputStream(ical.getBytes()), DateHelper.getTime(tz, 2014, 8, 1, 21, 0, 0));

    // verify task was created and its next run time
    assertEquals(1, s.getTasks().size());
    ICalTask task = (ICalTask) s.getTasks().iterator().next();
    assertEquals(1435809600000l, task.getProperties().get(ICalTask.PROP_NEXT_RUN_TIME));
}

From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java

@Override
public String getServerTimezone(Locale locale) {
    TimeZone timeZone = TimeZone.getDefault();
    boolean daylight = timeZone.inDaylightTime(new Date());

    // Get the short timezone display name with respect to DST
    String timeZoneDisplay = timeZone.getDisplayName(daylight, TimeZone.SHORT, locale);

    // Get the offset in hours (divide by number of milliseconds in an hour)
    int offset = timeZone.getOffset(System.currentTimeMillis()) / (3600000);

    // Get the offset display in either UTC -x or UTC +x
    String offsetDisplay = (offset < 0) ? String.valueOf(offset) : "+" + offset;
    timeZoneDisplay += " (UTC " + offsetDisplay + ")";

    return timeZoneDisplay;
}

From source file:com.redhat.rhn.domain.user.UserFactory.java

/**
 * Gets the default time zone/* ww  w .  j a  va2s.c om*/
 * @return US Eastern Time Zone
 */
public static RhnTimeZone getDefaultTimeZone() {
    RhnTimeZone sysDefault = getTimeZone(TimeZone.getDefault().getID());
    if (sysDefault != null) {
        return sysDefault;
    }
    Session session = HibernateFactory.getSession();
    List<RhnTimeZone> allTimeZones = session.getNamedQuery("RhnTimeZone.loadAll").list();
    for (RhnTimeZone tz : allTimeZones) {
        if (TimeZone.getDefault().getRawOffset() == TimeZone.getTimeZone(tz.getOlsonName()).getRawOffset()) {
            return tz;
        }
    }
    // This should not happen unless the timezone table is incomplete
    return getTimeZone("America/New_York");
}

From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java

/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 * //from   w ww .  j av  a 2  s .  co m
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
    if (getTimeZone() == null) {
        setTimeZone(TimeZone.getDefault());
    }
    myPrecision = thePrecision;
    myFractionalSeconds = "";
    if (theValue != null) {
        long millis = theValue.getTime() % 1000;
        if (millis < 0) {
            // This is for times before 1970 (see bug #444)
            millis = 1000 + millis;
        }
        String fractionalSeconds = Integer.toString((int) millis);
        myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
    }
    super.setValue(theValue);
}