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.jaspersoft.jasperserver.war.common.JdkTimeZonesList.java

protected TimeZone getSystemDefault() {
    TimeZone defaultTz = TimeZone.getDefault();
    return defaultTz;
}

From source file:ch.algotrader.service.algo.VWAPOrderServiceTest.java

@Before
public void setup() {

    this.vwapOrderService = new VWAPOrderService(this.orderExecutionService, this.calendarService,
            this.simpleOrderService);
    this.vwapOrderService.setApplicationContext(this.applicationContext);

    Mockito.when(this.applicationContext.getBean(HistoricalDataService.class))
            .thenReturn(this.historicalDataService);

    this.exchange = Exchange.Factory.newInstance("TEST_EXCHANGE", TimeZone.getDefault().toString());
    this.exchange.setId(1);

    SecurityFamily family = SecurityFamily.Factory.newInstance("", Currency.USD, 1, 2, "0<0.01", true, false);
    family.setExchange(this.exchange);

    this.security = Stock.Factory.newInstance(family);
    this.security.setSymbol("TEST_SECURITY");
    this.security.setId(1);

    this.strategy = Strategy.Factory.newInstance("TEST_STRATEGY", false);

    this.historicalBars = new ArrayList<Bar>();
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 9, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 9123));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 9, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7061));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 9, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7635));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 9, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6984));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 10, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 8671));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 10, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7703));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 10, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6531));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 10, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 8234));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 11, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 5930));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 11, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 8151));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 11, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6053));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 11, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7192));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 12, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6314));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 12, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6391));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 12, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 5838));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 12, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6128));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 13, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6249));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 13, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7025));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 13, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 5997));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 13, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6658));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 14, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6946));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 14, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 4920));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 14, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 5094));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 14, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7601));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 15, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7192));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 15, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7482));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 15, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7393));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 15, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 6295));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 16, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 5955));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 16, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 8821));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 16, 30, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7751));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 16, 45, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 7976));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 17, 0, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 9067));
    this.historicalBars.add(Bar.Factory.newInstance(DateUtil.dateForYMDHMS(2016, 1, 1, 17, 15, 0), null,
            this.security, Duration.MIN_15, null, null, null, null, 10569));

    Mockito.when(this.historicalDataService.getHistoricalBars(this.security.getId(), //
            DateUtils.truncate(new Date(), Calendar.DATE), //
            this.lookBackDays, //
            TimePeriod.DAY, //
            this.bucketSize, //
            MarketDataEventType.TRADES, //
            Collections.emptyMap())).thenReturn(this.historicalBars);

    Mockito.when(this.calendarService.isOpen(this.exchange.getId())).thenReturn(false);

    Mockito.when(this.calendarService.getNextOpenTime(this.exchange.getId()))
            .thenReturn(DateUtil.dateForYMDHMS(2016, 1, 1, 9, 00, 0));

    Mockito.when(this.calendarService.getNextCloseTime(this.exchange.getId()))
            .thenReturn(DateUtil.dateForYMDHMS(2016, 1, 1, 17, 30, 0));
}

From source file:com.lm.lic.manager.util.GenUtil.java

public static Date resetClientTimezone(HttpServletRequest request, Date date) {
    final TimeZone timeZone = TimeZone.getDefault();
    final boolean daylight = timeZone.inDaylightTime(date);
    final Locale locale = request.getLocale();
    String tzName = timeZone.getDisplayName(daylight, TimeZone.LONG, locale);
    // String countryCode = locale.getCountry();
    // TimeZone ltz = TimeZone.getTimeZone(countryCode);
    // TimeZoneNameUtility.getZoneStrings(locale);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* w  w w.j av  a 2  s .com*/
    cal.setTimeZone(TimeZone.getTimeZone(tzName));
    return cal.getTime();
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * @param date//from w  ww  .jav a2s .  c o  m
 * @return
 * @throws
 * @Description:pattern??Date
 */
public static Date stringToDate(String date, String pattern) {
    return stringToDate(date, pattern, TimeZone.getDefault());
}

From source file:com.microsoft.tfs.core.TFSTeamProjectCollection.java

/**
 * A convenience constructor to create a {@link TFSTeamProjectCollection}
 * from a {@link URI}. A default {@link ConnectionAdvisor} is used.
 *
 * @param uri/* www .j  a v a2 s. co m*/
 *        the {@link URI} to use to connect (must not be <code>null</code>)
 * @param credentials
 *        the {@link Credentials} to connect with (or <code>null</code> to
 *        attempt to use the best available credentials)
 */
public TFSTeamProjectCollection(final URI serverURI, final Credentials credentials) {
    this(serverURI, credentials, new DefaultConnectionAdvisor(Locale.getDefault(), TimeZone.getDefault()));
}

From source file:org.openmeetings.utils.math.TimezoneUtil.java

/**
 * Return the timezone based on our internal jName
 * /*from   w ww  .  ja  v  a 2 s.c om*/
 * @param jName
 * @return
 */
public TimeZone getTimezoneByInternalJName(String jName) {

    OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jName);

    if (omTimeZone == null) {
        log.error("There is not omTimeZone for this jName: " + jName);
        throw new RuntimeException("There is not omTimeZone for this jName: " + jName);
    }

    TimeZone timeZone = TimeZone.getTimeZone(omTimeZone.getIcal());

    if (timeZone != null) {
        return timeZone;
    }

    // if user has not time zone get one from the server configuration

    Configuration conf = cfgManagement.getConfKey(3L, "default.timezone");

    if (conf != null) {

        OmTimeZone omTimeZoneDefault = omTimeZoneDaoImpl.getOmTimeZone(conf.getConf_value());

        TimeZone timeZoneByOmTimeZone = TimeZone.getTimeZone(omTimeZoneDefault.getIcal());

        if (timeZoneByOmTimeZone != null) {
            return timeZoneByOmTimeZone;
        }

    }

    // If everything fails take the servers default one
    log.error(
            "There is no correct time zone set in the configuration of OpenMeetings for the key default.timezone or key is missing in table, using default locale!");
    return TimeZone.getDefault();
}

From source file:com.marklogic.client.functionaltest.TestEvalXquery.java

void validateReturnTypes(EvalResultIterator evr) throws Exception {
    boolean inDST = TimeZone.getDefault().inDaylightTime(new Date());
    while (evr.hasNext()) {
        EvalResult er = evr.next();// ww  w  .  java 2s .  c  o m
        if (er.getType().equals(Type.XML)) {
            DOMHandle dh = new DOMHandle();
            dh = er.get(dh);
            if (dh.get().getDocumentElement().hasChildNodes()) {
                //             System.out.println("Type XML  :"+convertXMLDocumentToString(dh.get()));
                assertEquals("document has content",
                        "<foo attr=\"attribute\"><?processing instruction?><!--comment-->test1</foo>",
                        convertXMLDocumentToString(dh.get()));
            } else {
                assertEquals("element node ", "<test1/>", convertXMLDocumentToString(dh.get()));
            }
        } else if (er.getType().equals(Type.JSON)) {
            JacksonHandle jh = new JacksonHandle();
            jh = er.get(jh);
            //             System.out.println("Type JSON :"+jh.get().toString());
            assertTrue("document has object?", jh.get().has("test"));
        } else if (er.getType().equals(Type.TEXTNODE)) {
            assertTrue("document contains", er.getAs(String.class).equals("test1"));
            //             System.out.println("type txt node :"+er.getAs(String.class));

        } else if (er.getType().equals(Type.BINARY)) {
            FileHandle fh = new FileHandle();
            fh = er.get(fh);
            //             System.out.println("type binary :"+fh.get().length());
            assertEquals("files size", 2, fh.get().length());
        } else if (er.getType().equals(Type.BOOLEAN)) {
            assertTrue("Documents exist?", er.getBoolean());
            //             System.out.println("type boolean:"+er.getBoolean());
        } else if (er.getType().equals(Type.INTEGER)) {
            //             System.out.println("type Integer: "+er.getNumber().longValue());
            assertEquals("count of documents ", 31, er.getNumber().intValue());
        } else if (er.getType().equals(Type.STRING)) {
            //There is git issue 152
            assertEquals("String?", "xml", er.getString());
            System.out.println("type string: " + er.getString());
        } else if (er.getType().equals(Type.NULL)) {
            //There is git issue 151
            //             assertNull(er.getAs(String.class));
            System.out.println("Testing is empty sequence is NUll?" + er.getAs(String.class));
        } else if (er.getType().equals(Type.OTHER)) {
            //There is git issue 151
            //             System.out.println("Testing is Others? "+er.getAs(String.class));
            assertTrue("Returns OTHERs",
                    (er.getString().contains("xdmp:forest-restart#1") || er.getString().contains("PT0S")));

        } else if (er.getType().equals(Type.ANYURI)) {
            //             System.out.println("Testing is AnyUri? "+er.getAs(String.class));
            assertEquals("Returns me a uri :", "test1.xml", er.getAs(String.class));

        } else if (er.getType().equals(Type.DATE)) {
            //             System.out.println("Testing is DATE? "+er.getAs(String.class));
            if (inDST)
                assertEquals("Returns me a date :", "2002-03-07-07:00", er.getAs(String.class));
            else
                assertEquals("Returns me a date :", "2002-03-07-08:00", er.getAs(String.class));
        } else if (er.getType().equals(Type.DATETIME)) {
            //             System.out.println("Testing is DATETIME? "+er.getAs(String.class));
            if (inDST)
                assertEquals("Returns me a dateTime :", "2010-01-06T18:13:50.874-07:00",
                        er.getAs(String.class));
            else
                assertEquals("Returns me a dateTime :", "2010-01-06T17:13:50.874-08:00",
                        er.getAs(String.class));
        } else if (er.getType().equals(Type.DECIMAL)) {
            //             System.out.println("Testing is Decimal? "+er.getAs(String.class));
            assertEquals("Returns me a Decimal :", "10.5", er.getAs(String.class));

        } else if (er.getType().equals(Type.DOUBLE)) {
            //             System.out.println("Testing is Double? "+er.getAs(String.class));
            assertEquals(1.0471975511966, er.getNumber().doubleValue(), 0);

        } else if (er.getType().equals(Type.DURATION)) {
            System.out.println("Testing is Duration? " + er.getAs(String.class));
            //             assertEquals("Returns me a Duration :",0.4903562,er.getNumber().floatValue());
        } else if (er.getType().equals(Type.FLOAT)) {
            //             System.out.println("Testing is Float? "+er.getAs(String.class));
            assertEquals(20, er.getNumber().floatValue(), 0);
        } else if (er.getType().equals(Type.GDAY)) {
            //             System.out.println("Testing is GDay? "+er.getAs(String.class));
            assertEquals("Returns me a GDAY :", "---01", er.getAs(String.class));
        } else if (er.getType().equals(Type.GMONTH)) {
            //             System.out.println("Testing is GMonth "+er.getAs(String.class));
            assertEquals("Returns me a GMONTH :", "--01", er.getAs(String.class));
        } else if (er.getType().equals(Type.GMONTHDAY)) {
            //             System.out.println("Testing is GMonthDay? "+er.getAs(String.class));
            assertEquals("Returns me a GMONTHDAY :", "--12-25-14:00", er.getAs(String.class));
        } else if (er.getType().equals(Type.GYEAR)) {
            //             System.out.println("Testing is GYear? "+er.getAs(String.class));
            assertEquals("Returns me a GYEAR :", "2005-12:00", er.getAs(String.class));
        } else if (er.getType().equals(Type.GYEARMONTH)) {
            //             System.out.println("Testing is GYearMonth?1976-02 "+er.getAs(String.class));
            assertEquals("Returns me a GYEARMONTH :", "1976-02", er.getAs(String.class));
        } else if (er.getType().equals(Type.HEXBINARY)) {
            //             System.out.println("Testing is HEXBINARY? "+er.getAs(String.class));
            assertEquals("Returns me a HEXBINARY :", "BEEF", er.getAs(String.class));
        } else if (er.getType().equals(Type.QNAME)) {
            //             System.out.println("Testing is QNAME integer"+er.getAs(String.class));
            assertEquals("Returns me a QNAME :", "integer", er.getAs(String.class));
        } else if (er.getType().equals(Type.TIME)) {
            //             System.out.println("Testing is TIME? "+er.getAs(String.class));
            assertEquals("Returns me a TIME :", "10:00:00", er.getAs(String.class));
        } else if (er.getType().equals(Type.ATTRIBUTE)) {
            //             System.out.println("Testing is ATTRIBUTE? "+er.getAs(String.class));
            assertEquals("Returns me a ATTRIBUTE :", "attribute", er.getAs(String.class));

        } else if (er.getType().equals(Type.PROCESSINGINSTRUCTION)) {
            //             System.out.println("Testing is ProcessingInstructions? "+er.getAs(String.class));
            assertEquals("Returns me a PROCESSINGINSTRUCTION :", "<?processing instruction?>",
                    er.getAs(String.class));
        } else if (er.getType().equals(Type.COMMENT)) {
            //             System.out.println("Testing is Comment node? "+er.getAs(String.class));
            assertEquals("Returns me a COMMENT :", "<!--comment-->", er.getAs(String.class));
        } else if (er.getType().equals(Type.BASE64BINARY)) {
            //             System.out.println("Testing is Base64Binary  "+er.getAs(String.class));
            assertEquals("Returns me a BASE64BINARY :", "DEADBEEF", er.getAs(String.class));
        } else {
            System.out.println(
                    "Got something which is not belongs to anytype we support " + er.getAs(String.class));
            assertFalse("getting in else part, missing a type  ", true);
        }
    }
}

From source file:org.shredzone.cilla.admin.login.LoginBean.java

/**
 * Returns the {@link TimeZone} of the currently logged in user. It's a convenience
 * call for {@link UserDto#getTimeZone()}.
 *
 * @return {@link TimeZone} of the authenticated user, or the system's default time
 *         zone if not logged in/* w  w  w.j a va 2s.com*/
 */
public TimeZone getTimeZone() {
    UserDto user = getUser();
    return (user != null ? user.getTimeZone() : TimeZone.getDefault());
}

From source file:Currently.java

/**
 * Parses one of the ISO 8601 that it produces. Note, it will not
 * parse the full range of ISO timestamps.
 *
 * @param stamp is the textual timestamp representation.
 * @return a time or <code>null</code>, if unparsable.
 *///w w  w . j a  va 2s.  com
public static Date parse(String stamp) {
    // initialize the compiled expressions once
    if (c_pattern == null) {
        c_pattern = new Pattern[c_expression.length];
        for (int i = 0; i < c_expression.length; ++i) {
            c_pattern[i] = Pattern.compile(c_expression[i]);
        }
    }

    // match against pattern
    for (int i = 0; i < c_expression.length; ++i) {
        Matcher m = c_pattern[i].matcher(stamp);
        if (m.matches()) {
            Calendar c = Calendar.getInstance();
            TimeZone z = TimeZone.getDefault();
            if (m.group(9) != null && m.group(9).length() > 0) {
                boolean utc = (Character.toUpperCase(m.group(9).charAt(0)) == 'Z');
                if (utc) {
                    z = TimeZone.getTimeZone("GMT+0");
                } else {
                    z = TimeZone.getTimeZone("GMT" + m.group(9));
                }
            }

            c.setTimeZone(z);
            c.set(Calendar.YEAR, Integer.parseInt(m.group(1)));
            c.set(Calendar.MONTH, Integer.parseInt(m.group(2)) + (Calendar.JANUARY - 1));
            c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(3)));

            if (m.group(4).length() > 0) {
                c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(5)));
                c.set(Calendar.MINUTE, Integer.parseInt(m.group(6)));
                if (m.group(7) != null && m.group(7).length() > 0) {
                    c.set(Calendar.SECOND, Integer.parseInt(m.group(7)));
                }
                if (m.group(8) != null && m.group(8).length() > 1) {
                    String millis = m.group(8).substring(1);
                    while (millis.length() < 3) {
                        millis += "0";
                    }
                    millis = millis.substring(0, 3);
                    c.set(Calendar.MILLISECOND, Integer.parseInt(millis));
                }
            }

            return c.getTime();
        }
    }

    // not found
    return null;
}

From source file:org.jstockchart.dataset.TimeseriesDataset.java

/**
 * Creates a new <code>TimeseriesDataset</code> instance.
 * /*from   w ww  . j ava2s .co m*/
 * @param timePeriodClass
 *            the <code>TimePeriod</code> class.
 * @param step
 *            the step of the time period.
 * @param timeline
 *            a "segmented" timeline.
 * @param createAverage
 *            indicates whether or not the average chart should be created.
 */
public TimeseriesDataset(Class<? extends TimePeriod> timePeriodClass, int step, SegmentedTimeline timeline,
        boolean createAverage) {
    this(DEFAULT_PRICE_DESCRIPTION, DEFAULT_AVERAGE_DESCRIPTION, DEFAULT_VOLUME_DESCRIPTION, timePeriodClass,
            step, timeline, TimeZone.getDefault(), createAverage);
}