Java Code Examples for java.time.LocalDateTime.atZone()

The following are Jave code examples for showing how to use atZone() of the java.time.LocalDateTime class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: sentry   File: Roster.java   Source Code and License Vote up 5 votes
private boolean isRecentJoin(UgcPlayer.Membership team) {
    if (team.getJoinedTeam() == null || !"true".equals(team.getActive())) {
        return false;
    }
    LocalDateTime date = LocalDateTime.parse(team.getJoinedTeam(), DateTimeFormatter.ofPattern(UGC_NEW_DATE_FORMAT, Locale.ENGLISH));
    ZonedDateTime join = date.atZone(UGC_ZONE_ID);
    return ZonedDateTime.now().minusHours(18).isBefore(join);
}
 
Example 2
Project: openjdk-jdk10   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendOffset(offsetPattern, noOffset);
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
Example 3
Project: openjdk-jdk10   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print_localized")
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
    OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
    ZonedDateTime zdt = ldt.atZone(offset);

    DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
                                                        .toFormatter();
    assertEquals(f.format(odt), expected);
    assertEquals(f.format(zdt), expected);
    assertEquals(f.parse(expected, ZoneOffset::from), offset);

    if (style == TextStyle.FULL) {
        f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);

        f = new DateTimeFormatterBuilder().appendPattern("OOOO")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }

    if (style == TextStyle.SHORT) {
        f = new DateTimeFormatterBuilder().appendPattern("O")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }
}
 
Example 4
Project: jdk8u-jdk   File: TCKZonedDateTime.java   Source Code and License Vote up 5 votes
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 5
Project: jdk8u-jdk   File: TCKZoneIdPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print(LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendZoneId();
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
Example 6
Project: jdk8u-jdk   File: TCKZoneIdPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print_pattern_VV(LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendPattern("VV");
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
Example 7
Project: jdk8u-jdk   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendOffset(offsetPattern, noOffset);
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
Example 8
Project: openjdk-jdk10   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    String pattern = null;
    String zero = null;
    if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
        pattern = "x";
        zero = "+00";
    } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
        pattern = "xx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) {
        pattern = "xxx";
        zero = "+00:00";
    } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) {
        pattern = "xxxx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
        pattern = "xxxxx";
        zero = "+00:00";
    }
    if (pattern != null) {
        ZonedDateTime zdt = ldt.atZone(zone);
        builder.appendPattern(pattern);
        String output = builder.toFormatter().format(zdt);
        assertEquals(output, (expected.equals("Z") ? zero : expected));
    }
}
 
Example 9
Project: jdk8u-jdk   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print")
public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    String pattern = null;
    String zero = null;
    if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
        pattern = "x";
        zero = "+00";
    } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
        pattern = "xx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) {
        pattern = "xxx";
        zero = "+00:00";
    } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) {
        pattern = "xxxx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
        pattern = "xxxxx";
        zero = "+00:00";
    }
    if (pattern != null) {
        ZonedDateTime zdt = ldt.atZone(zone);
        builder.appendPattern(pattern);
        String output = builder.toFormatter().format(zdt);
        assertEquals(output, (expected.equals("Z") ? zero : expected));
    }
}
 
Example 10
Project: jdk8u-jdk   File: TCKOffsetPrinterParser.java   Source Code and License Vote up 5 votes
@Test(dataProvider="print_localized")
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
    OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
    ZonedDateTime zdt = ldt.atZone(offset);

    DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
                                                        .toFormatter();
    assertEquals(f.format(odt), expected);
    assertEquals(f.format(zdt), expected);
    assertEquals(f.parse(expected, ZoneOffset::from), offset);

    if (style == TextStyle.FULL) {
        f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);

        f = new DateTimeFormatterBuilder().appendPattern("OOOO")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }

    if (style == TextStyle.SHORT) {
        f = new DateTimeFormatterBuilder().appendPattern("O")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }
}
 
Example 11
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 5 votes
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 12
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 5 votes
@Test(dataProvider="toInstant")
public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 13
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 5 votes
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
Example 14
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 4 votes
@Test(dataProvider="toInstant")
public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), expectedEpSec);
}
 
Example 15
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 4 votes
@Test(dataProvider="toInstant")
public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_0100);
    assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
}
 
Example 16
Project: openjdk-jdk10   File: TCKLocalDateTime.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void test_atZone_nullTimeZone() {
    LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
    t.atZone((ZoneId) null);
}
 
Example 17
Project: jdk8u-jdk   File: TCKZonedDateTime.java   Source Code and License Vote up 4 votes
@Test(dataProvider="toInstant")
public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), expectedEpSec);
}
 
Example 18
Project: openjdk-jdk10   File: TCKZonedDateTime.java   Source Code and License Vote up 4 votes
@Test(dataProvider="toInstant")
public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
}
 
Example 19
Project: jdk8u-jdk   File: TCKZonedDateTime.java   Source Code and License Vote up 4 votes
@Test(dataProvider="toInstant")
public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
}
 
Example 20
Project: jdk8u-jdk   File: TCKLocalDateTime.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void test_atZone_nullTimeZone() {
    LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
    t.atZone((ZoneId) null);
}