Example usage for java.util TimeZone setDefault

List of usage examples for java.util TimeZone setDefault

Introduction

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

Prototype

public static void setDefault(TimeZone zone) 

Source Link

Document

Sets the TimeZone that is returned by the getDefault method.

Usage

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

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from  w  w w.  jav a  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:org.jfree.data.time.junit.SecondTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from   ww w  .ja  v a2s.  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:it.damore.solr.importexport.App.java

/**
 * @param client//  www .  ja  v  a 2  s  .c  o m
 * @param outputFile
 * @throws SolrServerException
 * @throws IOException
 */
private static void readAllDocuments(HttpSolrClient client, File outputFile)
        throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    if (config.getFilterQuery() != null) {
        solrQuery.addFilterQuery(config.getFilterQuery());
    }
    solrQuery.setRows(0);

    solrQuery.addSort(config.getUniqueKey(), ORDER.asc); // Pay attention to this line

    String cursorMark = CursorMarkParams.CURSOR_MARK_START;

    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    // objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    DateFormat df = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:sss'Z'");
    objectMapper.setDateFormat(df);
    objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);

    QueryResponse r = client.query(solrQuery);

    long nDocuments = r.getResults().getNumFound();
    logger.info("Found " + nDocuments + " documents");

    if (!config.getDryRun()) {
        logger.info("Creating " + config.getFileName());

        Set<SkipField> skipFieldsEquals = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.EQUAL).collect(Collectors.toSet());
        Set<SkipField> skipFieldsStartWith = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.STARTS_WITH).collect(Collectors.toSet());
        Set<SkipField> skipFieldsEndWith = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.ENDS_WITH).collect(Collectors.toSet());

        try (PrintWriter pw = new PrintWriter(outputFile)) {
            solrQuery.setRows(200);
            boolean done = false;
            while (!done) {
                solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
                QueryResponse rsp = client.query(solrQuery);
                String nextCursorMark = rsp.getNextCursorMark();

                for (SolrDocument d : rsp.getResults()) {
                    skipFieldsEquals.forEach(f -> d.removeFields(f.getText()));
                    if (skipFieldsStartWith.size() > 0 || skipFieldsEndWith.size() > 0) {
                        Map<String, Object> collect = d.entrySet().stream()
                                .filter(e -> !skipFieldsStartWith.stream()
                                        .filter(f -> e.getKey().startsWith(f.getText())).findFirst()
                                        .isPresent())
                                .filter(e -> !skipFieldsEndWith.stream()
                                        .filter(f -> e.getKey().endsWith(f.getText())).findFirst().isPresent())
                                .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
                        pw.write(objectMapper.writeValueAsString(collect));
                    } else {
                        pw.write(objectMapper.writeValueAsString(d));
                    }
                    pw.write("\n");
                }
                if (cursorMark.equals(nextCursorMark)) {
                    done = true;
                }

                cursorMark = nextCursorMark;
            }

        }
    }

}

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

/**
 * Translates a millisecond (as defined by java.util.Date) into an index
 * along this timeline.//from www .jav  a  2s  .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.
 *///www  .j a va2  s .  c om
@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:net.audumla.astronomy.algorithims.AstronomicalTest.java

@Test
public void testWrapperMethodsRome() throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    CelestialObject sun = new Sun();
    Calendar c = Calendar.getInstance(TimeZone.getDefault());
    c.setTimeInMillis(0);/*from   w w w  . ja  va2 s. c o m*/
    c.set(Calendar.YEAR, 2009);
    c.set(Calendar.MONTH, Calendar.AUGUST);
    c.set(Calendar.DAY_OF_MONTH, 8);

    Date date = c.getTime();
    Geolocation.Location location = new Geolocation.Location();
    location.setLatitude(41.9000, Geolocation.Direction.NORTH);
    location.setLongitude(12.5000, Geolocation.Direction.EAST);
    TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL);
    logger.debug("Rome");
    logger.debug("Date    : " + date);
    logger.debug("Julian  : " + new JulianDate(date).julian());
    logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime());
    logger.debug("Sunset  : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime());
    Assert.assertEquals(details.getRiseTime().getTime(), 1249702797298l, 1000);
    Assert.assertEquals(details.getSetTime().getTime(), 1249757426299l, 1000);
}

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

/**
 * Some checks for the getFirstMillisecond() method.
 */// w ww . j a v  a  2 s  . c o m
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Year y = new Year(1970);
    // TODO: Check this result...
    assertEquals(-3600000L, y.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*from   w  ww . ja  va2 s  .c o  m*/
@Test
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(1, 1, 1, 1, 1970);
    assertEquals(119999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*  ww w .j a  va 2  s .c  o m*/
@Test
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(1, 1, 1, 1, 1, 1970);
    assertEquals(61999L, s.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:at.jku.rdfstats.RDFStatsConfiguration.java

private RDFStatsConfiguration(Model statsModel, List<String> endpoints, List<String> documentURLs,
        //         boolean classSpecific,
        Integer prefSize, String outFile, String outFormat, Integer strHistMaxLen, boolean quickMode,
        TimeZone timeZone) {/*  www .  java2 s  .c o m*/

    this.statsModel = (statsModel != null) ? statsModel : ModelFactory.createDefaultModel();
    this.endpoints = (endpoints != null) ? endpoints : new ArrayList<String>();
    this.documentURLs = (documentURLs != null) ? documentURLs : new ArrayList<String>();
    //      this.classSpecific = classSpecific;
    this.prefSize = (prefSize != null) ? prefSize : DEFAULT_PREFSIZE;
    this.outFile = (outFile != null) ? outFile : DEFAULT_OUTFILE;
    this.outFormat = (outFormat != null) ? outFormat : DEFAULT_OUTFORMAT;
    this.strHistMaxLength = (strHistMaxLen != null) ? strHistMaxLen : DEFAULT_STRHIST_MAXLEN;
    this.quickMode = quickMode;
    this.defaultTimeZone = (timeZone != null) ? timeZone : TimeZone.getDefault();
    TimeZone.setDefault(this.defaultTimeZone);

    String hostname = "";
    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ignore) {
    } finally {
        this.localHostname = hostname;
    }
}