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


Java ZonedDateTime类代码示例

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


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

示例1: naNValuesInIntervall

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void naNValuesInIntervall(){
    List<Tick> ticks = new ArrayList<>();
    for (long i = 0; i<= 10; i++){ // (NaN, 1, NaN, 2, NaN, 3, NaN, 4, ...)
        Decimal closePrice = i % 2 == 0 ? Decimal.valueOf(i): Decimal.NaN;
        Tick tick = new BaseTick(ZonedDateTime.now().plusDays(i),Decimal.NaN, Decimal.NaN,Decimal.NaN, Decimal.NaN, Decimal.NaN);
        ticks.add(tick);
    }

    BaseTimeSeries series = new BaseTimeSeries("NaN test",ticks);
    LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 2);
    for (int i = series.getBeginIndex(); i<= series.getEndIndex(); i++){
        if (i % 2 != 0){
            assertEquals(series.getTick(i-1).getClosePrice().toString(),lowestValue.getValue(i).toString());
        } else
        assertEquals(series.getTick(Math.max(0,i-1)).getClosePrice().toString(),lowestValue.getValue(i).toString());
    }
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:LowestValueIndicatorTest.java

示例2: getMockInventoryEntry

import java.time.ZonedDateTime; //导入依赖的package包/类
/**
 * Returns mock {@link InventoryEntry} instance. Executing getters on returned instance will return values passed
 * in parameters.
 *
 * @param sku result of calling {@link InventoryEntry#getSku()}
 * @param quantityOnStock result of calling {@link InventoryEntry#getQuantityOnStock()}
 * @param restockableInDays result of calling {@link InventoryEntry#getRestockableInDays()}
 * @param expectedDelivery result of calling {@link InventoryEntry#getExpectedDelivery()}
 * @param supplyChannel result of calling {@link InventoryEntry#getSupplyChannel()}
 * @param customFields result of calling {@link InventoryEntry#getCustom()}
 * @return mock instance of {@link InventoryEntry}
 */
public static InventoryEntry getMockInventoryEntry(final String sku,
                                                   final Long quantityOnStock,
                                                   final Integer restockableInDays,
                                                   final ZonedDateTime expectedDelivery,
                                                   final Reference<Channel> supplyChannel,
                                                   final CustomFields customFields) {
    final InventoryEntry inventoryEntry = mock(InventoryEntry.class);
    when(inventoryEntry.getSku()).thenReturn(sku);
    when(inventoryEntry.getQuantityOnStock()).thenReturn(quantityOnStock);
    when(inventoryEntry.getRestockableInDays()).thenReturn(restockableInDays);
    when(inventoryEntry.getExpectedDelivery()).thenReturn(expectedDelivery);
    when(inventoryEntry.getSupplyChannel()).thenReturn(supplyChannel);
    when(inventoryEntry.getCustom()).thenReturn(customFields);
    return inventoryEntry;
}
 
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:28,代码来源:InventorySyncMockUtils.java

示例3: UserDTO

import java.time.ZonedDateTime; //导入依赖的package包/类
public UserDTO(Long id, String login, String firstName, String lastName,
    String email, boolean activated, String imageUrl, String langKey,
    String createdBy, ZonedDateTime createdDate, String lastModifiedBy, ZonedDateTime lastModifiedDate,
    Set<String> authorities) {

    this.id = id;
    this.login = login;
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
    this.activated = activated;
    this.imageUrl = imageUrl;
    this.langKey = langKey;
    this.createdBy = createdBy;
    this.createdDate = createdDate;
    this.lastModifiedBy = lastModifiedBy;
    this.lastModifiedDate = lastModifiedDate;
    this.authorities = authorities;
}
 
开发者ID:ElectronicArmory,项目名称:Armory,代码行数:20,代码来源:UserDTO.java

示例4: refreshExpirationDates

import java.time.ZonedDateTime; //导入依赖的package包/类
public long refreshExpirationDates(Map<String, Integer> expirationSeconds) {
    ZonedDateTime now = ZonedDateTime.now();
    return gameServerRepository.findByIdIn(expirationSeconds.keySet()).parallelStream()
        .map(server -> {
            int seconds = expirationSeconds.get(server.getId());
            if (seconds != 0) {
                server.setExpirationDate(now.plusSeconds(seconds));
                if (server.getPlayers() > 0 && seconds < 60 * 15) {
                    ZonedDateTime lastRconAnnounce = Optional.ofNullable(server.getLastRconAnnounce())
                        .orElse(Instant.EPOCH.atZone(ZoneId.systemDefault()));
                    // announce only once per interval to avoid spamming
                    if (lastRconAnnounce.plusMinutes(getRconSayIntervalMinutes()).isBefore(ZonedDateTime.now())) {
                        Result<String> result = tryRcon(server,
                            "say [GameServers] Server will expire in " + humanizeShort(Duration.ofSeconds(seconds)));
                        if (result.isSuccessful()) {
                            server.setLastRconAnnounce(ZonedDateTime.now());
                        }
                    }
                }
            }
            server.setExpirationCheckDate(now);
            return server;
        })
        .map(gameServerRepository::save)
        .count();
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:27,代码来源:GameServerService.java

示例5: test_print_pattern_X

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="print")
public void test_print_pattern_X(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    String pattern = null;
    if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
        pattern = "X";
    } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
        pattern = "XX";
    } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) {
        pattern = "XXX";
    } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) {
        pattern = "XXXX";
    } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
        pattern = "XXXXX";
    }
    if (pattern != null) {
        ZonedDateTime zdt = ldt.atZone(zone);
        builder.appendPattern(pattern);
        String output = builder.toFormatter().format(zdt);
        assertEquals(output, expected);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKOffsetPrinterParser.java

示例6: now_Clock_allSecsInDay_utc

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
        assertEquals(test.getZone(), ZoneOffset.UTC);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TCKZonedDateTime.java

示例7: initDataForYearlyTimeFrame

import java.time.ZonedDateTime; //导入依赖的package包/类
@Before
public void initDataForYearlyTimeFrame(){

    String[] dataLine = rawData_1_week.split("\n");
    List<Tick> ticks = new ArrayList<>();
    for (int i = 0; i < dataLine.length; i++) {
        String[] tickData = dataLine[i].split(",");
        ZonedDateTime date = LocalDate.parse(tickData[0], DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay(ZoneId.systemDefault());
        double open = Double.parseDouble(tickData[1]);
        double high = Double.parseDouble(tickData[2]);
        double low = Double.parseDouble(tickData[3]);
        double close = Double.parseDouble(tickData[4]);
        double volume = Double.parseDouble(tickData[6]);
        ticks.add(new BaseTick(date, open, high, low, close, volume));
    }
    series_1_weeks = new BaseTimeSeries("FB_daily",ticks);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:18,代码来源:PivotPointIndicatorTest.java

示例8: parseGeneralMessageDelete

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void parseGeneralMessageDelete() {
    String data = "\\GKV8turbo_generalmessages|KV8turbo_generalmessages|openOV RET|||UTF-8|0.1|2017-04-11T22:05:46+02:00|\uFEFF\r\n" +
            "\\TGENERALMESSAGEDELETE|GENERALMESSAGEDELETE|start object\r\n" +
            "\\LDataOwnerCode|MessageCodeDate|MessageCodeNumber|TimingPointDataOwnerCode|TimingPointCode\r\n" +
            "RET|2017-04-11|27|ALGEMEEN|31001347\r\n";
    Kv78Packet p = Kv78Parser.parseMessage(data);

    Assert.assertEquals("KV8turbo_generalmessages", p.getType());
    Assert.assertEquals("openOV RET", p.getComment());
    Assert.assertEquals("UTF-8", p.getEncoding());
    Assert.assertEquals("0.1", p.getVersion());
    Assert.assertEquals(ZonedDateTime.parse("2017-04-11T22:05:46+02:00"), p.getGenerated());

    Assert.assertEquals("GENERALMESSAGEDELETE", p.getTables().get(0).getTableName());
    Assert.assertEquals("start object", p.getTables().get(0).getTableComment());

    Assert.assertEquals(1, p.getTables().get(0).getRecords().size());
    Map<String, String> record = p.getTables().get(0).getRecords().get(0);
    Assert.assertEquals(5, record.size());
    Assert.assertEquals("RET", record.get("DataOwnerCode"));
    Assert.assertEquals("2017-04-11", record.get("MessageCodeDate"));
    Assert.assertEquals("27", record.get("MessageCodeNumber"));
    Assert.assertEquals("ALGEMEEN", record.get("TimingPointDataOwnerCode"));
    Assert.assertEquals("31001347", record.get("TimingPointCode"));
}
 
开发者ID:CROW-NDOV,项目名称:displaydirect,代码行数:27,代码来源:Kv78ParserTest.java

示例9: should_wait_betweentasktimeout_when_task_found

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void should_wait_betweentasktimeout_when_task_found() throws Exception {
    Duration betweenTaskTimeout = Duration.ofHours(1L);
    Duration noTaskTimeout = Duration.ofMillis(5L);

    QueueConsumer queueConsumer = mock(QueueConsumer.class);
    TaskPicker taskPicker = mock(TaskPicker.class);
    TaskRecord taskRecord = new TaskRecord(0, null, 0, ZonedDateTime.now(),
            ZonedDateTime.now(), null, null);
    when(taskPicker.pickTask(queueConsumer)).thenReturn(taskRecord);
    TaskProcessor taskProcessor = mock(TaskProcessor.class);


    when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(testLocation1,
            QueueSettings.builder().withBetweenTaskTimeout(betweenTaskTimeout).withNoTaskTimeout(noTaskTimeout).build()));
    QueueProcessingStatus status = new QueueRunnerInSeparateTransactions(taskPicker, taskProcessor).runQueue(queueConsumer);

    assertThat(status, equalTo(QueueProcessingStatus.PROCESSED));

    verify(taskPicker).pickTask(queueConsumer);
    verify(taskProcessor).processTask(queueConsumer, taskRecord);
}
 
开发者ID:yandex-money,项目名称:db-queue,代码行数:23,代码来源:QueueRunnerInSeparateTransactionsTest.java

示例10: converteerAttributen

import java.time.ZonedDateTime; //导入依赖的package包/类
private void converteerAttributen(final MetaRecord record, final BlobRecord blobRecord) {
    for (final Map.Entry<AttribuutElement, MetaAttribuut> entry : record.getAttributen().entrySet()) {
        final AttribuutElement element = entry.getKey();
        final Object huidigeWaarde = entry.getValue().getWaarde();
        final Object value;

        if (huidigeWaarde instanceof Date) {
            value = ((Date) huidigeWaarde).getTime();
        } else if (huidigeWaarde instanceof ZonedDateTime) {
            value = ((ZonedDateTime) huidigeWaarde).toInstant().toEpochMilli();
        } else {
            value = huidigeWaarde;
        }

        blobRecord.addAttribuut(element.getId(), value);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:18,代码来源:BlobConverter.java

示例11: testEquals_differentCreationTime

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void testEquals_differentCreationTime() {
    Federation otherFederation = new Federation(
            Arrays.asList(new BtcECKey[]{
                    BtcECKey.fromPrivate(BigInteger.valueOf(100)),
                    BtcECKey.fromPrivate(BigInteger.valueOf(200)),
                    BtcECKey.fromPrivate(BigInteger.valueOf(300)),
                    BtcECKey.fromPrivate(BigInteger.valueOf(400)),
                    BtcECKey.fromPrivate(BigInteger.valueOf(500)),
                    BtcECKey.fromPrivate(BigInteger.valueOf(600)),
            }),
            ZonedDateTime.parse("2017-06-10T02:30:01Z").toInstant(),
            0L,
            NetworkParameters.fromID(NetworkParameters.ID_REGTEST)
    );
    Assert.assertFalse(federation.equals(otherFederation));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:FederationTest.java

示例12: reenqueue_should_update_process_time

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void reenqueue_should_update_process_time() throws Exception {
    QueueLocation location = generateUniqueLocation();
    String actor = "abc123";
    Long enqueueId = executeInTransaction(() ->
            queueDao.enqueue(location, new EnqueueParams<String>().withActor(actor)));

    ZonedDateTime beforeExecution = ZonedDateTime.now();
    Duration executionDelay = Duration.ofHours(1L);
    Boolean reenqueueResult = executeInTransaction(() -> queueActorDao.reenqueue(location, actor, executionDelay));
    Assert.assertThat(reenqueueResult, equalTo(true));
    jdbcTemplate.query("select * from " + QueueDatabaseInitializer.DEFAULT_TABLE_NAME + " where id=" + enqueueId, rs -> {
        ZonedDateTime afterExecution = ZonedDateTime.now();
        Assert.assertThat(rs.next(), equalTo(true));
        ZonedDateTime processTime = ZonedDateTime.ofInstant(rs.getTimestamp("process_time").toInstant(),
                ZoneId.systemDefault());

        Assert.assertThat(processTime.isAfter(beforeExecution.plus(executionDelay)), equalTo(true));
        Assert.assertThat(processTime.isBefore(afterExecution.plus(executionDelay)), equalTo(true));
        return new Object();
    });
}
 
开发者ID:yandex-money,项目名称:db-queue,代码行数:23,代码来源:QueueActorDaoTest.java

示例13: test_AWS_SIG4_string_to_sign

import java.time.ZonedDateTime; //导入依赖的package包/类
@Test
public void test_AWS_SIG4_string_to_sign() throws IOException {
    String expected = "AWS4-HMAC-SHA256\n" +
            "20150830T123600Z\n" +
            "20150830/us-east-1/iam/aws4_request\n" +
            "f536975d06c0309214f805bb90ccff089219ecd68b2577efef23edd43b7e1a59";

    ZonedDateTime aDate = ZonedDateTime.parse("2015-08-30T12:36:00.000Z", DateTimeFormatter.ISO_DATE_TIME);
    Supplier<ZonedDateTime> clock = () -> aDate;
    AwsSigningInterceptor interceptor = new AwsSigningInterceptor(cfg, clock);


    String requestHash = "f536975d06c0309214f805bb90ccff089219ecd68b2577efef23edd43b7e1a59";
    String stringToSign = interceptor.createStringToSign(aDate, requestHash);

    assertThat(stringToSign).isEqualTo(expected);
}
 
开发者ID:esiqveland,项目名称:okhttp-awssigner,代码行数:18,代码来源:AwsSigningInterceptorTest.java

示例14: buildAuthnStatement

import java.time.ZonedDateTime; //导入依赖的package包/类
/**
 * Creates an authentication statement for the current request.
 *
 * @param assertion    the assertion
 * @param authnRequest the authn request
 * @param adaptor      the adaptor
 * @param service      the service
 * @return constructed authentication statement
 * @throws SamlException the saml exception
 */
private AuthnStatement buildAuthnStatement(final Assertion assertion, final AuthnRequest authnRequest,
                                           final SamlRegisteredServiceServiceProviderMetadataFacade adaptor,
                                           final SamlRegisteredService service) throws SamlException {

    final String authenticationMethod = this.authnContextClassRefBuilder.build(assertion, authnRequest, adaptor, service);
    final String id = '_' + String.valueOf(Math.abs(new SecureRandom().nextLong()));
    final AuthnStatement statement = newAuthnStatement(authenticationMethod, DateTimeUtils.zonedDateTimeOf(assertion.getAuthenticationDate()), id);
    if (assertion.getValidUntilDate() != null) {
        final ZonedDateTime dt = DateTimeUtils.zonedDateTimeOf(assertion.getValidUntilDate());
        statement.setSessionNotOnOrAfter(
                DateTimeUtils.dateTimeOf(dt.plusSeconds(casProperties.getAuthn().getSamlIdp().getResponse().getSkewAllowance())));
    }
    statement.setSubjectLocality(buildSubjectLocality(assertion, authnRequest, adaptor));
    return statement;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:SamlProfileSamlAuthNStatementBuilder.java

示例15: msgToInternalDate

import java.time.ZonedDateTime; //导入依赖的package包/类
public static ZonedDateTime msgToInternalDate(ImapMessage msg) {
  try {
    return msg.getInternalDate();
  } catch (UnfetchedFieldException ex) {
    throw Throwables.propagate(ex);
  }
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:8,代码来源:TestUtils.java


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