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

The following examples show how to use java.time.LocalDateTime#atZone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@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);
    }
}
 
Example 2
@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);
    }
}
 
Example 3
/**
 * Gets the date.
 *
 * @return the date
 */
public ZonedDateTime getDate() {
    if (dateTimePicker == null) {
        return null;
    }
    LocalDateTime localDateTime = dateTimePicker.getDateTimeStrict();

    if (localDateTime == null) {
        return null;
    }

    // Populate zone offset
    String offsetId =
            String.format(
                    "%s%02d:%02d",
                    (offsetSign.getSelectedIndex() == 0 ? offsetStrings[0] : offsetStrings[1]),
                    hourSpinner.getValue(),
                    minuteSpinner.getValue());

    return localDateTime.atZone(ZoneOffset.of(offsetId));
}
 
Example 4
Source Project: yanagishima   File: DbUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void insertQueryHistory(TinyORM db, String datasource, String engine, String query, String user, String queryId, int linenumber) {
    try {
        LocalDateTime submitTimeLdt = LocalDateTime.parse(queryId.substring(0, "yyyyMMdd_HHmmss".length()), DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
        ZonedDateTime submitTimeZdt = submitTimeLdt.atZone(ZoneId.of("GMT", ZoneId.SHORT_IDS));
        String fetchResultTimeString = ZonedDateTime.now().toString();
        ZonedDateTime fetchResultTime = ZonedDateTime.parse(fetchResultTimeString);
        long elapsedTimeMillis = ChronoUnit.MILLIS.between(submitTimeZdt, fetchResultTime);

        Path resultFilePath = PathUtil.getResultFilePath(datasource, queryId, false);
        long resultFileSize = Files.size(resultFilePath);
        db.insert(Query.class)
                .value("datasource", datasource)
                .value("engine", engine)
                .value("query_id", queryId)
                .value("fetch_result_time_string", fetchResultTimeString)
                .value("query_string", query)
                .value("user", user)
                .value("status", Status.SUCCEED.name())
                .value("elapsed_time_millis", elapsedTimeMillis)
                .value("result_file_size", resultFileSize)
                .value("linenumber", linenumber)
                .execute();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
@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 6
@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
@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 8
@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 9
@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 10
@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 11
Source Project: j2objc   File: TCKOffsetPrinterParser.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("data_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 12
@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 13
@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
@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 15
@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 16
protected Date toDate(LocalDateTime localDateTime){
	ZonedDateTime atZone = localDateTime.atZone(ZoneId.systemDefault());
	return Date.from(atZone.toInstant());
}
 
Example 17
@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 18
@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
Source Project: elexis-3-core   File: TimeTool.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param localDate
 * @since 3.2
 */
public TimeTool(final LocalDateTime localDateTime){
	ZonedDateTime atZone = localDateTime.atZone(ZoneId.systemDefault());
	this.setTimeInMillis(atZone.toInstant().toEpochMilli());
	resolution = defaultResolution;
}
 
Example 20
@Test(dataProvider="toInstant")
public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), expectedEpSec);
}