当前位置: 首页>>代码示例>>Java>>正文


Java Duration.parse方法代码示例

本文整理汇总了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());
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:20,代码来源:NewEventSpeechlet.java

示例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);
        }
    }
 
开发者ID:ccremer,项目名称:clustercode,代码行数:12,代码来源:FfmpegParser.java

示例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
    }
}
 
开发者ID:carlanton,项目名称:mpd-tools,代码行数:9,代码来源:ValidatorValidator.java

示例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);
	}
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:9,代码来源:BlockChunkLoaderConfig.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKDuration.java

示例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);
}
 
开发者ID:RedEpicness,项目名称:RManager,代码行数:11,代码来源:CoreUtil.java

示例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"));
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:14,代码来源:TimerPersistData.java

示例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;
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:10,代码来源:ClassificationImpl.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKDuration.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TCKDuration.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKDuration.java

示例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);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:StepRegistryConfig.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKDuration.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKDuration.java


注:本文中的java.time.Duration.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。