本文整理汇总了Java中java.time.Duration.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.parse方法的具体用法?Java Duration.parse怎么用?Java Duration.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeTo
import java.time.Duration; //导入方法依赖的package包/类
private DateTime getTimeTo(IntentRequest request, DateTime from) {
final String sDuration = sv(request, SLOT_DURATION);
final String sDateFrom = sv(request, SLOT_DATE_FROM);
final String sDateTo = sv(request, SLOT_DATE_TO);
final String sTimeTo = sv(request, SLOT_TIME_TO);
if(sTimeTo != null) {
if(sDateTo != null) {
return DateTime.parse(sDateTo + "T" + sTimeTo);
}
return DateTime.parse(sDateFrom + "T" + sTimeTo);
} else if(sDateTo != null) {
return DateTime.parse(sDateTo).withTimeAtStartOfDay();
}
final Duration duration = Duration.parse(sDuration);
return from.plus(duration.toMillis());
}
示例2: parseDuration
import java.time.Duration; //导入方法依赖的package包/类
Duration parseDuration(String rawDuration) {
val arr = rawDuration.split(":");
val input = "PT" + arr[0] + "H" + arr[1] + "M" + arr[2] + "S";
try {
return Duration.parse(input);
} catch (DateTimeParseException ex) {
return Duration.ofMillis(0);
}
}
示例3: deserialize
import java.time.Duration; //导入方法依赖的package包/类
@Override
public Duration deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
try {
return super.deserialize(p, ctxt);
} catch (Exception e) {
return Duration.parse("PT" + p.getText()); // hax
}
}
示例4: getFuelDuration
import java.time.Duration; //导入方法依赖的package包/类
public Duration getFuelDuration() {
try {
return Duration.parse(fuelDuration);
} catch (DateTimeParseException e) {
StickyChunk.getInstance().getLogger().warn(String.format("Fuel-Duration (%s) of %s is malformed. Using 8h instead", fuelDuration, getName()));
return Duration.ofHours(8);
}
}
示例5: factory_parse_comma
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse_comma(String text, long expectedSeconds, int expectedNanoOfSecond) {
text = text.replace('.', ',');
Duration test = Duration.parse(text);
assertEquals(test.getSeconds(), expectedSeconds);
assertEquals(test.getNano(), expectedNanoOfSecond);
}
示例6: validationIsSuccessfulWhenDurationIsNotExceeded
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void validationIsSuccessfulWhenDurationIsNotExceeded() {
Messages messages = messages();
Instant now = Instant.now();
DurationNotExceededValidator<Object> validator = new DurationNotExceededValidator<>(DEFAULT_MESSAGE, context -> now.minus(5, MINUTES), context -> now, Duration.parse("PT5M"));
Messages returnedMessages = validator.validate(null, messages);
assertThat(returnedMessages, sameInstance(messages));
assertThat(returnedMessages.hasErrorLike(DEFAULT_MESSAGE), is(false));
}
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:11,代码来源:DurationNotExceededValidatorTest.java
示例7: fromString
import java.time.Duration; //导入方法依赖的package包/类
public static Duration fromString(String s) {
String time = ("P" + s).toUpperCase();
if (!time.endsWith("D")) {
time = time.replace("D", "DT");
}
if (!time.contains("D")) {
time = time.replace("P", "PT");
}
return Duration.parse(time);
}
示例8: deserialize
import java.time.Duration; //导入方法依赖的package包/类
@Override
public void deserialize(ConfigurationSection config) {
ISerializable.deserialize(config, this);
this.duration = Duration.parse(config.getString("duration"));
this.resetPeriod = Period.parse(config.getString("resetPeriod"));
this.periodCountingBase = ZonedDateTime.parse(config.getString("periodCountingBase"));
this.creationTime = Instant.parse(config.getString("creationTime"));
this.lastTimerCallback = Instant.parse(config.getString("lastTimerCallback"));
this.lastResetCallback = Instant.parse(config.getString("lastResetCallback"));
this.lastCheckpoint = Instant.parse(config.getString("lastCheckpoint"));
this.timeElapsed = Duration.parse(config.getString("timeElapsed"));
}
示例9: setServiceLevel
import java.time.Duration; //导入方法依赖的package包/类
@Override
public void setServiceLevel(String serviceLevel) {
try {
Duration.parse(serviceLevel);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid duration. Please use the format defined by ISO 8601");
}
this.serviceLevel = serviceLevel;
}
示例10: factory_parseFailures_comma
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="parseFailure", expectedExceptions=DateTimeParseException.class)
public void factory_parseFailures_comma(String text) {
text = text.replace('.', ',');
Duration.parse(text);
}
示例11: factory_parse_plus
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse_plus(String text, long expectedSeconds, int expectedNanoOfSecond) {
Duration test = Duration.parse("+" + text);
assertEquals(test.getSeconds(), expectedSeconds);
assertEquals(test.getNano(), expectedNanoOfSecond);
}
示例12: factory_parse_tooSmall_decimal
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_tooSmall_decimal() {
Duration.parse("PT" + Long.MIN_VALUE + ".1S");
}
示例13: step
import java.time.Duration; //导入方法依赖的package包/类
/**
* Returns the step size (reporting frequency) to use. The default is 10 seconds.
*/
default Duration step() {
String v = get(prefix() + ".step");
return v == null ? Duration.ofMinutes(1) : Duration.parse(v);
}
示例14: factory_parse_tooSmall
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_tooSmall() {
Duration.parse("PT" + Long.MIN_VALUE + "1S");
}
示例15: factory_parse_tooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_tooBig() {
Duration.parse("PT" + Long.MAX_VALUE + "1S");
}