Search in sources :

Example 51 with Instant

use of java.time.Instant in project sonarqube by SonarSource.

the class DefaultIssue method truncateToSeconds.

@CheckForNull
private static Date truncateToSeconds(@Nullable Date d) {
    if (d == null) {
        return null;
    }
    Instant instant = d.toInstant();
    instant = instant.truncatedTo(ChronoUnit.SECONDS);
    return Date.from(instant);
}
Also used : Instant(java.time.Instant) CheckForNull(javax.annotation.CheckForNull)

Example 52 with Instant

use of java.time.Instant in project VocabHunter by VocabHunter.

the class SessionWordsToolImpl method timedCollect.

private static <T extends List<?>> T timedCollect(final String type, final Supplier<T> s, final Path file) {
    Instant start = Instant.now();
    T words = s.get();
    Instant end = Instant.now();
    Duration duration = Duration.between(start, end);
    String filename = FileNameTool.filename(file);
    LOG.info("Read filter file and found {} words marked as {} in {}ms ({})", words.size(), type, duration.toMillis(), filename);
    return words;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration)

Example 53 with Instant

use of java.time.Instant in project VocabHunter by VocabHunter.

the class FileStreamer method analyse.

public AnalysisResult analyse(final Path file) {
    Instant start = Instant.now();
    List<String> stream = lines(file);
    String filename = FileNameTool.filename(file);
    AnalysisResult result = analyser.analyse(stream, filename);
    int count = result.getOrderedUses().size();
    Instant end = Instant.now();
    Duration duration = Duration.between(start, end);
    LOG.info("Analysed text and found {} words in {}ms ({})", count, duration.toMillis(), filename);
    return result;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) AnalysisResult(io.github.vocabhunter.analysis.model.AnalysisResult)

Example 54 with Instant

use of java.time.Instant in project alchemy-test by SirWellington.

the class TestClassInjectors method inflateInstant.

private static void inflateInstant(FrameworkField field, Object target) throws IllegalArgumentException, IllegalAccessException {
    GenerateInstant annotation = field.getAnnotation(GenerateInstant.class);
    checkNotNull(annotation, "missing annotation");
    AlchemyGenerator<Instant> generator = GenerateInstant.Values.createGeneratorFor(annotation);
    Instant value = generator.get();
    inflate(field, target, value);
}
Also used : Instant(java.time.Instant)

Example 55 with Instant

use of java.time.Instant in project alchemy-test by SirWellington.

the class GenerateInstantTest method testValue.

@Test
public void testValue() {
    System.out.println("testValue");
    AlchemyGenerator<Instant> generator = GenerateInstant.Values.createGeneratorFor(annotation);
    assertThat(generator, notNullValue());
    Instant now = Instant.now();
    Instant result = generator.get();
    assertThat(result, notNullValue());
    switch(type) {
        case FUTURE:
            assertThat(result.isAfter(now), is(true));
            break;
        case PAST:
            assertThat(result.isBefore(now), is(true));
            break;
        case RANGE:
            assertThat(result.toEpochMilli(), greaterThanOrEqualTo(startTime.toEpochMilli()));
            assertThat(result.toEpochMilli(), lessThan(endTime.toEpochMilli()));
            break;
        case PRESENT:
            long marginOfErrorMillis = 50;
            assertThat(result.toEpochMilli(), greaterThanOrEqualTo(now.toEpochMilli() - marginOfErrorMillis));
            assertThat(result.toEpochMilli(), lessThanOrEqualTo(now.toEpochMilli() + marginOfErrorMillis));
            break;
    }
}
Also used : Instant(java.time.Instant) Test(org.junit.Test)

Aggregations

Instant (java.time.Instant)463 Test (org.testng.annotations.Test)143 Test (org.junit.Test)85 ZonedDateTime (java.time.ZonedDateTime)39 Duration (java.time.Duration)30 Clock (java.time.Clock)26 Lifetime (org.apache.cxf.sts.request.Lifetime)26 OffsetDateTime (java.time.OffsetDateTime)23 LocalDateTime (java.time.LocalDateTime)20 ArrayList (java.util.ArrayList)18 Element (org.w3c.dom.Element)18 LocalDate (java.time.LocalDate)17 IOException (java.io.IOException)14 Date (java.util.Date)14 LocalTime (java.time.LocalTime)12 DateTimeFormatter (java.time.format.DateTimeFormatter)12 STSException (org.apache.cxf.ws.security.sts.provider.STSException)12 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)12 Timestamp (java.sql.Timestamp)11 DefaultConditionsProvider (org.apache.cxf.sts.token.provider.DefaultConditionsProvider)10