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


Java Instant.parse方法代码示例

本文整理汇总了Java中java.time.Instant.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.parse方法的具体用法?Java Instant.parse怎么用?Java Instant.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.Instant的用法示例。


在下文中一共展示了Instant.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold

import java.time.Instant; //导入方法依赖的package包/类
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant lastOfflineNotificationInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);
    Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:22,代码来源:OfflineDevicesJobTests.java

示例2: thatPushNotificationIsSentWhenThresholdWasPassedAndNoNotificationWasEverSent

import java.time.Instant; //导入方法依赖的package包/类
@Test
public void thatPushNotificationIsSentWhenThresholdWasPassedAndNoNotificationWasEverSent() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant jobRunInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.empty());

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:21,代码来源:OfflineDevicesJobTests.java

示例3: testConstructionOfInput

import java.time.Instant; //导入方法依赖的package包/类
@Test
public void testConstructionOfInput() {
    final Instant evaluationTime = Instant.parse("2013-03-28T00:00:00Z");
    final Input input = Input.create("TestRuleSetName",
            DecisionTreeRuleSet.convertNamesToWeightedDrivers(Arrays.asList("driver1", "driver2")),
            evaluationTime);
    assertEquals("TestRuleSetName", input.getRuleSetName());

    assertEquals("*", input.getValueForDriverName("driver1"));
    assertEquals("*", input.getValueForDriverName("driver2"));
    assertEquals(evaluationTime, input.getEvaluationDate());

    assertEquals(Arrays.asList("*", "*"), input.getEvaluationInputs());

    assertEquals("Input{driverMap={WeightedDriver{name='driver1', weight=4}=*, " +
            "WeightedDriver{name='driver2', weight=2}=*}, " +
            "ruleSetName='TestRuleSetName', " +
            "evaluationDate=2013-03-28T00:00:00Z}", input.toString());
}
 
开发者ID:jpmorganchase,项目名称:swblocks-decisiontree,代码行数:20,代码来源:InputTest.java

示例4: deserialze

import java.time.Instant; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 4) {
        String text = lexer.stringVal();
        lexer.nextToken();
        if (type == LocalDateTime.class) {
            return LocalDateTime.parse(text);
        }
        if (type == LocalDate.class) {
            return LocalDate.parse(text);
        }
        if (type == LocalTime.class) {
            return LocalTime.parse(text);
        }
        if (type == ZonedDateTime.class) {
            return ZonedDateTime.parse(text);
        }
        if (type == OffsetDateTime.class) {
            return OffsetDateTime.parse(text);
        }
        if (type == OffsetTime.class) {
            return OffsetTime.parse(text);
        }
        if (type == ZoneId.class) {
            return ZoneId.of(text);
        }
        if (type == Period.class) {
            return Period.parse(text);
        }
        if (type == Duration.class) {
            return Duration.parse(text);
        }
        if (type == Instant.class) {
            return Instant.parse(text);
        }
        return null;
    }
    throw new UnsupportedOperationException();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:40,代码来源:Jdk8DateCodec.java

示例5: ensureValid

import java.time.Instant; //导入方法依赖的package包/类
@Override
public void ensureValid(String name, Object value) {
    String timestamp = (String) value;
    try {
        Instant.parse(timestamp);
    } catch (DateTimeParseException e) {
        throw new ConfigException(name, value, "Wasn't able to parse the timestamp, make sure it is formatted according to ISO-8601 standards");
    }


}
 
开发者ID:simplesteph,项目名称:kafka-connect-github-source,代码行数:12,代码来源:TimestampValidator.java

示例6: stringToInstant

import java.time.Instant; //导入方法依赖的package包/类
public static final Instant stringToInstant(String text) {
    try {
        return Instant.parse(text);
    } catch (Exception ex) {
        try {
            return Instant.ofEpochMilli(Long.parseLong(text));
        } catch (Exception ex2) {
            try {
                return Timestamp.valueOf(text).toInstant();
            } catch (Exception ex3) {
                return null;
            }
        }
    }
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:16,代码来源:Util.java

示例7: createAnItemEvictedEvent

import java.time.Instant; //导入方法依赖的package包/类
@Test
public void createAnItemEvictedEvent() throws Exception {

  Instant fixedInstant = Instant.parse("2017-04-07T10:02:05.456Z");
  Clock clock = Clock.fixed(fixedInstant, ZoneId.of("+02:00"));
  Item item = anItem().withName("item name").build();

  Event<Item> event = new SimpleEventFactory(clock).newItemEvictedEvent(item);

  assertThat(event.created(), is(fixedInstant));
  assertThat(event.body(), is(item));
}
 
开发者ID:gdipaolantonio,项目名称:ripostiglio,代码行数:13,代码来源:SimpleEventFactoryTest.java

示例8: createAnItemStoredEvent

import java.time.Instant; //导入方法依赖的package包/类
@Test
public void createAnItemStoredEvent() throws Exception {

  Instant fixedInstant = Instant.parse("2017-03-21T22:35:18.123Z");
  Clock clock = Clock.fixed(fixedInstant, ZoneId.of("+01:00"));
  Item item = anItem().withName("item name").build();

  Event<Item> event = new SimpleEventFactory(clock).newItemStoredEvent(item);

  assertThat(event.created(), is(fixedInstant));
  assertThat(event.body(), is(item));
}
 
开发者ID:gdipaolantonio,项目名称:ripostiglio,代码行数:13,代码来源:SimpleEventFactoryTest.java

示例9: CoffeeBrewFinished

import java.time.Instant; //导入方法依赖的package包/类
public CoffeeBrewFinished(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:CoffeeBrewFinished.java

示例10: setStartDate

import java.time.Instant; //导入方法依赖的package包/类
public void setStartDate(String startDate) {
    if (StringUtils.isNotBlank(startDate)) {
        this.startDate = Instant.parse(startDate);
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:6,代码来源:SystemEvent.java

示例11: CoffeeBrewStarted

import java.time.Instant; //导入方法依赖的package包/类
public CoffeeBrewStarted(JsonObject jsonObject) {
    this(new OrderInfo(jsonObject.getJsonObject("orderInfo")), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:CoffeeBrewStarted.java

示例12: OrderFinished

import java.time.Instant; //导入方法依赖的package包/类
public OrderFinished(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:OrderFinished.java

示例13: createdDateProvider

import java.time.Instant; //导入方法依赖的package包/类
private static Stream<Instant> createdDateProvider() {
	Instant firstDateInstant = Instant.parse("2017-01-01T08:00:00.846Z");
	Instant secondDateInstant = Instant.parse("2018-01-01T08:00:00.846Z");
	return Stream.of(firstDateInstant, secondDateInstant);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:6,代码来源:UnprocessedCpcFileDataTest.java

示例14: OrderAccepted

import java.time.Instant; //导入方法依赖的package包/类
public OrderAccepted(JsonObject jsonObject) {
    this(new OrderInfo(jsonObject.getJsonObject("orderInfo")), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:OrderAccepted.java

示例15: OrderBeansValidated

import java.time.Instant; //导入方法依赖的package包/类
public OrderBeansValidated(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:OrderBeansValidated.java


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