當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。