List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:org.jfree.data.time.QuarterTest.java
/** * Some checks for the getFirstMillisecond() method. *//* www . j av 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")); Quarter q = new Quarter(3, 1970); assertEquals(15634800000L, q.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.agiso.tempel.Tempel.java
/** * //from ww w.j av a 2 s . c o m * * @param properties * @throws Exception */ private Map<String, Object> addRuntimeProperties(Map<String, Object> properties) throws Exception { Map<String, Object> props = new HashMap<String, Object>(); // Okrelanie lokalizacji daty/czasu uywanej do wypenienia paramtrw szablonw // zawierajcych dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL: Locale date_locale; if (properties.containsKey(UP_DATE_LOCALE)) { date_locale = LocaleUtils.toLocale((String) properties.get(UP_DATE_LOCALE)); Locale.setDefault(date_locale); } else { date_locale = Locale.getDefault(); } TimeZone time_zone; if (properties.containsKey(UP_TIME_ZONE)) { time_zone = TimeZone.getTimeZone((String) properties.get(UP_DATE_LOCALE)); TimeZone.setDefault(time_zone); } else { time_zone = TimeZone.getDefault(); } // Wyznaczanie daty, na podstawie ktrej zostan wypenione parametry szablonw // przechowujce dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL. // Odbywa si w oparciu o wartoci parametrw 'date_format' i 'date'. Parametr // 'date_format' definiuje format uywany do parsowania acucha reprezentujcego // dat okrelon parametrem 'date'. Parametr 'date_format' moe nie by okrelony. // W takiej sytuacji uyty jest format DateFormat.LONG aktywnej lokalizacji (tj. // systemowej, ktra moe by przedefiniowana przez parametr 'date_locale'), ktry // moe by przedefiniowany przez parametry 'date_format_long' i 'time_format_long': Calendar calendar = Calendar.getInstance(date_locale); if (properties.containsKey(RP_DATE)) { String date_string = (String) properties.get(RP_DATE); if (properties.containsKey(RP_DATE_FORMAT)) { String date_format = (String) properties.get(RP_DATE_FORMAT); DateFormat formatter = new SimpleDateFormat(date_format); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else if (properties.containsKey(UP_DATE_FORMAT_LONG) && properties.containsKey(UP_TIME_FORMAT_LONG)) { // TODO: Zaoenie, e format data-czas jest zoony z acucha daty i czasu rozdzelonych spacj: // 'UP_DATE_FORMAT_LONG UP_TIME_FORMAT_LONG' DateFormat formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG) + " " + (String) properties.get(UP_TIME_FORMAT_LONG), date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else { DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } } // Jeli nie okrelono, wypenianie parametrw przechowujcych poszczeglne // skadniki daty, tj. rok, miesic i dzie: if (!properties.containsKey(TP_YEAR)) { props.put(TP_YEAR, calendar.get(Calendar.YEAR)); } if (!properties.containsKey(TP_MONTH)) { props.put(TP_MONTH, calendar.get(Calendar.MONTH)); } if (!properties.containsKey(TP_DAY)) { props.put(TP_DAY, calendar.get(Calendar.DAY_OF_MONTH)); } // Jeli nie okrelono, wypenianie parametrw przechowujcych dat i czas w // formatach SHORT, MEDIUM, LONG i FULL (na podstawie wyznaczonej lokalizacji): Date date = calendar.getTime(); if (!properties.containsKey(TP_DATE_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_DATE_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_DATE_LONG)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_LONG, formatter.format(date)); } if (!properties.containsKey(TP_DATE_FULL)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_FULL, formatter.format(date)); } if (!properties.containsKey(TP_TIME_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_TIME_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_TIME_LONG)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_LONG, formatter.format(date)); } if (!properties.containsKey(TP_TIME_FULL)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_FULL, formatter.format(date)); } return props; }
From source file:com.rogchen.common.xml.UtilDateTime.java
/** * ? ?// w ww . ja va 2 s. c o m * * @param stamp * @param daysLater * @return */ public static Timestamp getDayEnd(Timestamp stamp, Long daysLater) { return getDayEnd(stamp, daysLater, TimeZone.getDefault(), Locale.getDefault()); }
From source file:com.microsoft.tfs.client.common.credentials.CredentialsHelper.java
private static boolean isCredentialsValid(URI baseURI, Credentials credentials) { /*/*from ww w .ja v a2s. c o m*/ * At this point we do not have any connection which HTTPClient we might * use to create a TeeClientHandler. Let's create a fake one. We do not * use the connection we create here as a real TFSTeamProjectColection. * We only use this fake connection object as a source of an HTTPClient * configured to use the VSTS credentials provided. */ final TFSTeamProjectCollection rootConnection = new TFSTeamProjectCollection(baseURI, credentials, new CommonClientConnectionAdvisor(Locale.getDefault(), TimeZone.getDefault())); final AccountHttpClient client = new AccountHttpClient(new TeeClientHandler(rootConnection.getHTTPClient()), baseURI); try { return client.checkConnection(); } finally { /* * We didn't use any features of the vstsConnection but the * HTTPClient. However to release all resources and the * infrastructure created for the connection (e.g. * ShoultDownManager, HTTPClientReference, Service Clients, etc.), * we still should close this connection when leaving the try-catch * block. */ try { rootConnection.close(); } catch (final Exception e) { log.error("Absolutelly unexpected error while closing not opened connection", e); //$NON-NLS-1$ } } }
From source file:com.wildplot.android.ankistats.HourlyBreakdown.java
public boolean calculateBreakdown(int type) { mTitle = R.string.stats_breakdown;//w w w . j a va 2 s . c om mAxisTitles = new int[] { R.string.stats_time_of_day, R.string.stats_percentage_correct, R.string.stats_reviews }; mValueLabels = new int[] { R.string.stats_percentage_correct, R.string.stats_answers }; mColors = new int[] { R.color.stats_counts, R.color.stats_hours }; mType = type; String lim = _revlogLimitWholeOnly().replaceAll("[\\[\\]]", ""); if (lim.length() > 0) { lim = " and " + lim; } Calendar sd = GregorianCalendar.getInstance(); sd.setTimeInMillis(mCollectionData.getCrt() * 1000); Calendar cal = Calendar.getInstance(); TimeZone tz = TimeZone.getDefault(); /* date formatter in local timezone */ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); sdf.setTimeZone(tz); /* print your timestamp and double check it's the date you expect */ String localTime = sdf.format(new Date(mCollectionData.getCrt() * 1000)); // I assume your timestamp is in seconds and you're converting to milliseconds? int pd = _periodDays(); if (pd > 0) { lim += " and id > " + ((mCollectionData.getDayCutoff() - (86400 * pd)) * 1000); } int hourOfDay = sd.get(GregorianCalendar.HOUR_OF_DAY); long cutoff = mCollectionData.getDayCutoff(); long cut = cutoff - sd.get(Calendar.HOUR_OF_DAY) * 3600; ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "select " + "23 - ((cast((" + cut + " - id/1000) / 3600.0 as int)) % 24) as hour, " + "sum(case when ease = 1 then 0 else 1 end) / " + "cast(count() as float) * 100, " + "count() " + "from revlog where type in (0,1,2) " + lim + " " + "group by hour having count() > 30 order by hour"; Log.d(AnkiStatsApplication.TAG, sd.get(Calendar.HOUR_OF_DAY) + " : " + cutoff + " breakdown query: " + query); try { cur = mAnkiDb.getDatabase().rawQuery(query, null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for breakdown, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine // if (list.size() == 0 || list.get(0)[0] > 0) { // list.add(0, new double[] { 0, 0, 0 }); // } // if (num == -1 && list.size() < 2) { // num = 31; // } // if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) { // list.add(new double[] { num, 0, 0 }); // } else if (type == Utils.TYPE_LIFE && list.size() < 2) { // list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0, 0 }); // } for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int intHour = (int) data[0]; int hour = (intHour - 4) % 24; if (hour < 0) hour += 24; data[0] = hour; list.set(i, data); } Collections.sort(list, new Comparator<double[]>() { @Override public int compare(double[] s1, double[] s2) { if (s1[0] < s2[0]) return -1; if (s1[0] > s2[0]) return 1; return 0; } }); mSeriesList = new double[4][list.size()]; mPeak = 0.0; mMcount = 0.0; double minHour = Double.MAX_VALUE; double maxHour = 0; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int hour = (int) data[0]; //double hour = data[0]; if (hour < minHour) minHour = hour; if (hour > maxHour) maxHour = hour; double pct = data[1]; if (pct > mPeak) mPeak = pct; mSeriesList[0][i] = hour; mSeriesList[1][i] = pct; mSeriesList[2][i] = data[2]; if (i == 0) { mSeriesList[3][i] = pct; } else { double prev = mSeriesList[3][i - 1]; double diff = pct - prev; diff /= 3.0; diff = Math.round(diff * 10.0) / 10.0; mSeriesList[3][i] = prev + diff; } if (data[2] > mMcount) mMcount = data[2]; if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) mSeriesList[1][i]; } mMaxElements = (int) (maxHour - minHour); return list.size() > 0; }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Constructs a dataset containing a single series (more can be added), * tied to a specific timezone./*from w w w.j a v a 2s . c o m*/ * * @param series a series to add to the collection (<code>null</code> * permitted). * @param zone the timezone (<code>null</code> permitted, will use * <code>TimeZone.getDefault()</code> in that case). */ public TimeSeriesCollection(TimeSeries series, TimeZone zone) { // FIXME: need a locale as well as a timezone if (zone == null) { zone = TimeZone.getDefault(); } this.workingCalendar = Calendar.getInstance(zone); this.data = new ArrayList(); if (series != null) { this.data.add(series); series.addChangeListener(this); } this.xPosition = TimePeriodAnchor.START; this.domainIsPointsInTime = true; }
From source file:org.jfree.data.time.MillisecondTest.java
/** * Some checks for the getLastMillisecond() method. *//* ww w. j av a 2 s . c om*/ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(750, 1, 1, 1, 1, 1, 1970); assertEquals(61750L, m.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.junit.MinuteTest.java
/** * Some checks for the getLastMillisecond() method. */// w w w .j ava 2 s . com 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.junit.SecondTest.java
/** * Some checks for the getLastMillisecond() method. *///from w w w . java2s . c o m 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:com.jaxzin.iraf.forecast.swing.JForecaster.java
@SuppressWarnings({ "MethodWithMultipleLoops" }) protected XYDataset createDataset() { final TimeSeriesCollection tsc = new TimeSeriesCollection(); // long start = System.currentTimeMillis(); Forecast forecastData = null;//w w w. java 2s.com try { // System.out.println("Generating dataset; initial salary is <"+domain.getInitialSalary()+">"); forecastData = forecaster.forecast(domain); } catch (ForecastException e) { e.printStackTrace(); } int count = 1; assert forecastData != null; final int total = forecastData.getForecastData().size() + 1; //noinspection ForLoopThatDoesntUseLoopVariable for (Iterator i = forecastData.getForecastData().iterator(); i.hasNext(); count++) { final List<Money> universeData = (List<Money>) i.next(); //noinspection ObjectAllocationInLoop,UnqualifiedStaticUsage final TimeSeries ts = new TimeSeries(new StringBuilder() .append(String.valueOf((count * TOTAL_PERCENTILES) / total)).append("th").toString(), Year.class); for (Money money : universeData) { if (ts.getItemCount() == 0) { //noinspection ObjectAllocationInLoop ts.add(RegularTimePeriod.createInstance(Year.class, new Date(), TimeZone.getDefault()), money.doubleValue()); } else { ts.add(ts.getNextTimePeriod(), money.doubleValue()); } } tsc.addSeries(ts); } // System.out.println(System.currentTimeMillis()-start); return tsc; }