Example usage for java.time Duration ofDays

List of usage examples for java.time Duration ofDays

Introduction

In this page you can find the example usage for java.time Duration ofDays.

Prototype

public static Duration ofDays(long days) 

Source Link

Document

Obtains a Duration representing a number of standard 24 hour days.

Usage

From source file:Main.java

public static void main(String[] args) {

    // same time in millis
    Instant now = Instant.ofEpochMilli(1262347200000l);

    // native plusSeconds() method to add 10 seconds
    Instant nowPlusTenSeconds = now.plusSeconds(10);

    // no native support for units like days.
    Instant nowPlusTwoDays = now.plus(2, ChronoUnit.DAYS);
    Instant nowMinusTwoDays = now.minus(Duration.ofDays(2));

    System.out.println(nowPlusTenSeconds);
    System.out.println(nowPlusTwoDays);
    System.out.println(nowMinusTwoDays);
}

From source file:com.teradata.benchto.driver.BenchmarkPropertiesTest.java

@Test
public void parseTimeLimit() {
    assertThat(benchmarkPropertiesWithTimeLimit(null).getTimeLimit()).isEmpty();
    assertThat(benchmarkPropertiesWithTimeLimit("P1D").getTimeLimit().get()).isEqualTo(Duration.ofDays(1));
}

From source file:com.microsoft.azure.servicebus.samples.managingentity.ManagingEntity.java

private void createQueue(String queueName) {

    // Name of the queue is a required parameter.
    // All other queue properties have defaults, and hence optional.
    QueueDescription queueDescription = new QueueDescription(queueName);

    // The duration of a peek lock; that is, the amount of time that a message is locked from other receivers.
    queueDescription.setLockDuration(Duration.ofSeconds(45));

    // Size of the Queue. For non-partitioned entity, this would be the size of the queue.
    // For partitioned entity, this would be the size of each partition.
    queueDescription.setMaxSizeInMB(2048);

    // This value indicates if the queue requires guard against duplicate messages.
    // Find out more in DuplicateDetection sample.
    queueDescription.setRequiresDuplicateDetection(false);

    // Since RequiresDuplicateDetection is false, the following need not be specified and will be ignored.
    // queueDescription.setDuplicationDetectionHistoryTimeWindow(Duration.ofMinutes(2));

    // This indicates whether the queue supports the concept of session.
    queueDescription.setRequiresSession(false);

    // The default time to live value for the messages.
    // Find out more in "TimeToLive" sample.
    queueDescription.setDefaultMessageTimeToLive(Duration.ofDays(7));

    // Duration of idle interval after which the queue is automatically deleted.
    queueDescription.setAutoDeleteOnIdle(ManagementClientConstants.MAX_DURATION);

    // Decides whether an expired message due to TTL should be dead-lettered.
    // Find out more in "TimeToLive" sample.
    queueDescription.setEnableDeadLetteringOnMessageExpiration(false);

    // The maximum delivery count of a message before it is dead-lettered.
    // Find out more in "DeadletterQueue" sample.
    queueDescription.setMaxDeliveryCount(8);

    // Creating only one partition.
    // Find out more in PartitionedQueues sample.
    queueDescription.setEnablePartitioning(false);

    try {/*from w  ww .  j a va2  s . c  o  m*/
        this.managementClient.createQueueAsync(queueDescription).get();
    } catch (InterruptedException e) {
        System.out.println("Encountered exception while creating Queue - \n" + e.toString());
    } catch (ExecutionException e) {
        if (e.getCause() instanceof ServiceBusException) {
            System.out.println("Encountered ServiceBusException while creating Queue - \n" + e.toString());
        }
        System.out.println("Encountered exception while creating Queue - \n" + e.toString());
    }
}

From source file:me.carbou.mathieu.tictactoe.di.ServiceBindings.java

@Override
protected void configure() {
    bind(Clock.class).toInstance(Clock.systemUTC()); // enabled override the whole system clock

    // bind security service and the way of getting a connected UserContext
    bind(SecurityService.class).to(DefaultSecurityService.class);
    bind(AccountRepository.class).to(MongoAccountRepository.class);
    bind(CredentialsMatcher.class).toInstance(new HashedCredentialsMatcher(3));
    bind(SessionConfigurations.class).toInstance(new SessionConfigurations().add("tic-tac-toe",
            new SessionConfiguration().setCheckOrigin(false).setCheckUserAgent(false)
                    .setMaxAge((int) Duration.ofDays(30).getSeconds())
                    .setCookieName(Env.isProduction() ? "id" : "id-" + Env.NAME).setCookiePath("/")
                    .setCookieDomain(Env.DOMAIN)));
}

From source file:com.netflix.spinnaker.igor.docker.DockerRegistryCacheV2KeysMigration.java

private void migrateBatch(List<DockerRegistryV1Key> oldKeys) {
    int expireSeconds = (int) Duration.ofDays(properties.getRedis().getDockerV1KeyMigration().getTtlDays())
            .getSeconds();/* w  w w .j  av a2 s.  co m*/
    redis.withCommandsClient(c -> {
        for (DockerRegistryV1Key oldKey : oldKeys) {
            String newKey = keyFactory.convert(oldKey).toString();
            if (c.exists(newKey)) {
                // Nothing to do here, just move on with life
                continue;
            }

            // Copy contents of v1 to v2
            String v1Key = oldKey.toString();
            Map<String, String> value = c.hgetAll(v1Key);
            c.hmset(newKey, value);
            c.expire(v1Key, expireSeconds);
        }
    });
}

From source file:com.realdolmen.rdfleet.soap.MileageUpdateLogicTest.java

private Car createCar() {
    Car car = new Car();
    car.setFunctionalLevel(2);/*  w ww.j a va  2s .c o m*/
    car.setMake("Audi");
    car.setModel("A1");
    car.setAmountDowngrade(BigDecimal.valueOf(2315.25));
    car.setFuelType(FuelType.DIESEL);
    car.setAmountUpgrade(BigDecimal.valueOf(0).setScale(2, RoundingMode.HALF_UP));
    car.setListPrice(BigDecimal.valueOf(25343.22));
    car.setTyreType(TyreType.ALUMINIUM);
    car.setTimeOfDeliveryInDays(Duration.ofDays(150));
    return car;
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService_determineRelevantGoalsTest.java

@Test
public void determineRelevantGoals_appActivityBeforeGoalStart_emptySet() {
    Set<GoalDto> relevantGoals = AnalysisEngineService
            .determineRelevantGoals(makeAppPayload(makeCategorySet(socialGoal), Duration.ofDays(3)));
    assertThat(relevantGoals, empty());/*from www.j ava 2s.  co m*/
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService_determineRelevantGoalsTest.java

@Test
public void determineRelevantGoals_appActivityOnGoalWithHistory_oneGoalReturned() {
    Set<GoalDto> relevantGoals = AnalysisEngineService
            .determineRelevantGoals(makeAppPayload(makeCategorySet(shoppingGoal), Duration.ofDays(1)));
    assertThat(relevantGoals, containsInAnyOrder(GoalDto.createInstance(shoppingGoal)));
}

From source file:com.teradata.benchto.driver.loader.BenchmarkLoader.java

private List<Benchmark> loadBenchmarks(String sequenceId, Path benchmarkFile) {
    try {//from  www  .  j av a2 s .c  om
        String content = new String(readAllBytes(benchmarkFile), UTF_8);
        Map<String, Object> yaml = loadYamlFromString(content);

        checkArgument(yaml.containsKey(DATA_SOURCE_KEY), "Mandatory variable %s not present in file %s",
                DATA_SOURCE_KEY, benchmarkFile);
        checkArgument(yaml.containsKey(QUERY_NAMES_KEY), "Mandatory variable %s not present in file %s",
                QUERY_NAMES_KEY, benchmarkFile);

        List<BenchmarkDescriptor> benchmarkDescriptors = createBenchmarkDescriptors(yaml);

        List<Benchmark> benchmarks = newArrayListWithCapacity(benchmarkDescriptors.size());
        for (BenchmarkDescriptor benchmarkDescriptor : benchmarkDescriptors) {
            String benchmarkName = benchmarkName(benchmarkFile);
            List<Query> queries = queryLoader.loadFromFiles(benchmarkDescriptor.getQueryNames());

            Benchmark benchmark = new BenchmarkBuilder(benchmarkName, sequenceId, queries)
                    .withDataSource(benchmarkDescriptor.getDataSource())
                    .withEnvironment(properties.getEnvironmentName())
                    .withRuns(benchmarkDescriptor.getRuns().orElse(DEFAULT_RUNS))
                    .withPrewarmRuns(benchmarkDescriptor.getPrewarmRepeats().orElse(DEFAULT_PREWARM_RUNS))
                    .withConcurrency(benchmarkDescriptor.getConcurrency().orElse(DEFAULT_CONCURRENCY))
                    .withFrequency(
                            benchmarkDescriptor.getFrequency().map(frequency -> Duration.ofDays(frequency)))
                    .withBeforeBenchmarkMacros(benchmarkDescriptor.getBeforeBenchmarkMacros())
                    .withAfterBenchmarkMacros(benchmarkDescriptor.getAfterBenchmarkMacros())
                    .withBeforeExecutionMacros(benchmarkDescriptor.getBeforeExecutionMacros())
                    .withAfterExecutionMacros(benchmarkDescriptor.getAfterExecutionMacros())
                    .withVariables(benchmarkDescriptor.getVariables()).build();
            benchmarks.add(benchmark);
        }

        return benchmarks;
    } catch (IOException e) {
        throw new BenchmarkExecutionException("Could not load benchmark: " + benchmarkFile, e);
    }
}

From source file:com.github.aptd.simulation.elements.IBaseElement.java

@IAgentActionFilter
@IAgentActionName(name = "simtime/max")
private ZonedDateTime maxTime() {
    return ZonedDateTime.ofInstant(Instant.now().plus(Duration.ofDays(9999)), m_timezone);
}