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:org.jfree.data.time.junit.MinuteTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from  ww  w .  j a  va  2 s  .c  o m*/
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(43, 15, 1, 4, 2006);
    assertEquals(1143902580000L, m.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.haulmont.cuba.gui.components.filter.edit.CustomConditionFrame.java

@Override
public void initComponents() {
    super.initComponents();

    typeSelect.addValueChangeListener(e -> {
        boolean disableTypeCheckBox = ParamType.UNARY.equals(typeSelect.getValue())
                || ParamType.BOOLEAN.equals(typeSelect.getValue());
        inExprCb.setEnabled(!disableTypeCheckBox);
        if (disableTypeCheckBox)
            inExprCb.setValue(false);/*www. ja v a2s .c  o  m*/

        boolean isEntity = ParamType.ENTITY.equals(typeSelect.getValue());
        boolean isEnum = ParamType.ENUM.equals(typeSelect.getValue());
        boolean isDate = ParamType.DATE.equals(typeSelect.getValue());

        entityLab.setEnabled(isEntity || isEnum);
        entitySelect.setEnabled(isEntity || isEnum);
        entitySelect.setRequired(entitySelect.isEnabled());
        paramWhereLab.setEnabled(isEntity);
        entityParamWhereField.setEnabled(isEntity);
        paramViewLab.setEnabled(isEntity);
        entityParamViewField.setEnabled(isEntity);

        useUserTimeZoneLab.setVisible(isDate);
        useUserTimeZone.setVisible(isDate);

        Param param = condition.getParam();
        fillEntitySelect(param);

        //recreate default value component based on param type
        if (!initializing && defaultValueLayout.isVisible()) {
            ParamType paramType = (ParamType) e.getValue();
            if ((isEntity || isEnum) && (entitySelect.getValue() == null)) {
                defaultValueLayout.remove(defaultValueComponent);
                param.setJavaClass(null);
            } else {
                Class paramJavaClass = getParamJavaClass(paramType);
                param.setJavaClass(paramJavaClass);
                param.setDefaultValue(null);
                createDefaultValueComponent();
            }
        }
    });

    inExprCb.addValueChangeListener(e -> {
        condition.getParam().setInExpr(BooleanUtils.isTrue((Boolean) e.getValue()));
        //recreate default value component based on "in list" checkbox value
        if (!initializing && defaultValueLayout.isVisible()) {
            condition.getParam().setDefaultValue(null);
            createDefaultValueComponent();
        }
    });

    useUserTimeZone.addValueChangeListener(e -> {
        if (defaultValueComponent != null) {
            if (defaultValueComponent instanceof DateField) {
                DateField dateField = (DateField) defaultValueComponent;
                if (Boolean.TRUE.equals(e.getValue())) {
                    UserSession userSession = userSessionSource.getUserSession();
                    if (userSession.getTimeZone() != null) {
                        dateField.setTimeZone(userSession.getTimeZone());
                    }
                    dateField.setValue(null);
                    dateField.setEditable(false);
                } else {
                    dateField.setTimeZone(TimeZone.getDefault());
                    dateField.setEditable(true);
                }
            }
        }
    });

    entitySelect.addValueChangeListener(e -> {
        if (initializing || !defaultValueLayout.isVisible()) {
            return;
        }
        if (e.getValue() == null) {
            defaultValueLayout.remove(defaultValueComponent);
            return;
        }
        Param param = condition.getParam();
        Class paramJavaClass = e.getValue() instanceof Class ? (Class) e.getValue()
                : ((MetaClass) e.getValue()).getJavaClass();
        param.setJavaClass(paramJavaClass);
        param.setDefaultValue(null);
        createDefaultValueComponent();
    });

    FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
    filterHelper.setLookupNullSelectionAllowed(typeSelect, false);
    filterHelper.setLookupFieldPageLength(typeSelect, 12);

    joinField.setSuggester((source, text, cursorPosition) -> requestHint(joinField, text, cursorPosition));
    joinField.setHighlightActiveLine(false);
    joinField.setShowGutter(false);

    whereField.setSuggester((source, text, cursorPosition) -> requestHint(whereField, text, cursorPosition));
    whereField.setHighlightActiveLine(false);
    whereField.setShowGutter(false);

    entityParamWhereField.setSuggester((source, text,
            cursorPosition) -> requestHintParamWhere(entityParamWhereField, text, cursorPosition));
    entityParamWhereField.setHighlightActiveLine(false);
    entityParamWhereField.setShowGutter(false);
}

From source file:org.jfree.data.time.junit.SecondTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *///ww w .  ja  va2  s . c o  m
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(15, 43, 15, 1, 4, 2006);
    assertEquals(1143902595000L, s.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:info.magnolia.cms.core.MetaData.java

/**
 * Part of metadata, adds creation date of the current node
 *///from w  w  w . j a  v a2 s  .  c o  m
public void setCreationDate() throws AccessDeniedException {
    allowUpdate();
    Calendar value = new GregorianCalendar(TimeZone.getDefault());
    setProperty(this.getInternalPropertyName(CREATION_DATE), value);
}

From source file:edu.dlnu.liuwenpeng.Time.TimeSeriesCollection.java

/**    
* Constructs an empty dataset, tied to the default timezone.    
*/
public TimeSeriesCollection() {
    this(null, TimeZone.getDefault());
}

From source file:org.jfree.data.time.Week.java

/**
 * Creates a time period for the week in which the specified date/time
 * falls, using the default time zone and locale (the locale can affect the
 * day-of-the-week that marks the beginning of the week, as well as the
 * minimal number of days in the first week of the year).
 *
 * @param time  the time (<code>null</code> not permitted).
 *
 * @see #Week(Date, TimeZone, Locale)/*from w ww.  jav a 2s .co  m*/
 */
public Week(Date time) {
    // defer argument checking...
    this(time, TimeZone.getDefault(), Locale.getDefault());
}

From source file:org.activequant.util.charting.IntradayMarketTimeline.java

/**
 * Translates a millisecond (as defined by java.util.Date) into an index
 * along this timeline./*w  w  w.  j ava2 s .c o m*/
 *
 * @param target - the milliseconds of a date to convert
 *
 * @return A timeline value.
 */
public long toTimelineValue(long currentDayMillis) {

    //
    //find out the day of the week the current day is
    //SUNDAY = 1,...SATURDAY = 7
    Calendar currentDay = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    currentDay.setTimeInMillis(currentDayMillis);

    //a list of the days from the current date until last thursday 00:00
    //which includes thursday itself from (00:00,23:59)
    ArrayList<Integer> daysFromThursday = new ArrayList<Integer>();

    Calendar lastThursday = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

    lastThursday.setTimeInMillis(currentDayMillis);

    //move backwards in time until you hit a wednesday
    while (lastThursday.get(Calendar.DAY_OF_WEEK) != Calendar.THURSDAY) {
        //add this day to the list
        daysFromThursday.add(new Integer(lastThursday.get(Calendar.DAY_OF_WEEK)));
        //
        //move back one more day
        lastThursday.add(Calendar.DATE, -1);
    }
    //
    //add thursday to the list
    daysFromThursday.add(new Integer(Calendar.THURSDAY));

    //adjust Calendar to the beginning of last thursday
    lastThursday.set(Calendar.MILLISECOND, 0);
    lastThursday.set(Calendar.SECOND, 0);
    lastThursday.set(Calendar.MINUTE, 0);
    lastThursday.set(Calendar.HOUR_OF_DAY, 0);

    //get the milliseconds for the beginning of last Thursday
    long lastThursdayMillis = lastThursday.getTimeInMillis();

    //because Jan 1, 1970 was a Thursday, lastThursdayMillis
    //gives an even # of weeks from Jan 1, 1970 until lastThursdayMillis. 
    //so subtract the (down time per week * the
    //number of weeks) since Jan 1, 1970

    //the number of weeks since Jan 1, 1970
    int numberOfWeeks = (int) Math.round((new Long(lastThursdayMillis / MILLIS_PER_WEEK)).doubleValue());
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    TimeZone.setDefault(TimeZone.getDefault());

    //get the timeline value for the number of millis since
    //Jan 1, 1970 to last thursday, by multiplying the number of weeks
    //since Jan 1, 1970 by the amount of active milliseconds per week
    long timelineValue = numberOfWeeks * this.activeTimePerWeek;
    //          
    //add the amount of active millseconds for the current day
    //of the given time
    long millisOfCurrentDay = currentDay.get(Calendar.HOUR_OF_DAY) * 3600000
            + currentDay.get(Calendar.MINUTE) * 60000 + currentDay.get(Calendar.SECOND) * 1000
            + currentDay.get(Calendar.MILLISECOND);

    long startOfCurrentDay = this.getStartTime(currentDay.get(Calendar.DAY_OF_WEEK));
    long endOfCurrentDay = this.getEndTime(currentDay.get(Calendar.DAY_OF_WEEK));

    if (millisOfCurrentDay >= startOfCurrentDay && millisOfCurrentDay <= endOfCurrentDay) {

        timelineValue += millisOfCurrentDay - startOfCurrentDay;
    }

    //get the size of the list
    int listSize = daysFromThursday.size();

    //add the active time since last thursday, skipping the first day since
    //we already took care of that
    for (int i = 1; i < listSize; i++) {
        int day = ((Integer) daysFromThursday.get(i)).intValue();

        timelineValue += this.getActiveTimePerDay(day);

    }

    return timelineValue;
}

From source file:org.jfree.data.time.HourTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from   ww w.  j  a  v  a 2s  .  com*/
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Hour h = new Hour(15, 1, 4, 2006);
    assertEquals(1143900000000L, h.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.concursive.connect.web.modules.login.utils.UserUtils.java

public static User createGuestUser() {
    User user = new User();
    user.setId(-2);//from w w  w.ja v a  2s .  com
    user.setIdRange("-2");
    user.setGroupId(1);
    user.setFirstName("Guest");
    user.setEnabled(true);
    // @todo Use applicationPrefs for the correct defaults
    // Set a default time zone for user
    if (user.getTimeZone() == null) {
        user.setTimeZone(TimeZone.getDefault().getID());
    }
    // Set a default currency for user
    if (user.getCurrency() == null) {
        user.setCurrency(NumberFormat.getCurrencyInstance().getCurrency().getCurrencyCode());
    }
    // Set default locale: language, country
    if (user.getLanguage() == null) {
        user.setLanguage("en_US");
    }
    return user;
}

From source file:com.bdb.weather.display.RainPlot.java

/**
 * Load the rain data.//www .jav a2  s  . c  o m
 * 
 * @param list The list of historical records for the rainfall graph.
 */
public void setRainData(List<RainEntry> list) {
    if (list.size() == rainSeries.getItemCount()) {
        RegularTimePeriod n0 = RegularTimePeriod.createInstance(Minute.class,
                TimeUtils.localDateTimeToDate(list.get(0).time), TimeZone.getDefault());
        RegularTimePeriod n1 = RegularTimePeriod.createInstance(Minute.class,
                TimeUtils.localDateTimeToDate(list.get(list.size() - 1).time), TimeZone.getDefault());

        RegularTimePeriod e0 = rainSeries.getDataItem(0).getPeriod();
        RegularTimePeriod e1 = rainSeries.getDataItem(rainSeries.getItemCount() - 1).getPeriod();

        //
        // If the first and last times are the same between what's been plotted and what was passed in, the graph is up to date,
        // do nothing.
        //
        if (n0.equals(e0) && n1.equals(e1)) {
            return;
        }
    }

    rainSeries.clear();
    rainRateSeries.clear();

    if (list.size() > 0) {
        rainPlot.clearDomainMarkers();
        //
        // Load the graph
        //
        for (RainEntry r : list) {
            RegularTimePeriod p = RegularTimePeriod.createInstance(Minute.class,
                    TimeUtils.localDateTimeToDate(r.time), TimeZone.getDefault());

            if (r.rainfall != null) {
                TimeSeriesDataItem item = new TimeSeriesDataItem(p, r.rainfall.get());
                rainSeries.add(item);
            }

            if (r.rainfallRate != null) {
                TimeSeriesDataItem item = new TimeSeriesDataItem(p, r.rainfallRate.get());
                rainRateSeries.add(item);
            }
        }

        rainPlot.getRangeAxis().setAutoRange(true);

        addMarker(list.get(list.size() - 1).time);
    }
}