org.threeten.bp.zone.ZoneRulesProvider Java Examples
The following examples show how to use
org.threeten.bp.zone.ZoneRulesProvider.
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: AssetsZoneRulesInitializer.java From ThreeTenABP with Apache License 2.0 | 6 votes |
@Override protected void initializeProviders() { TzdbZoneRulesProvider provider; InputStream is = null; try { is = context.getAssets().open(assetPath); provider = new TzdbZoneRulesProvider(is); } catch (IOException e) { throw new IllegalStateException(assetPath + " missing from assets", e); } finally { if (is != null) { try { is.close(); } catch (IOException ignored) { } } } ZoneRulesProvider.registerProvider(provider); }
Example #2
Source File: ZoneRegion.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Obtains an instance of {@code ZoneId} from an identifier. * * @param zoneId the time-zone ID, not null * @param checkAvailable whether to check if the zone ID is available * @return the zone ID, not null * @throws DateTimeException if the ID format is invalid * @throws DateTimeException if checking availability and the ID cannot be found */ static ZoneRegion ofId(String zoneId, boolean checkAvailable) { Jdk8Methods.requireNonNull(zoneId, "zoneId"); if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) { throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId); } ZoneRules rules = null; try { // always attempt load for better behavior after deserialization rules = ZoneRulesProvider.getRules(zoneId, true); } catch (ZoneRulesException ex) { // special case as removed from data file if (zoneId.equals("GMT0")) { rules = ZoneOffset.UTC.getRules(); } else if (checkAvailable) { throw ex; } } return new ZoneRegion(zoneId, rules); }
Example #3
Source File: LazyThreeTen.java From lazythreetenbp with Apache License 2.0 | 5 votes |
/** * Call on background thread to eagerly load all zones. Starts with loading * {@link ZoneId#systemDefault()} which is the one most likely to be used. */ @WorkerThread public static void cacheZones() { ZoneId.systemDefault().getRules(); for (String zoneId : ZoneRulesProvider.getAvailableZoneIds()) { ZoneRulesProvider.getRules(zoneId, true); } }
Example #4
Source File: ZoneWriterTest.java From lazythreetenbp with Apache License 2.0 | 5 votes |
private SortedMap<String, ZoneRules> generateZones(String... zoneIds) throws IOException { SortedMap<String, ZoneRules> zones = new TreeMap<>(); for (String zoneId : zoneIds) { zones.put(zoneId, ZoneRulesProvider.getRules(zoneId, false)); } zoneWriter.writeZones(zones); return zones; }
Example #5
Source File: AndroidThreeTenTest.java From ThreeTenABP with Apache License 2.0 | 5 votes |
@Test public void customPath() { AndroidThreeTen.init(context, "does/not/exist.dat"); try { // This will trigger class loading and parsing of the supplied file. ZoneRulesProvider.getAvailableZoneIds(); fail(); } catch (ExceptionInInitializerError e) { assertThat(e).hasCauseThat().isInstanceOf(IllegalStateException.class); assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("does/not/exist.dat missing from assets"); } }
Example #6
Source File: TestZoneIdParser.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name="zones") Object[][] populateTestData() { Set<String> ids = ZoneRulesProvider.getAvailableZoneIds(); Object[][] rtnval = new Object[ids.size()][]; int i = 0; for (String id : ids) { rtnval[i++] = new Object[] { id, ZoneId.of(id) }; } return rtnval; }
Example #7
Source File: LazyZoneRulesInitializer.java From lazythreetenbp with Apache License 2.0 | 4 votes |
@Override protected void initializeProviders() { ZoneRulesProvider.registerProvider(new LazyZoneRulesProvider(application)); }
Example #8
Source File: AndroidThreeTenTest.java From lazythreetenbp with Apache License 2.0 | 4 votes |
@Test public void init() { LazyThreeTen.init(context); assertThat(ZoneRulesProvider.getAvailableZoneIds()).isNotEmpty(); }
Example #9
Source File: AndroidThreeTenTest.java From ThreeTenABP with Apache License 2.0 | 4 votes |
@Test public void litmus() { AndroidThreeTen.init(context); assertThat(ZoneRulesProvider.getAvailableZoneIds()).isNotEmpty(); }
Example #10
Source File: ZoneRegion.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public ZoneRules getRules() { // additional query for group provider when null allows for possibility // that the provider was added after the ZoneId was created return (rules != null ? rules : ZoneRulesProvider.getRules(id, false)); }
Example #11
Source File: ZoneId.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Gets the set of available zone IDs. * <p> * This set includes the string form of all available region-based IDs. * Offset-based zone IDs are not included in the returned set. * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}. * <p> * The set of zone IDs can increase over time, although in a typical application * the set of IDs is fixed. Each call to this method is thread-safe. * * @return a modifiable copy of the set of zone IDs, not null */ public static Set<String> getAvailableZoneIds() { return new HashSet<String>(ZoneRulesProvider.getAvailableZoneIds()); }