本文整理汇总了Java中java.time.zone.ZoneRulesException类的典型用法代码示例。如果您正苦于以下问题:Java ZoneRulesException类的具体用法?Java ZoneRulesException怎么用?Java ZoneRulesException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZoneRulesException类属于java.time.zone包,在下文中一共展示了ZoneRulesException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@Override
protected void execute(CommandEvent event)
{
String args = event.getArgs();
if(args.isEmpty())
{
event.replyWarning("Please specify a timezone!");
return;
}
try
{
ZoneId.of(args);
}
catch(ZoneRulesException e)
{
event.replyError("Please specify a valid timezone!");
return;
}
db.setTimezone(event.getAuthor(), args);
event.replySuccess("Successfully updated timezone!");
}
示例2: test_deserialization_lenient_characters
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@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
}
}
示例3: shouldAllTimeZonesBeValid
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@Test
public void shouldAllTimeZonesBeValid() {
boolean allValid = true;
for (TimeZone tz : TimeZone.values()) {
try {
tz.getZoneId().getId().equals(tz.getId());
} catch (ZoneRulesException e) {
e.printStackTrace();
allValid = false;
}
}
assertThat(allValid, org.hamcrest.Matchers.is(true));
}
示例4: ofId
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
/**
* 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);
}
示例5: ofId
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
/**
* 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) {
Jdk7Methods.Objects_requireNonNull(zoneId, "zoneId");
if (zoneId.length() < 2 || zoneId.startsWith("UTC") || zoneId.startsWith("GMT")
|| (PATTERN.matcher(zoneId).matches() == false)) {
throw new DateTimeException("ZoneId format is not a valid region format");
}
ZoneRules rules = null;
try {
// always attempt load for better behavior after deserialization
rules = ZoneRulesProvider.getRules(zoneId);
} catch (ZoneRulesException ex) {
if (checkAvailable) {
throw ex;
}
}
return new ZoneRegion(zoneId, rules);
}
示例6: ofId
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
/**
* 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);
}
示例7: provideRules
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@Override
protected ZoneRules provideRules(String zoneId, boolean forCaching) {
if (zoneId.equals("FooLocation")) {
return rules;
}
throw new ZoneRulesException("Invalid");
}
示例8: test_systemDefault_unableToConvert_unknownId
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
TimeZone current = TimeZone.getDefault();
try {
TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
ZoneId.systemDefault();
} finally {
TimeZone.setDefault(current);
}
}
示例9: TzdbZoneRulesProvider
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
/**
* Creates an instance.
*
* @throws ZoneRulesException if unable to load
*/
public TzdbZoneRulesProvider(List<Path> files) {
try {
load(files);
} catch (Exception ex) {
throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
}
}
示例10: getZoneRules
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
public ZoneRules getZoneRules(String zoneId) {
Object obj = zones.get(zoneId);
if (obj == null) {
String zoneId0 = zoneId;
if (links.containsKey(zoneId)) {
zoneId = links.get(zoneId);
obj = zones.get(zoneId);
}
if (obj == null) {
// Timezone link can be located in 'backward' file and it
// can refer to another link, so we need to check for
// link one more time, before throwing an exception
String zoneIdBack = zoneId;
if (links.containsKey(zoneId)) {
zoneId = links.get(zoneId);
obj = zones.get(zoneId);
}
if (obj == null) {
throw new ZoneRulesException("Unknown time-zone ID: " + zoneIdBack);
}
}
}
if (obj instanceof ZoneRules) {
return (ZoneRules)obj;
}
try {
ZoneRules zrules = buildRules(zoneId, (List<ZoneLine>)obj);
zones.put(zoneId, zrules);
return zrules;
} catch (Exception ex) {
throw new ZoneRulesException(
"Invalid binary time-zone data: TZDB:" + zoneId, ex);
}
}
示例11: deserialize
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
@Override
protected TimeZone deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) {
try {
final ZoneId zoneId = ZoneId.of(jsonValue);
final ZonedDateTime zonedDateTime = LocalDateTime.now().atZone(zoneId);
return new SimpleTimeZone(zonedDateTime.getOffset().getTotalSeconds() * 1000, zoneId.getId());
} catch (ZoneRulesException e) {
throw new JsonbException(Messages.getMessage(MessageKeys.ZONE_PARSE_ERROR, jsonValue), e);
}
}
示例12: getTimeZone
import java.time.zone.ZoneRulesException; //导入依赖的package包/类
/**
* Returns the specified time zone from the repository configuration or the default time zone if none specified.
*
* @return the time zone
*/
public ZoneId getTimeZone() {
if (timeZone == null) {
return ZoneId.systemDefault();
}
try {
return ZoneId.of(timeZone);
} catch (final ZoneRulesException e) {
LOGGER.warn("The time zone was not found. Uses GMT as fallback.");
return ZoneId.of("GMT");
}
}