Java Code Examples for org.joda.time.DateTimeZone#setProvider()

The following examples show how to use org.joda.time.DateTimeZone#setProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JodaTimeAndroid.java    From joda-time-android with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes ResourceZoneInfoProvider and registers an instance of
 * {@link TimeZoneChangedReceiver} to receive android.intent.action.TIMEZONE_CHANGED
 * broadcasts. This method does nothing if previously called.
 */
public static void init(Context context) {
    if (sInitCalled) {
        return;
    }

    sInitCalled = true;

    try {
        DateTimeZone.setProvider(new ResourceZoneInfoProvider(context));
    }
    catch (IOException e) {
        throw new RuntimeException("Could not read ZoneInfoMap. You are probably using Proguard wrong.", e);
    }

    context.getApplicationContext()
        .registerReceiver(new TimeZoneChangedReceiver(), new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED));
}
 
Example 2
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testProviderSecurity() {
    if (OLD_JDK) {
        return;
    }
    try {
        Policy.setPolicy(RESTRICT);
        System.setSecurityManager(new SecurityManager());
        DateTimeZone.setProvider(new MockOKProvider());
        fail();
    } catch (SecurityException ex) {
        // ok
    } finally {
        System.setSecurityManager(null);
        Policy.setPolicy(ALLOW);
    }
}
 
Example 3
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Context context = InstrumentationRegistry.getInstrumentation().getContext();
    DateTimeZone.setProvider(new ResourceZoneInfoProvider(context));

    // Need to initialize these after ResourceZoneInfoProvider.init()
    PARIS = DateTimeZone.forID("Europe/Paris");
    LONDON = DateTimeZone.forID("Europe/London");

    locale = Locale.getDefault();
    zone = DateTimeZone.getDefault();
    Locale.setDefault(Locale.UK);
}
 
Example 4
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testProvider_badClassName() {
    try {
        System.setProperty("org.joda.time.DateTimeZone.Provider", "xxx");
        DateTimeZone.setProvider(null);

    } catch (RuntimeException ex) {
        // expected
        assertEquals(ResourceZoneInfoProvider.class, DateTimeZone.getProvider().getClass());
    } finally {
        System.getProperties().remove("org.joda.time.DateTimeZone.Provider");
        DateTimeZone.setProvider(null);
    }
}
 
Example 5
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameProvider_badClassName() {
    try {
        System.setProperty("org.joda.time.DateTimeZone.NameProvider", "xxx");
        DateTimeZone.setProvider(null);

    } catch (RuntimeException ex) {
        // expected
        assertEquals(DefaultNameProvider.class, DateTimeZone.getNameProvider().getClass());
    } finally {
        System.getProperties().remove("org.joda.time.DateTimeZone.NameProvider");
        DateTimeZone.setProvider(null);
    }
}
 
Example 6
Source File: App.java    From prayer-times-android with Apache License 2.0 3 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Fabric.with(this, new Crashlytics());
    Crashlytics.setUserIdentifier(Preferences.UUID.get());
    if (BuildConfig.DEBUG)
        Crashlytics.setBool("isDebug", true);


    mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);


    DateTimeZone.setProvider(new AndroidTimeZoneProvider());
    LocaleUtils.init(getBaseContext());


    registerReceiver(new TimeZoneChangedReceiver(), new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED));


    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);


    /*if (AppRatingDialog.getInstallationTime() == 0) {
        AppRatingDialog.setInstalltionTime(System.currentTimeMillis());
    }*/

    InternalBroadcastReceiver.loadAll();
    InternalBroadcastReceiver.sender(this).sendOnStart();
    TimeTickReceiver.start(this);

}
 
Example 7
Source File: App.java    From prayer-times-android with Apache License 2.0 3 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Fabric.with(this, new Crashlytics());
    Crashlytics.setUserIdentifier(Preferences.UUID.get());
    if (BuildConfig.DEBUG)
        Crashlytics.setBool("isDebug", true);


    mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);


    DateTimeZone.setProvider(new AndroidTimeZoneProvider());
    LocaleUtils.init(getBaseContext());


    registerReceiver(new TimeZoneChangedReceiver(), new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED));


    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);


    /*if (AppRatingDialog.getInstallationTime() == 0) {
        AppRatingDialog.setInstalltionTime(System.currentTimeMillis());
    }*/

    InternalBroadcastReceiver.loadAll();
    InternalBroadcastReceiver.sender(this).sendOnStart();
    TimeTickReceiver.start(this);

}