List of usage examples for java.util TimeZone setDefault
public static void setDefault(TimeZone zone)
From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.BlockScheduleItemsFragment.java
protected void setupDay(ViewGroup rootView) { final int position = getArguments().getInt("id"); final long startMillis = getArguments().getLong("startMillis"); mDay = new Day(); // Setup data mDay.index = position;/*w w w . j av a2 s . c om*/ mDay.timeStart = startMillis; mDay.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS; mDay.loaderUri = CfpContract.Blocks.buildBlocksBetweenDirUri(mDay.timeStart, mDay.timeEnd); // Setup views mDay.rootView = rootView; mDay.scrollView = (ObservableScrollView) mDay.rootView.findViewById(R.id.schedule_items_scroll); mDay.scheduleItemsView = (ScheduleItemsLayout) mDay.rootView.findViewById(R.id.schedule_items); mDay.nowView = mDay.rootView.findViewById(R.id.schedule_items_now); // mDay.blocksView.setDrawingCacheEnabled(true); // mDay.blocksView.setAlwaysDrawnWithCacheEnabled(true); TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE); mDay.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS); }
From source file:hudson.plugins.timestamper.format.TimestampFormatterImplTest.java
/** *///from ww w.j ava2 s . co m @Test public void testMarkupElapsedTimeWithDifferentTimeZoneAfterSerialization() { serialize = true; TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); assertThat(markup("line").toString(true), is(prefixInDifferentTimezone + "line")); }
From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java
@BeforeClass public static void setUpClass() { // Initializing a new local server on this port timeServer = new SimpleNTPServer(TEST_PORT); // Starting the local server timeServer.startServer();//from w ww. j av a2 s . c o m /* * Store the initial system time zone and locale value, so that we can * restore them at the test end. */ systemTimeZone = TimeZone.getDefault(); locale = Locale.getDefault(); /* * Set new default time zone and locale, which will be used during the * tests execution. */ TimeZone.setDefault(TimeZone.getTimeZone(DEFAULT_TIME_ZONE_ID)); Locale.setDefault(Locale.US); }
From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java
@Test public void testWrapperMethodsMelbourne() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("Australia/Melbourne")); CelestialObject sun = CelestialObject.SUN; Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.setTimeInMillis(0);/*from w ww. j a v a 2s . co 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(-37.70461920, 145.1030275, 0.0); TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL); logger.debug("Melbourne"); 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(), 1249677914422l, 1000); Assert.assertEquals(details.getSetTime().getTime(), 1249718740422l, 1000); }
From source file:com.qian.weeno.util.UIUtils.java
/** * Format and return the given {@link Blocks} values using * {@link #CONFERENCE_TIME_ZONE}.//from www . ja v a2s . c o m */ public static String formatTimeString(long time, Context context) { TimeZone.setDefault(CONFERENCE_TIME_ZONE); // NOTE: There is an efficient version of formatDateRange in Eclair and // beyond that allows you to recycle a StringBuilder. return DateUtils.formatDateTime(context, time, TIME_FLAGS); }
From source file:com.google.android.apps.iosched.util.UIUtils.java
public static boolean isSameDay(long time1, long time2) { TimeZone.setDefault(CONFERENCE_TIME_ZONE); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTimeInMillis(time1);//ww w . ja v a2 s .co m cal2.setTimeInMillis(time2); return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:org.eclipse.smarthome.binding.ntp.test.NtpOSGiTest.java
@AfterClass public static void tearDownClass() { // Set the default time zone and locale to their initial value. TimeZone.setDefault(systemTimeZone); Locale.setDefault(locale);//from ww w . ja v a2 s . co m }
From source file:org.bigloupe.web.scheduler.InitializeScheduler.java
public InitializeScheduler(List<File> jobDirs, File logDir, File tempDir, MailerService mailerService, BigLoupeConfiguration configuration, boolean enableDevMode) throws IOException { this.jobDirs = Utils.nonNull(jobDirs); this.logsDir = Utils.nonNull(logDir); this.tempDir = Utils.nonNull(tempDir); this._mailerService = mailerService; if (!this.logsDir.exists()) this.logsDir.mkdirs(); if (!this.tempDir.exists()) this.tempDir.mkdirs(); for (File jobDir : jobDirs) { if (!jobDir.exists()) { logger.warn("Job directory " + jobDir + " does not exist. Creating."); jobDir.mkdirs();//from w w w . j a v a2s . com } } if (jobDirs.size() < 1) throw new IllegalArgumentException("No job directory given."); Props defaultProps = PropsUtils.loadPropsInDirs(jobDirs, ".properties", ".schema"); _baseClassLoader = getBaseClassloader(); String defaultTimezoneID = defaultProps.getString(DEFAULT_TIMEZONE_ID, null); if (defaultTimezoneID != null) { DateTimeZone.setDefault(DateTimeZone.forID(defaultTimezoneID)); TimeZone.setDefault(TimeZone.getTimeZone(defaultTimezoneID)); } NamedPermitManager permitManager = getNamedPermitManager(defaultProps); JobWrappingFactory factory = new JobWrappingFactory(permitManager, new ReadWriteLockManager(), logsDir.getAbsolutePath(), "java", new ImmutableMap.Builder<String, Class<? extends Job>>().put("java", JavaJob.class) .put("command", ProcessJob.class).put("javaprocess", JavaProcessJob.class) .put("map-reduce", MapReduceJob.class).put("pig", PigProcessJob.class) .put("propertyPusher", NoopJob.class).put("python", PythonJob.class) .put("ruby", RubyJob.class).put("script", ScriptJob.class) .put("sqoop", SqoopProcessJob.class).put("indexfile", IndexFileProcessJob.class) .put("noop", NoopJob.class).build()); _hdfsUrl = defaultProps.getString("hdfs.instance.url", null); _jobManager = new JobManager(factory, logsDir.getAbsolutePath(), defaultProps, jobDirs, _baseClassLoader, configuration); String failureEmail = defaultProps.getString("job.failure.email", null); String successEmail = defaultProps.getString("job.success.email", null); int schedulerThreads = defaultProps.getInt("scheduler.threads", 50); _instanceName = defaultProps.getString(INSTANCE_NAME, ""); final File initialJobDir = jobDirs.get(0); File schedule = getScheduleFile(defaultProps, initialJobDir); File backup = getBackupFile(defaultProps, initialJobDir); File executionsStorageDir = new File(defaultProps.getString("azkaban.executions.storage.dir", initialJobDir.getAbsolutePath() + "/executions")); if (!executionsStorageDir.exists()) executionsStorageDir.mkdirs(); long lastExecutionId = getLastExecutionId(executionsStorageDir); logger.info(String.format("Using path[%s] for storing executions.", executionsStorageDir)); logger.info(String.format("Last known execution id was [%s]", lastExecutionId)); final ExecutableFlowSerializer flowSerializer = new DefaultExecutableFlowSerializer(); final ExecutableFlowDeserializer flowDeserializer = new DefaultExecutableFlowDeserializer(_jobManager, factory); FlowExecutionSerializer flowExecutionSerializer = new FlowExecutionSerializer(flowSerializer); FlowExecutionDeserializer flowExecutionDeserializer = new FlowExecutionDeserializer(flowDeserializer); _allFlows = new CachingFlowManager( new RefreshableFlowManager(_jobManager, flowExecutionSerializer, flowExecutionDeserializer, executionsStorageDir, lastExecutionId), defaultProps.getInt("azkaban.flow.cache.size", 1000)); _jobManager.setFlowManager(_allFlows); _jobExecutorManager = new JobExecutorManager(_allFlows, _jobManager, failureEmail, successEmail, schedulerThreads); this._schedulerManager = new ScheduleManager(_jobExecutorManager, new LocalFileScheduleLoader(schedule, backup)); /* set predefined log url prefix */ String server_url = defaultProps.getString("server.url", null); if (server_url != null) { if (server_url.endsWith("/")) _jobExecutorManager.setRuntimeProperty(BigLoupeConfiguration.DEFAULT_LOG_URL_PREFIX, server_url + "logs?file="); else _jobExecutorManager.setRuntimeProperty(BigLoupeConfiguration.DEFAULT_LOG_URL_PREFIX, server_url + "/logs?file="); } }
From source file:com.otterca.common.crypto.acceptance.X509CertificateBuilderAcceptanceTest.java
/** * Default constructor.//w ww. j a va 2s . co m * * @throws Exception */ protected X509CertificateBuilderAcceptanceTest() throws GeneralSecurityException, InvalidNameException, URISyntaxException, UnknownHostException, IOException { certUtil = new X509CertificateUtilImpl(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // create key pairs. this is for testing so we use 512-bit keys for // speed. KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); keyPairGen.initialize(512); keyPair = keyPairGen.generateKeyPair(); issuerKeyPair = keyPairGen.generateKeyPair(); grandfatherKeyPair = keyPairGen.generateKeyPair(); notBefore = Calendar.getInstance(); notBefore.set(Calendar.MINUTE, 0); notBefore.set(Calendar.SECOND, 0); notBefore.set(Calendar.MILLISECOND, 0); notAfter = Calendar.getInstance(); notAfter.setTime(notBefore.getTime()); notAfter.add(Calendar.YEAR, 1); expectedGeneralNameUri1 = new com.otterca.common.crypto.GeneralName.URI("http://example.com"); expectedGeneralNameUri2 = new com.otterca.common.crypto.GeneralName.URI("ldap://example.net"); expectedGeneralNameDir = new com.otterca.common.crypto.GeneralName.Directory("C=US,ST=AK,C=Anchorage"); expectedGeneralNameEmail = new com.otterca.common.crypto.GeneralName.Email("bob@example.com"); expectedGeneralNameDns = new com.otterca.common.crypto.GeneralName.DNS("example.com"); expectedGeneralNameIpAddress = new com.otterca.common.crypto.GeneralName.IpAddress("127.0.0.1"); }
From source file:org.transitime.applications.Core.java
/** * Construct the Core object and read in the config data. This is private * so that the createCore() factory method must be used. * /*from w w w. j av a 2 s .c o m*/ * @param agencyId */ public Core(String agencyId) { // Determine configuration rev to use. If one specified on command // line, use it. If not, then use revision stored in db. int configRev; if (configRevStr != null) { // Use config rev from command line configRev = Integer.parseInt(configRevStr); } else { // Read in config rev from ActiveRevisions table in db ActiveRevisions activeRevisions = ActiveRevisions.get(agencyId); // If config rev not set properly then simply log error. // Originally would also exit() but found that want system to // work even without GTFS configuration so that can test AVL feed. if (!activeRevisions.isValid()) { logger.error("ActiveRevisions in database is not valid. The " + "configuration revs must be set to proper values. {}", activeRevisions); } configRev = activeRevisions.getConfigRev(); } // Set the timezone so that when dates are read from db or are logged // the time will be correct. Therefore this needs to be done right at // the start of the application, before db is read. TimeZone timeZone = Agency.getTimeZoneFromDb(agencyId); TimeZone.setDefault(timeZone); // Clears out the session factory so that a new one will be created for // future db access. This way new db connections are made. This is // useful for dealing with timezones and postgres. For that situation // want to be able to read in timezone from db so can set default // timezone. Problem with postgres is that once a factory is used to // generate sessions the database will continue to use the default // timezone that was configured at that time. This means that future // calls to the db will use the wrong timezone! Through this function // one can read in timezone from database, set the default timezone, // clear the factory so that future db connections will use the newly // configured timezone, and then successfully process dates. HibernateUtils.clearSessionFactory(); // Read in all GTFS based config data from the database configData = new DbConfig(agencyId); configData.read(configRev); // Create the DataDBLogger so that generated data can be stored // to database via a robust queue. But don't actually log data // if in playback mode since then would be writing data again // that was first written when predictor was run in real time. // Note: DataDbLogger needs to be started after the timezone is set. // Otherwise when running for a different timezone than what the // computer is setup for then can log data using the wrong time! // This is strange since setting TimeZone.setDefault() is supposed // to work across all threads it appears that sometimes it wouldn't // work if Db logger started first. dataDbLogger = DataDbLogger.getDataDbLogger(agencyId, CoreConfig.storeDataInDatabase(), CoreConfig.pauseIfDbQueueFilling()); // Start mandatory modules timeoutHandlerModule = new TimeoutHandlerModule(AgencyConfig.getAgencyId()); timeoutHandlerModule.start(); service = new ServiceUtils(configData); time = new Time(configData); }