List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java
/** * Downloads the header images for the given woeid and weather-data. Failure is considered * non-fatal./*from ww w. ja va 2 s. c o m*/ * * @throws VolleyError */ public static void downloadWeatherImages(Context context, BitmapUtils bitmapUtils, String woeid, WeatherData weatherData, String timezone) throws VolleyError { WindowManager windowManager = AppInjector.provideWindowManager(); // first we need to determine if it is day or night. // TODO: this needs the timezone if (timezone == null) { timezone = TimeZone.getDefault().getID(); } WeatherUtils weatherUtils = AppInjector.provideWeatherUtils(); boolean isDay = weatherUtils.isDay(timezone, weatherData); ImageDownloadHelper downloadHelper = ImageDownloadHelper.getInstance(context); // call into the download-helper this will return a json object with // city photos matching the current weather condition. JSONObject photos = downloadHelper.searchCityWeatherPhotos(woeid, weatherData.nowConditionCode, isDay); // Now we need the screen dimension to know which photos have a usable size. int dimen = getMaxScreenDimension(windowManager); // determine the photos that can be used. List<ImageDownloadHelper.PhotoInfo> result = new ArrayList<>(); ImageDownloadHelper.getEligiblePhotosFromResponse(photos, result, dimen); // when no usable photos have been found try photos at the city level with // no weather condition info. if (result.isEmpty()) { photos = downloadHelper.searchCityImage(woeid); ImageDownloadHelper.getEligiblePhotosFromResponse(photos, result, dimen); // when still no photo was found, clear the existing photos and return if (result.isEmpty()) { weatherUtils.clearCityPhotos(context, woeid, 0); return; } } // Now determine the amount of photos we should download int N = Math.min(MAX_PHOTO_COUNT, result.size()); // idx keeps the index of the actually downloaded photo count int idx = 0; // note the idx < N instead of i < N. // this loop must continue until the amount is satisfied. for (int i = 0; idx < N; i++) { // quit when the end of the list is reached if (i >= result.size()) break; // try to download the photo details from the webservice. ImageDownloadHelper.PhotoInfo info = result.get(i); JSONObject photoInfo = downloadHelper.loadPhotoInfo(context, info.id); if (photoInfo != null) { // we need to know if the photo is rotated. If so, we need to apply this // rotation after download. int rotation = ImageDownloadHelper.getRotationFromJson(photoInfo); if (downloadFile(context, info, woeid, idx)) { // Apply rotation when non zero if (rotation != 0) { File cacheDir = weatherUtils.getWeatherPhotoCacheDir(context); String fileName = weatherUtils.createPhotoFileName(woeid, idx); File photoImage = new File(cacheDir, fileName); Bitmap bitmap = bitmapUtils.decodeSampledBitmapFromFile(photoImage, dimen, dimen); if (bitmap == null) { Log.wtf("WeatherLoadingService", "error decoding bitmap"); continue; } Matrix matrix = new Matrix(); matrix.postRotate(rotation); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); weatherUtils.saveBitmap(context, bitmap, woeid, idx); } // success, handle the next one. idx++; } } } // remove photos at higher indexes than the amount downloaded. weatherUtils.clearCityPhotos(context, woeid, idx + 1); }
From source file:org.jfree.data.time.Month.java
/** * Constructs a new <code>Month</code> instance, based on a date/time and * the default time zone.// w ww . j a v a 2 s . c om * * @param time the date/time (<code>null</code> not permitted). * * @see #Month(Date, TimeZone, Locale) */ public Month(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); }
From source file:org.jfree.data.time.Second.java
/** * Constructs a new instance from the specified date/time and the default * time zone../*from w ww . j ava2 s .co m*/ * * @param time the time (<code>null</code> not permitted). * * @see #Second(Date, TimeZone) */ public Second(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); }
From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java
public void testDateTimeTimestampWithCalendar() throws SQLException { Statement stat = conn.createStatement(); stat.execute("create table ts(x timestamp primary key)"); stat.execute("create table t(x time primary key)"); stat.execute("create table d(x date)"); Calendar utcCalendar = new GregorianCalendar(new SimpleTimeZone(0, "Z")); TimeZone old = TimeZone.getDefault(); DateTimeUtils.resetCalendar();/*from w w w . j ava 2 s .c o m*/ TimeZone.setDefault(TimeZone.getTimeZone("PST")); try { Timestamp ts1 = Timestamp.valueOf("2010-03-13 18:15:00"); Time t1 = new Time(ts1.getTime()); Date d1 = new Date(ts1.getTime()); // when converted to UTC, this is 03:15, which doesn't actually exist // because of summer time change at that day Timestamp ts2 = Timestamp.valueOf("2010-03-13 19:15:00"); Time t2 = new Time(ts2.getTime()); Date d2 = new Date(ts2.getTime()); PreparedStatement prep; ResultSet rs; prep = conn.prepareStatement("insert into ts values(?)"); prep.setTimestamp(1, ts1, utcCalendar); prep.execute(); prep.setTimestamp(1, ts2, utcCalendar); prep.execute(); prep = conn.prepareStatement("insert into t values(?)"); prep.setTime(1, t1, utcCalendar); prep.execute(); prep.setTime(1, t2, utcCalendar); prep.execute(); prep = conn.prepareStatement("insert into d values(?)"); prep.setDate(1, d1, utcCalendar); prep.execute(); prep.setDate(1, d2, utcCalendar); prep.execute(); rs = stat.executeQuery("select * from ts order by x"); rs.next(); assertEquals("2010-03-14 02:15:00.0", rs.getString(1)); assertEquals("2010-03-13 18:15:00.0", rs.getTimestamp(1, utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp(1).toString()); assertEquals("2010-03-14 02:15:00.0", rs.getString("x")); assertEquals("2010-03-13 18:15:00.0", rs.getTimestamp("x", utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp("x").toString()); rs.next(); assertEquals("2010-03-14 03:15:00.0", rs.getString(1)); assertEquals("2010-03-13 19:15:00.0", rs.getTimestamp(1, utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp(1).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getString("x")); assertEquals("2010-03-13 19:15:00.0", rs.getTimestamp("x", utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp("x").toString()); rs = stat.executeQuery("select * from t order by x"); rs.next(); assertEquals("02:15:00", rs.getString(1)); assertEquals("18:15:00", rs.getTime(1, utcCalendar).toString()); assertEquals("02:15:00", rs.getTime(1).toString()); assertEquals("02:15:00", rs.getString("x")); assertEquals("18:15:00", rs.getTime("x", utcCalendar).toString()); assertEquals("02:15:00", rs.getTime("x").toString()); rs.next(); assertEquals("03:15:00", rs.getString(1)); assertEquals("19:15:00", rs.getTime(1, utcCalendar).toString()); assertEquals("03:15:00", rs.getTime(1).toString()); assertEquals("03:15:00", rs.getString("x")); assertEquals("19:15:00", rs.getTime("x", utcCalendar).toString()); assertEquals("03:15:00", rs.getTime("x").toString()); rs = stat.executeQuery("select * from d order by x"); rs.next(); assertEquals("2010-03-14", rs.getString(1)); assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate(1).toString()); assertEquals("2010-03-14", rs.getString("x")); assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate("x").toString()); rs.next(); assertEquals("2010-03-14", rs.getString(1)); assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate(1).toString()); assertEquals("2010-03-14", rs.getString("x")); assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate("x").toString()); } finally { TimeZone.setDefault(old); DateTimeUtils.resetCalendar(); } stat.execute("drop table ts"); stat.execute("drop table t"); stat.execute("drop table d"); }
From source file:ca.uhn.hl7v2.model.tests.DataTypeUtilTest.java
@Test public void testGetLocalGMTOffset() { TimeZone tz = TimeZone.getDefault(); int offset = tz.getRawOffset(); int hours = offset / (60 * 60 * 1000); int minutes = (offset - (hours * (60 * 60 * 1000))) / (60 * 1000); int gmtOffset = hours * 100 + minutes; assertEquals("GMT offset", gmtOffset, DataTypeUtil.getLocalGMTOffset()); }
From source file:com.attribyte.essem.ConsoleServlet.java
public ConsoleServlet(final ESEndpoint esEndpoint, final ESUserStore userStore, final ServletContextHandler rootContext, final IndexAuthorization indexAuthorization, final String templateDirectory, final String dashboardTemplateDirectory, String assetDirectory, final Collection<String> allowedAssetPaths, final Collection<String> allowedIndexes, final List<DisplayTZ> zones, final AsyncClient client, final RequestOptions requestOptions, final Logger logger, final boolean debug) { this.esEndpoint = esEndpoint; this.userStore = userStore; this.indexAuthorization = indexAuthorization; this.templateDirectory = templateDirectory; this.dashboardTemplateDirectory = dashboardTemplateDirectory; this.allowedIndexes = ImmutableList.copyOf(allowedIndexes); this.zones = ImmutableList.copyOf(zones); ImmutableMap.Builder<String, DisplayTZ> zoneMapBuilder = ImmutableMap.builder(); for (DisplayTZ tz : zones) { zoneMapBuilder.put(tz.id, tz);//w w w .j a v a2s. co m } this.zoneMap = zoneMapBuilder.build(); DisplayTZ _defaultDisplayTz = this.zoneMap.get(TimeZone.getDefault().getID()); if (_defaultDisplayTz == null && zones.size() > 0) { _defaultDisplayTz = zones.get(0); } else { _defaultDisplayTz = new DisplayTZ(TimeZone.getDefault().getID(), TimeZone.getDefault().getDisplayName()); } this.defaultDisplayTZ = _defaultDisplayTz; this.client = client; this.requestOptions = requestOptions; this.logger = logger; this.debug = debug; this.templateGroup = debug ? null : loadTemplates(); this.dashboardTemplateGroup = debug ? null : loadDashboardTemplates(); if (!assetDirectory.endsWith("/")) { assetDirectory = assetDirectory + "/"; } rootContext.addAliasCheck(new ContextHandler.ApproveAliases()); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", assetDirectory); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.acceptRanges", "false"); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.welcomeServlets", "true"); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.redirectWelcome", "false"); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.aliases", "true"); rootContext.setInitParameter("org.eclipse.jetty.servlet.Default.gzip", "true"); DefaultServlet defaultServlet = new DefaultServlet(); for (String path : allowedAssetPaths) { logger.info("Enabling asset path: " + path); rootContext.addServlet(new ServletHolder(defaultServlet), path); } this.applicationCache = new ApplicationCache(client, requestOptions, esEndpoint, logger); for (String index : allowedIndexes) { try { List<Application> apps = this.applicationCache.getApplications(index); if (apps != null && apps.size() > 0) { logger.info("Found " + apps.size() + " apps for '" + index + "'"); for (Application app : apps) { long start = System.currentTimeMillis(); logger.info("Priming '" + app.name + "'"); int totalMetrics = app.getMetricsCount(); int activeMetrics = this.applicationCache.removeBoringMetrics(app).getMetricsCount(); logger.info("Found " + activeMetrics + " active metrics of " + totalMetrics); logger.info("Primed in " + (System.currentTimeMillis() - start) + " ms"); } } } catch (IOException ioe) { logger.error("Problem getting applications", ioe); } } this.defaultDashboard = new Dashboard.Builder().setDisplayGrid(true).setAutoUpdateSeconds(0) .setWithTitles(true).setWidth(300).setHeight(220).setLargeBlockGridColumns(4) .setSmallBlockGridColumns(2).setTz(defaultDisplayTZ).build(); }
From source file:microsoft.exchange.webservices.data.ExchangeServiceBase.java
/** * Initializes a new instance.//from ww w .jav a2 s . com * * @param requestedServerVersion The requested server version. */ protected ExchangeServiceBase() { //real init -- ONLY WAY TO BUILD AN OBJECT => each constructor must call this() to build properly the httpConnectionManager this.timeZone = TimeZone.getDefault(); this.setUseDefaultCredentials(true); try { EwsSSLProtocolSocketFactory factory = EwsSSLProtocolSocketFactory.build(null); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new PlainConnectionSocketFactory()).register("https", factory).build(); this.httpConnectionManager = new PoolingHttpClientConnectionManager(registry); } catch (Exception err) { err.printStackTrace(); } }
From source file:org.openmeetings.utils.math.TimezoneUtil.java
/** * Return the timezone based Id from omTimeZone table * /* w w w .ja v a2 s .co m*/ * @param jName * @return */ public TimeZone getTimezoneByOmTimeZoneId(Long omtimezoneId) { OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZoneById(omtimezoneId); 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.indoqa.lang.util.TimeUtils.java
public static Date getEndOfDay(Date date) { return getEndOfDay(date, TimeZone.getDefault()); }
From source file:com.panet.imeta.trans.steps.excelinput.ExcelInput.java
/** * Build an empty row based on the meta-data... * // w w w.ja va2 s . co m * @return */ private Object[] fillRow(int startcolumn, ExcelInputRow excelInputRow) throws KettleException { Object[] r = new Object[data.outputRowMeta.size()]; // Keep track whether or not we handled an error for this line yet. boolean errorHandled = false; // Set values in the row... Cell cell = null; for (int i = startcolumn; i < excelInputRow.cells.length && i - startcolumn < meta.getField().length; i++) { cell = excelInputRow.cells[i]; int rowcolumn = i - startcolumn; ValueMetaInterface targetMeta = data.outputRowMeta.getValueMeta(rowcolumn); ValueMetaInterface sourceMeta = null; try { checkType(cell, targetMeta); } catch (KettleException ex) { if (!meta.isErrorIgnored()) { ex = new KettleCellValueException(ex, this.data.sheetnr, this.data.rownr, i, ""); throw ex; } if (log.isBasic()) logBasic(Messages.getString("ExcelInput.Log.WarningProcessingExcelFile", "" + targetMeta, "" + data.filename, ex.getMessage())); if (!errorHandled) { data.errorHandler.handleLineError(excelInputRow.rownr, excelInputRow.sheetName); errorHandled = true; } if (meta.isErrorLineSkipped()) { return null; } } CellType cellType = cell.getType(); if (CellType.BOOLEAN.equals(cellType) || CellType.BOOLEAN_FORMULA.equals(cellType)) { r[rowcolumn] = Boolean.valueOf(((BooleanCell) cell).getValue()); sourceMeta = data.valueMetaBoolean; } else { if (CellType.DATE.equals(cellType) || CellType.DATE_FORMULA.equals(cellType)) { Date date = ((DateCell) cell).getDate(); long time = date.getTime(); int offset = TimeZone.getDefault().getOffset(time); r[rowcolumn] = new Date(time - offset); sourceMeta = data.valueMetaDate; } else { if (CellType.LABEL.equals(cellType) || CellType.STRING_FORMULA.equals(cellType)) { String string = ((LabelCell) cell).getString(); switch (meta.getField()[rowcolumn].getTrimType()) { case ExcelInputMeta.TYPE_TRIM_LEFT: string = Const.ltrim(string); break; case ExcelInputMeta.TYPE_TRIM_RIGHT: string = Const.rtrim(string); break; case ExcelInputMeta.TYPE_TRIM_BOTH: string = Const.trim(string); break; default: break; } r[rowcolumn] = string; sourceMeta = data.valueMetaString; } else { if (CellType.NUMBER.equals(cellType) || CellType.NUMBER_FORMULA.equals(cellType)) { r[rowcolumn] = new Double(((NumberCell) cell).getValue()); sourceMeta = data.valueMetaNumber; } else { if (log.isDetailed()) logDetailed(Messages.getString("ExcelInput.Log.UnknownType", cell.getType().toString(), cell.getContents())); r[rowcolumn] = null; } } } } ExcelInputField field = meta.getField()[rowcolumn]; // Change to the appropriate type if needed... // try { // Null stays null folks. // if (sourceMeta != null && sourceMeta.getType() != targetMeta.getType() && r[rowcolumn] != null) { ValueMetaInterface sourceMetaCopy = sourceMeta.clone(); sourceMetaCopy.setConversionMask(field.getFormat()); sourceMetaCopy.setGroupingSymbol(field.getGroupSymbol()); sourceMetaCopy.setDecimalSymbol(field.getDecimalSymbol()); sourceMetaCopy.setCurrencySymbol(field.getCurrencySymbol()); switch (targetMeta.getType()) { // Use case: we find a numeric value: convert it using the supplied format to the desired data type... // case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: switch (field.getType()) { case ValueMetaInterface.TYPE_DATE: // number to string conversion (20070522.00 --> "20070522") // ValueMetaInterface valueMetaNumber = new ValueMeta("num", ValueMetaInterface.TYPE_NUMBER); valueMetaNumber.setConversionMask("#"); Object string = sourceMetaCopy.convertData(valueMetaNumber, r[rowcolumn]); // String to date with mask... // r[rowcolumn] = targetMeta.convertData(sourceMetaCopy, string); break; default: r[rowcolumn] = targetMeta.convertData(sourceMetaCopy, r[rowcolumn]); break; } break; // Use case: we find a date: convert it using the supplied format to String... // default: r[rowcolumn] = targetMeta.convertData(sourceMetaCopy, r[rowcolumn]); } } } catch (KettleException ex) { if (!meta.isErrorIgnored()) { ex = new KettleCellValueException(ex, this.data.sheetnr, cell.getRow(), i, field.getName()); throw ex; } if (log.isBasic()) logBasic(Messages.getString("ExcelInput.Log.WarningProcessingExcelFile", "" + targetMeta, "" + data.filename, ex.toString())); if (!errorHandled) // check if we didn't log an error already for this one. { data.errorHandler.handleLineError(excelInputRow.rownr, excelInputRow.sheetName); errorHandled = true; } if (meta.isErrorLineSkipped()) { return null; } else { r[rowcolumn] = null; } } } int rowIndex = meta.getField().length; // Do we need to include the filename? if (!Const.isEmpty(meta.getFileField())) { r[rowIndex] = data.filename; rowIndex++; } // Do we need to include the sheetname? if (!Const.isEmpty(meta.getSheetField())) { r[rowIndex] = excelInputRow.sheetName; rowIndex++; } // Do we need to include the sheet rownumber? if (!Const.isEmpty(meta.getSheetRowNumberField())) { r[rowIndex] = new Long(data.rownr); rowIndex++; } // Do we need to include the rownumber? if (!Const.isEmpty(meta.getRowNumberField())) { r[rowIndex] = new Long(getLinesWritten() + 1); rowIndex++; } return r; }