List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:fr.gael.dhus.DHuS.java
/** Starts the DHuS (starts Tomcat, creates the Spring application context. */ public static void start() { // Transfer System.err in logger System.setErr(new PrintStream(new LoggingOutputStream(LOGGER), true)); String version = DHuS.class.getPackage().getImplementationVersion(); // Force ehcache not to call home System.setProperty("net.sf.ehcache.skipUpdateCheck", "true"); System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true"); System.setProperty("user.timezone", "UTC"); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); System.setProperty("fr.gael.dhus.version", version == null ? "dev" : version); if (!SystemService.restore()) { LOGGER.error("Cannot run system restoration."); LOGGER.error("Check the restoration file \"" + SystemService.RESTORATION_PROPERTIES + "\" from the current directory."); System.exit(1);//from w ww . j av a 2 s . c o m } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { if ((server != null) && server.isRunning()) { try { server.stop(); } catch (TomcatException e) { e.printStackTrace(); } } } })); // Always add JMSAppender //Logger rootLogger = LogManager.getRootLogger (); //org.apache.logging.log4j.core.Logger coreLogger = //(org.apache.logging.log4j.core.Logger)rootLogger; //JMSAppender jmsAppender = JMSAppender.createAppender (); //coreLogger.addAppender (jmsAppender); try { // Activates the resolver for Drb DrbFactoryResolver.setMetadataResolver(new DrbCortexMetadataResolver(DrbCortexModel.getDefaultModel())); } catch (IOException e) { LOGGER.error("Resolver cannot be handled."); //logger.error (new Message(MessageType.SYSTEM, //"Resolver cannot be handled.")); } LOGGER.info("Launching Data Hub Service..."); //logger.info (new Message(MessageType.SYSTEM, //"Loading Data Hub Service...")); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:fr/gael/dhus/spring/dhus-core-context.xml"); context.registerShutdownHook(); // Registers ContextClosedEvent listeners to properly save states before // the Spring context is destroyed. ApplicationListener sync_sv = context.getBean(ISynchronizerService.class); context.addApplicationListener(sync_sv); // Initialize Database Incoming folder IncomingManager incoming_manager = (IncomingManager) context.getBean("incomingManager"); incoming_manager.initIncoming(); // Initialize DHuS loggers //jmsAppender.cleanWaitingLogs (); //logger.info (new Message(MessageType.SYSTEM, "DHuS Started")); try { //ftp = xml.getBean (FtpServer.class); //ftp.start (); server = ApplicationContextProvider.getBean(TomcatServer.class); server.init(); LOGGER.info("Starting server " + server.getClass() + "..."); //logger.info (new Message(MessageType.SYSTEM, "Starting server...")); server.start(); //logger.info (new Message(MessageType.SYSTEM, "Server started.")); LOGGER.info("Server started."); // Initialises SolrDAO SolrDao solr_dao = (SolrDao) context.getBean("solrDao"); solr_dao.initServerStarted(); Map<String, WebApplication> webapps = context.getBeansOfType(WebApplication.class); for (String beanName : webapps.keySet()) { server.install(webapps.get(beanName)); } fr.gael.dhus.server.http.web.WebApplication.installAll(server); WebServlet.installAll(server); WebPostProcess.launchAll(); LOGGER.info("Server is ready..."); started = true; //InitializableComponent.initializeAll (); //logger.info (new Message(MessageType.SYSTEM, "Server is ready...")); server.await(); } catch (Exception e) { LOGGER.error("Cannot start system.", e); //logger.error (new Message(MessageType.SYSTEM, "Cannot start DHuS."), e); //ftp.stop (); System.exit(1); } }
From source file:microsoft.exchange.webservices.data.property.complex.OlsonTimeZoneTest.java
@Test public void testOlsonTimeZoneConversion() { final Map<String, String> olsonTimeZoneToMsMap = TimeZoneUtils.createOlsonTimeZoneToMsMap(); final String[] timeZoneIds = TimeZone.getAvailableIDs(); for (final String timeZoneId : timeZoneIds) { final boolean america = timeZoneId.startsWith("America"); final boolean europe = timeZoneId.startsWith("Europe"); final boolean africa = timeZoneId.startsWith("Africa"); if (america || europe || africa) { // There are a few timezones that are out of date or don't have direct microsoft mappings // according to the Unicode source we use so we will only test Americas, Europe and Africa. final TimeZone timeZone = TimeZone.getTimeZone(timeZoneId); final OlsonTimeZoneDefinition olsonTimeZone = new OlsonTimeZoneDefinition(timeZone); final String olsonTimeZoneId = olsonTimeZone.getId(); Assert.assertFalse(StringUtils.isBlank(olsonTimeZoneId)); Assert.assertEquals(olsonTimeZoneToMsMap.get(timeZoneId), olsonTimeZoneId); }//from w w w . ja va2 s .c o m } }
From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java
@Test public void testClearAllTasks() throws Exception { TimeZone tz = TimeZone.getTimeZone("GMT"); MockScheduledTaskExecutor executor = new MockScheduledTaskExecutor(); // make sure executor has no delays already set assertFalse(executor.hasDelays());//from w w w . j a va 2s . c o m String ical = "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "BEGIN:VEVENT\n" + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20130714T170000Z\n" + "DTEND:20130714T170000Z\n" + "SUMMARY:My Task\n" + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Action','properties':{'message':'foo'}}]\n" + "END:VEVENT\n" + "END:VCALENDAR"; long startOfDay = DateHelper.getTime(tz, 2013, 7, 14, 0, 0, 0); ICalTaskProvider s = new ICalTaskProvider("pluginId", null, null, tz); s.setScheduleExecutor(executor); s.loadICSStream(new ByteArrayInputStream(ical.getBytes()), startOfDay); // confirm executor has a delay assertTrue(executor.hasDelays()); s.clearAllTasks(); // confirm executor has no delays assertFalse(executor.hasDelays()); }
From source file:no.met.jtimeseries.chart.Utility.java
/** * Calculate the time at the threshold value * // ww w. j ava 2s.co m * @param time1 * The first time string * @param value1 * The first value * @param time2 * The second time String * @param value2 * The second value * @param value3 * The threshold value * @return The time at the threshold */ public static Date timeOfThreshold(Date time1, double value1, Date time2, double value2, double value3) { DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); long date3 = 0; long date1 = time1.getTime(); long date2 = time2.getTime(); double slope = (date2 - date1) / (value2 - value1); double bias = date2 - slope * value2; date3 = new Double(slope * value3 + bias).longValue(); return new Date(date3); }
From source file:monasca.log.api.app.ApplicationModule.java
@Named("objectMapper") @Provides/*from w w w .j ava 2 s. co m*/ public ObjectMapper objectMapper() { return new ObjectMapper() .setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, FAIL_ON_UNKNOWN_PROPERTIES) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, ACCEPT_SINGLE_VALUE_AS_ARRAY) .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, ORDER_MAP_ENTRIES_BY_KEYS) .setTimeZone(TimeZone.getTimeZone(TIME_ZONE_UTC)) .setSerializationInclusion(JsonInclude.Include.NON_NULL); }
From source file:com.mercandalli.android.apps.files.file.filespace.FileSpaceModel.java
public FileSpaceModel() { mDateFormatGmt = new SimpleDateFormat(DATE_FORMAT, Locale.US); mDateFormatGmt.setTimeZone(TimeZone.getTimeZone(UTC)); mDateFormatLocal = new SimpleDateFormat(DATE_FORMAT, Locale.US); mDateFormatGmtMillis = new SimpleDateFormat(DATE_FORMAT_MS, Locale.US); mDateFormatGmtMillis.setTimeZone(TimeZone.getTimeZone(UTC)); mDateFormatLocalMillis = new SimpleDateFormat(DATE_FORMAT_MS, Locale.US); }
From source file:com.seajas.search.contender.scripting.FeedScriptsTestBase.java
public FeedScriptsTestBase() { dates.setTimeZone(TimeZone.getTimeZone("UTC")); }
From source file:com.modelmetrics.cloudconverter.importxls.services.FileServiceImpl.java
/** * Parses an XLS file into a WrapperBean * /* ww w . j a va 2 s . co m*/ * @param file * @return WrapperBean * @throws ParseException */ @SuppressWarnings("unchecked") public List<ExcelWorksheetWrapperBean> parseXLS(File file) throws ParseException { // keeps date fields real. TimeZone.setDefault(TimeZone.getTimeZone("-0")); List<ExcelWorksheetWrapperBean> wrapperBeans = new ArrayList<ExcelWorksheetWrapperBean>(); try { Workbook workbook; workbook = Workbook.getWorkbook(file); Sheet[] sheets = workbook.getSheets(); for (Sheet sheet : sheets) { ExcelWorksheetWrapperBean bean = new ExcelWorksheetWrapperBean(); bean.setSheetName(StringUtils.applyConstraints(sheet.getName())); int totalRows = sheet.getRows(); for (int i = 0; i < totalRows; i++) { Cell[] cells = sheet.getRow(i); List<Object> list = new ArrayList<Object>(); for (int j = 0; j < cells.length; j++) { Cell c = cells[j]; // log.debug("cell format is: (i,j) (" + i + ", " + j + // "): // " + c.getCellFormat().getFormat().getFormatString()); String value = c.getContents(); if (i == 0) { // parse column names bean.getNames().add(StringUtils.applyConstraints(value)); bean.getLabels().add(value); } if (i == 1) { // parse data types CellType type = c.getType(); if (type.equals(CellType.DATE) || type.equals(CellType.DATE_FORMULA)) { if (value.contains(":")) { bean.getTypes().add(Constants.DATETIME); } else { bean.getTypes().add(Constants.DATE); } } else if (type.equals(CellType.BOOLEAN) || type.equals(CellType.BOOLEAN_FORMULA)) { bean.getTypes().add(Constants.CHECKBOX); } else if (type.equals(CellType.LABEL) || type.equals(CellType.STRING_FORMULA)) { if (GenericValidator.isEmail(value)) { bean.getTypes().add(Constants.EMAIL); } else if (StringUtils.isPhoneNumber(value)) { bean.getTypes().add(Constants.PHONE_NUMBER); } else if (StringUtils.isURL(value)) { bean.getTypes().add(Constants.URL); } else { bean.getTypes().add(Constants.TEXT); } } else if (type.equals(CellType.NUMBER) || type.equals(CellType.NUMBER_FORMULA)) { log.debug("Number: " + value + " : format : " + c.getCellFormat().getFormat().getFormatString()); if (value.contains("%")) { bean.getTypes().add(Constants.PERCENTAGE); } else if (value.contains("$")) { bean.getTypes().add(Constants.CURRENCY); } else if (value.contains(",") || value.contains(".")) { bean.getTypes().add(Constants.DOUBLE); } else { bean.getTypes().add(Constants.INT); } } else { // default. bean.getTypes().add(Constants.TEXT); } } if (i >= 1) { // parse data values CellType type = c.getType(); if (type.equals(CellType.BOOLEAN) || type.equals(CellType.BOOLEAN_FORMULA)) { list.add(((BooleanCell) c).getValue()); } else if (type.equals(CellType.DATE) || type.equals(CellType.DATE_FORMULA)) { Date aux = ((DateCell) c).getDate(); list.add(aux); // } } else if (type.equals(CellType.LABEL) || type.equals(CellType.STRING_FORMULA)) { list.add(value); } else if (type.equals(CellType.EMPTY)) { list.add(null); } else if (type.equals(CellType.NUMBER) || type.equals(CellType.NUMBER_FORMULA)) { if (value.contains("%")) { // otherwise "percentages" show up in SFDC // as // 0.78 when it should be 78%. list.add(((NumberCell) c).getValue() * 100); } else { list.add(((NumberCell) c).getValue()); } } if (i == 1) { bean.getExamples().add(value); } } } if (i >= 1) { /* * RSC 2009-06-02 Check to be sure there is data in a list */ boolean notEmpty = false; for (Object o : list) { if (o != null && o.toString().trim().length() != 0) { notEmpty = true; break; } } if (!notEmpty) { throw new RuntimeException( "Found an empty row. Your spreadsheet should not contain an empty row. Check sheet " + sheet.getName() + ", row " + (i + 1) + "."); } bean.getData().add(list); bean.setOverride(Boolean.FALSE); } } wrapperBeans.add(bean); } } catch (BiffException e) { throw new ParseException("Could not read file"); } catch (IOException e) { throw new ParseException("Input/Output error"); } catch (IndexOutOfBoundsException e) { throw new ParseException("Columns and data do not match"); } catch (NullPointerException e) { throw new ParseException("A reference in the file has a null value"); } return wrapperBeans; }
From source file:org.envirocar.aggregation.AggregatedTracksServlet.java
@Override public void init() throws ServletException { super.init(); this.connection = new PostgresConnection(); this.aggregatedTracksTableName = (String) Properties.getProperty("aggregatedTracksTableName"); this.query = "SELECT * FROM " + this.aggregatedTracksTableName + " ORDER BY id DESC LIMIT 100"; this.trackQuery = "SELECT * FROM " + this.aggregatedTracksTableName + " WHERE id = '%s'"; TimeZone tz = TimeZone.getTimeZone("UTC"); df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(tz);/*from ww w. ja v a2 s . c o m*/ om = new ObjectMapper(); }
From source file:com.arm.connector.bridge.core.Utils.java
public static long getUTCTime() { return Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTimeInMillis() - Utils.getUTCOffset(); }