Search in sources :

Example 66 with ZoneId

use of java.time.ZoneId in project assertj-core by joel-costigliola.

the class ZonedDateTimeAssert_isNotIn_Test method isNotIn_should_compare_datetimes_in_actual_timezone.

@Test
public void isNotIn_should_compare_datetimes_in_actual_timezone() {
    ZonedDateTime utcDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, ZoneOffset.UTC);
    ZoneId cestTimeZone = ZoneId.of("Europe/Berlin");
    ZonedDateTime cestDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, cestTimeZone);
    // cestDateTime and utcDateTime are not equals in same timezone
    assertThat(utcDateTime).isNotIn(cestDateTime, ZonedDateTime.now());
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 67 with ZoneId

use of java.time.ZoneId in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesHostNameAndTimestamp.

@Test
void writesHostNameAndTimestamp(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("test", () -> {
    });
    LocalDateTime now = LocalDateTime.parse("2016-01-28T14:02:59.123");
    ZoneId zone = ZoneId.systemDefault();
    executeTests(engine, tempDirectory, Clock.fixed(ZonedDateTime.of(now, zone).toInstant(), zone));
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite", "hostname=\"" + InetAddress.getLocalHost().getHostName() + "\"", "timestamp=\"2016-01-28T14:02:59\"", "<testcase", "</testsuite>");
// @formatter:on
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 68 with ZoneId

use of java.time.ZoneId in project spf4j by zolyfarkas.

the class QuantizedXYZDatasetImpl method createXTickUnits.

public TickUnits createXTickUnits() {
    TickUnits tux = new TickUnits();
    if (data.length == 0) {
        return tux;
    }
    ZoneId systemDefault = ZoneId.systemDefault();
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HH:mm:ss").withZone(systemDefault);
    final DateTimeFormatter shortFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HH").withZone(systemDefault);
    final DateTimeFormatter mediumFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HH:mm").withZone(systemDefault);
    final long[] timestamps = new long[data[0].length];
    long time = startTimeMillis;
    for (int i = 0; i < timestamps.length; i++) {
        timestamps[i] = time;
        time += stepMillis;
    }
    // base
    tux.add(new TimestampTickUnitImpl(1, timestamps, stepMillis, formatter));
    long nr = 5000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, formatter));
    }
    nr = 15000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, formatter));
    }
    // minute
    nr = 60000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, mediumFormat));
    }
    // 15 minute
    nr = 900000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, mediumFormat));
    }
    // hour
    nr = 3600000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, shortFormat));
    }
    // 6 hour
    nr = 21600000L / stepMillis;
    if (nr > 1) {
        tux.add(new TimestampTickUnitImpl(nr, timestamps, stepMillis, shortFormat));
    }
    return tux;
}
Also used : TickUnits(org.jfree.chart.axis.TickUnits) ZoneId(java.time.ZoneId) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 69 with ZoneId

use of java.time.ZoneId in project uhgroupings by uhawaii-system-its-ti-iam.

the class Dates method toLocalDate.

public static LocalDate toLocalDate(Date date) {
    Date result = new Date();
    try {
        if (date instanceof java.sql.Date) {
            result.setTime(date.getTime());
        }
        Instant instant = date.toInstant();
        ZoneId zoneId = zoneId();
        ZonedDateTime zoneDateTime = instant.atZone(zoneId);
        return zoneDateTime.toLocalDate();
    } catch (ClassCastException e) {
        System.err.println(e.getMessage());
    }
    return null;
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 70 with ZoneId

use of java.time.ZoneId in project dbflute-core by dbflute.

the class DfTypeUtil method doParseLocalDateTimeAsTimestamp.

protected static Timestamp doParseLocalDateTimeAsTimestamp(LocalDateTime localDateTime, TimeZone timeZone) {
    if (localDateTime == null) {
        return null;
    }
    final TimeZone realZone = chooseRealZone(timeZone);
    final ZoneId zoneId = timeZone != null ? realZone.toZoneId() : ZoneId.systemDefault();
    return Timestamp.from(localDateTime.toInstant(zoneId.getRules().getOffset(localDateTime)));
}
Also used : TimeZone(java.util.TimeZone) ZoneId(java.time.ZoneId)

Aggregations

ZoneId (java.time.ZoneId)420 Test (org.junit.Test)137 ZonedDateTime (java.time.ZonedDateTime)108 LocalDateTime (java.time.LocalDateTime)69 LocalDate (java.time.LocalDate)55 Instant (java.time.Instant)49 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)37 DateTimeFormatter (java.time.format.DateTimeFormatter)32 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)21 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)12 Duration (java.time.Duration)12 OffsetDateTime (java.time.OffsetDateTime)11