本文整理汇总了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!");
}
开发者ID:EndlessBot,项目名称:Endless,代码行数:25,代码来源:TimeFor.java
示例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
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKZoneIdSerialization.java
示例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));
}
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:18,代码来源:TimeZoneTest.java
示例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);
}
开发者ID:seratch,项目名称:java-time-backport,代码行数:29,代码来源:ZoneRegion.java
示例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);
}
开发者ID:m-m-m,项目名称:java8-backports,代码行数:28,代码来源:ZoneRegion.java
示例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);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ZoneRegion.java
示例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");
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZoneRulesProvider.java
示例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);
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TestZoneId.java
示例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);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:TzdbZoneRulesProvider.java
示例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);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:TzdbZoneRulesProvider.java
示例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);
}
}
开发者ID:eclipse,项目名称:yasson,代码行数:11,代码来源:TimeZoneTypeDeserializer.java
示例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");
}
}
开发者ID:1and1,项目名称:go-maven-poller,代码行数:17,代码来源:MavenRepoConfig.java
注:本文中的java.time.zone.ZoneRulesException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论