use of java.time.zone.ZoneRulesException in project j2objc by google.
the class ZoneRegion method ofId.
/**
* 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 ZoneRulesException if checking availability and the ID cannot be found
*/
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
Objects.requireNonNull(zoneId, "zoneId");
checkName(zoneId);
ZoneRules rules = null;
try {
// always attempt load for better behavior after deserialization
rules = ZoneRulesProvider.getRules(zoneId, true);
} catch (ZoneRulesException ex) {
if (checkAvailable) {
throw ex;
}
}
return new ZoneRegion(zoneId, rules);
}
use of java.time.zone.ZoneRulesException in project j2objc by google.
the class TCKZoneIdSerialization method test_deserialization_lenient_characters.
@Test
public void test_deserialization_lenient_characters() throws Exception {
// an ID can be loaded without validation during deserialization
String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-";
ZoneId deser = deserialize(id);
// getId, equals, hashCode, toString and normalized are OK
assertEquals(deser.getId(), id);
assertEquals(deser.toString(), id);
assertEquals(deser, deser);
assertEquals(deser.hashCode(), deser.hashCode());
assertEquals(deser.normalized(), deser);
// getting the rules is not
try {
deser.getRules();
fail();
} catch (ZoneRulesException ex) {
// expected
}
}
use of java.time.zone.ZoneRulesException in project ballerina by ballerina-lang.
the class Utils method createTimeZone.
public static BStruct createTimeZone(StructInfo timezoneStructInfo, String zoneIdValue) {
String zoneIdName;
try {
ZoneId zoneId = ZoneId.of(zoneIdValue);
zoneIdName = zoneId.toString();
// Get offset in seconds
TimeZone tz = TimeZone.getTimeZone(zoneId);
int offsetInMills = tz.getOffset(new Date().getTime());
int offset = offsetInMills / 1000;
return BLangVMStructs.createBStruct(timezoneStructInfo, zoneIdName, offset);
} catch (ZoneRulesException e) {
throw new BallerinaException("invalid timezone id: " + zoneIdValue);
}
}
use of java.time.zone.ZoneRulesException in project teammates by TEAMMATES.
the class TzdbResourceZoneRulesProvider method provideRules.
@Override
protected ZoneRules provideRules(String zoneId, boolean forCaching) {
// forCaching flag is ignored because this is not a dynamic provider
Object obj = regionToRules.get(zoneId);
if (obj == null) {
throw new ZoneRulesException("Unknown time-zone ID: " + zoneId);
}
try {
if (obj instanceof byte[]) {
byte[] bytes = (byte[]) obj;
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes));
obj = serRead(dis);
regionToRules.put(zoneId, obj);
}
return (ZoneRules) obj;
} catch (Exception ex) {
throw new ZoneRulesException("Invalid binary time-zone data: TZDB:" + zoneId + ", version: " + versionId, ex);
}
}
use of java.time.zone.ZoneRulesException in project neo4j by neo4j.
the class DateTimeValue method parse.
private static DateTimeValue parse(Matcher matcher, Supplier<ZoneId> defaultZone) {
LocalDateTime local = LocalDateTime.of(parseDate(matcher), optTime(matcher));
String zoneName = matcher.group("zoneName");
ZoneOffset offset = parseOffset(matcher);
ZoneId zone;
if (zoneName != null) {
zone = parseZoneName(zoneName);
if (offset != null) {
try {
if (!zone.getRules().isValidOffset(local, offset)) {
throw new InvalidArgumentException("Timezone and offset do not match: " + matcher.group());
}
} catch (ZoneRulesException e) {
throw new TemporalParseException(e.getMessage(), e);
}
}
} else if (offset != null) {
zone = offset;
} else {
zone = defaultZone.get();
}
return new DateTimeValue(ZonedDateTime.ofLocal(local, zone, offset));
}
Aggregations