@Override public void onReceive(Context context, Intent intent) { String tzId = intent.getStringExtra("time-zone"); try { DateTimeZone newDefault = DateTimeZone.forTimeZone(TimeZone.getDefault()); DateTimeZone.setDefault(newDefault); Log.d("joda-time-android", "TIMEZONE_CHANGED received, changed default timezone to \"" + tzId + "\""); } catch (IllegalArgumentException e) { Log.e("joda-time-android", "Could not recognize timezone id \"" + tzId + "\"", e); } }
System.setProperty("user.timezone", timezone); TimeZone.setDefault(TimeZone.getTimeZone(timezone)); DateTimeZone.setDefault(DateTimeZone.forID(timezone)); logger.info("Setting timezone to " + timezone);
@After public void tearDown() throws Exception { Locale.setDefault(locale); DateTimeZone.setDefault(zone); }
@BeforeClass public static void tz() { DateTimeZone.setDefault(DateTimeZone.forID("America/Los_Angeles")); }
@Override public void init(SourceState state) { DateTimeZone.setDefault(DateTimeZone .forID(state.getProp(ConfigurationKeys.SOURCE_TIMEZONE, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE))); initDatePartition(state); this.sourcePartitionPrefix = state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_PREFIX, StringUtils.EMPTY); this.sourcePartitionSuffix = state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_SUFFIX, StringUtils.EMPTY); this.sourceDir = new Path(state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY)); this.leadTimeDuration = PartitionAwareFileRetrieverUtils.getLeadTimeDurationFromConfig(state); this.helper = new HadoopFsHelper(state); this.schemaInSourceDir = state.getPropAsBoolean(ConfigurationKeys.SCHEMA_IN_SOURCE_DIR, ConfigurationKeys.DEFAULT_SCHEMA_IN_SOURCE_DIR); this.schemaFile = this.schemaInSourceDir ? state.getProp(ConfigurationKeys.SCHEMA_FILENAME, ConfigurationKeys.DEFAULT_SCHEMA_FILENAME) : ""; }
@After public void tearDown() throws Exception { // Restore to normal "now" time DateTimeUtils.setCurrentMillisSystem(); DateTimeZone.setDefault(mOldDefaultJodaTz); TimeZone.setDefault(mOldDefaultSystemTz); ContentResolver cr = InstrumentationRegistry.getContext().getContentResolver(); Settings.System.putString(cr, Settings.System.TIME_12_24, mOldTime1224Setting); }
@Test public void testDefault() { assertNotNull(DateTimeZone.getDefault()); DateTimeZone.setDefault(PARIS); assertSame(PARIS, DateTimeZone.getDefault()); try { DateTimeZone.setDefault(null); fail(); } catch (IllegalArgumentException ex) {} }
@Before public void setUp() throws Exception { // Init zone info Context context = InstrumentationRegistry.getContext(); JodaTimeAndroid.init(context); // Force the system into 24-hour time for tests ContentResolver cr = context.getContentResolver(); mOldTime1224Setting = Settings.System.getString(cr, Settings.System.TIME_12_24); Settings.System.putString(cr, Settings.System.TIME_12_24, "24"); // Force all tests to be in the US locale; that way we can test output in consistent manner Application app = (Application) InstrumentationRegistry.getContext().getApplicationContext(); Resources res = app.getBaseContext().getResources(); Configuration config = res.getConfiguration(); Locale.setDefault(Locale.US); config.locale = Locale.US; res.updateConfiguration(config, res.getDisplayMetrics()); // Force the default timezone mDefaultJodaTz = DateTimeZone.forID("America/New_York"); mOldDefaultJodaTz = DateTimeZone.getDefault(); DateTimeZone.setDefault(mDefaultJodaTz); // ...And for the system as well mDefaultSystemTz = TimeZone.getTimeZone("America/Chicago"); mOldDefaultSystemTz = TimeZone.getDefault(); TimeZone.setDefault(mDefaultSystemTz); // Force current "now" time, so all tests can be consistent mNow = new DateTime(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE, MILLIS_OF_SECOND, mDefaultJodaTz); DateTimeUtils.setCurrentMillisFixed(mNow.getMillis()); }
@Test public void testDefaultSecurity() { if (OLD_JDK) { return; } try { Policy.setPolicy(RESTRICT); System.setSecurityManager(new SecurityManager()); DateTimeZone.setDefault(PARIS); fail(); } catch (SecurityException ex) { // ok } finally { System.setSecurityManager(null); Policy.setPolicy(ALLOW); } }
@Test public void testGetMillisKeepLocal() { long millisLondon = TEST_TIME_SUMMER; long millisParis = TEST_TIME_SUMMER - 1L * DateTimeConstants.MILLIS_PER_HOUR; assertEquals(millisLondon, LONDON.getMillisKeepLocal(LONDON, millisLondon)); assertEquals(millisParis, LONDON.getMillisKeepLocal(LONDON, millisParis)); assertEquals(millisLondon, PARIS.getMillisKeepLocal(PARIS, millisLondon)); assertEquals(millisParis, PARIS.getMillisKeepLocal(PARIS, millisParis)); assertEquals(millisParis, LONDON.getMillisKeepLocal(PARIS, millisLondon)); assertEquals(millisLondon, PARIS.getMillisKeepLocal(LONDON, millisParis)); DateTimeZone zone = DateTimeZone.getDefault(); try { DateTimeZone.setDefault(LONDON); assertEquals(millisLondon, PARIS.getMillisKeepLocal(null, millisParis)); } finally { DateTimeZone.setDefault(zone); } }
private void init() { for (String str : props.getProperty(CAMUS_SWEEPER_PRIORITY_LIST, "").split(",")) { String[] tokens = str.split("="); String topic = tokens[0]; int priority = tokens.length > 1 ? Integer.parseInt(tokens[1]) : 1; priorityTopics.put(topic, priority); } this.errorMessages = Collections.synchronizedList(new ArrayList<SweeperError>()); DateTimeZone.setDefault(DateTimeZone.forID(props.getProperty("default.timezone"))); this.runningJobs = Collections.synchronizedList(new ArrayList<Job>()); sourceSubdir = props.getProperty("camus.sweeper.source.subdir"); destSubdir = props.getProperty("camus.sweeper.dest.subdir"); try { planner = ((CamusSweeperPlanner) Class.forName(props.getProperty("camus.sweeper.planner.class")).newInstance()) .setPropertiesLogger(props, log); } catch (Exception e) { throw new RuntimeException(e); } }
private void restoreDefaultTimeZone() { if (currentDTZ != null) { DateTimeZone.setDefault(currentDTZ); currentDTZ = null; } } }
public static void setDefaultTimeZone(Configuration conf) { String dtzStr = conf.get(PigConfiguration.PIG_DATETIME_DEFAULT_TIMEZONE); if (dtzStr != null && dtzStr.length() > 0) { // don't use offsets because it breaks across DST/Standard Time DateTimeZone.setDefault(DateTimeZone.forID(dtzStr)); } }
private void setDefaultTimeZone() { String dtzStr = pc.getProperties().getProperty("pig.datetime.default.tz"); if (dtzStr != null && dtzStr.length() > 0) { currentDTZ = DateTimeZone.getDefault(); DateTimeZone.setDefault(DateTimeZone.forID(dtzStr)); } }
@Before public void before() { DateTimeZone.setDefault(DateTimeZone.forID("America/Los_Angeles")); }
private void setJvmAndJodaDefaultTimezone(TimeZoneInfo tzInfo) { jiraProperties.setProperty("user.timezone", tzInfo.getTimeZoneId()); TimeZone.setDefault(tzInfo.toTimeZone()); DateTimeZone.setDefault(DateTimeZone.forTimeZone(tzInfo.toTimeZone())); } }
@Before public void reset() { // Set current time to a fixed value, so that revision in the generated discovery doc will be a // fixed value (19700101). DateTimeZone.setDefault(DateTimeZone.UTC); DateTimeUtils.setCurrentMillisFixed(1L); suppressAllWarnings = true; }
@Test public void stringToTimestampChangeTZ() { DateTimeZone defaultTZ = DateTimeZone.getDefault(); try { DateTimeZone.setDefault(DateTimeZone.forID("America/Los_Angeles")); assertEquals(1236478747000L, formatTimeStamp("2009-03-08 02:19:07", DateFunctionsUtils.getSQLFormatterForFormatString("YYYY-MM-DD HH:MI:SS"))); } finally { DateTimeZone.setDefault(defaultTZ); } }
public void tearDown() throws JSONException { InstanceSettings.delete(getContext(), widgetId - 1); InstanceSettings.delete(getContext(), widgetId); ApplicationPreferences.setWidgetId(getContext(), 0); InstanceSettings.fromJson(getBaseContext(getContext()), storedSettings); DateUtil.setNow(null); DateTimeZone.setDefault(storedZone); EventAppWidgetProvider.updateAllWidgets(getBaseContext(getContext())); }
@Test public void stringToTimestampChangeTZOffset() { DateTimeZone defaultTZ = DateTimeZone.getDefault(); try { assertEquals(calculateTime("2008-09-15 10:53:00"), formatTimeStamp("2008-09-15T15:53:00+0500", DateFunctionsUtils.getSQLFormatterForFormatString("YYYY-MM-DD\"T\"HH24:MI:SSTZO"))); assertEquals(calculateTime("2011-01-01 04:00:00"), formatTimeStamp("2010-12-31T23:00:00-0500", DateFunctionsUtils.getSQLFormatterForFormatString("YYYY-MM-DD\"T\"HH24:MI:SSTZO"))); assertEquals(calculateTime("2010-12-31 23:00:00"), formatTimeStamp("2010-12-31T23:00:00", DateFunctionsUtils.getSQLFormatterForFormatString("YYYY-MM-DD\"T\"HH24:MI:SS"))); } finally { DateTimeZone.setDefault(defaultTZ); } }