Java Code Examples for java.time.ZonedDateTime#getYear()
The following examples show how to use
java.time.ZonedDateTime#getYear() .
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 check out the related API usage on the sidebar.
Example 1
Source File: TCKZoneRules.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void test_Paris_getStandardOffset() { ZoneRules test = europeParis(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21)); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } zdt = zdt.plusMonths(6); } }
Example 2
Source File: SingleExecutionTime.java From cron-utils with Apache License 2.0 | 6 votes |
private Optional<TimeNode> generateDayCandidatesUsingDoY(final ZonedDateTime reference) { final int year = reference.getYear(); final int month = reference.getMonthValue(); final LocalDate date = LocalDate.of(year, 1, 1); final int lengthOfYear = date.lengthOfYear(); final List<Integer> candidates = createDayOfYearValueGeneratorInstance(daysOfYearCronField, year).generateCandidates(1, lengthOfYear); final int low = LocalDate.of(year, month, 1).getDayOfYear(); final int high = month == 12 ? LocalDate.of(year, 12, 31).getDayOfYear() + 1 : LocalDate.of(year, month + 1, 1).getDayOfYear(); final List<Integer> collectedCandidates = candidates.stream().filter(dayOfYear -> dayOfYear >= low && dayOfYear < high) .map(dayOfYear -> LocalDate.ofYearDay(reference.getYear(), dayOfYear).getDayOfMonth()) .collect(Collectors.toList()); return Optional.of(collectedCandidates).filter(not(List::isEmpty)).map(TimeNode::new); }
Example 3
Source File: TCKZoneRules.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void test_Paris_getStandardOffset() { ZoneRules test = europeParis(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21)); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } zdt = zdt.plusMonths(6); } }
Example 4
Source File: TCKZoneRules.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void test_Paris_getStandardOffset() { ZoneRules test = europeParis(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21)); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } zdt = zdt.plusMonths(6); } }
Example 5
Source File: TCKZoneRules.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example 6
Source File: TCKZoneRules.java From hottub with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example 7
Source File: TCKZoneRules.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 8
Source File: TCKZoneRules.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 9
Source File: TCKZoneRules.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 10
Source File: TCKZoneRules.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 11
Source File: TCKZoneRules.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example 12
Source File: TCKZoneRules.java From hottub with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 13
Source File: TCKZoneRules.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example 14
Source File: TCKZoneRules.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example 15
Source File: JavatimeTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) { ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault()); return zdt.getYear() == ts.getYear() + 1900 && zdt.getMonthValue() == ts.getMonth() + 1 && zdt.getDayOfMonth() == ts.getDate() && zdt.getHour() == ts.getHours() && zdt.getMinute() == ts.getMinutes() && zdt.getSecond() == ts.getSeconds() && zdt.getNano() == ts.getNanos(); }
Example 16
Source File: JavatimeTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) { ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault()); return zdt.getYear() == ts.getYear() + 1900 && zdt.getMonthValue() == ts.getMonth() + 1 && zdt.getDayOfMonth() == ts.getDate() && zdt.getHour() == ts.getHours() && zdt.getMinute() == ts.getMinutes() && zdt.getSecond() == ts.getSeconds() && zdt.getNano() == ts.getNanos(); }
Example 17
Source File: TCKZoneRules.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example 18
Source File: JavatimeTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) { ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault()); return zdt.getYear() == ts.getYear() + 1900 && zdt.getMonthValue() == ts.getMonth() + 1 && zdt.getDayOfMonth() == ts.getDate() && zdt.getHour() == ts.getHours() && zdt.getMinute() == ts.getMinutes() && zdt.getSecond() == ts.getSeconds() && zdt.getNano() == ts.getNanos(); }
Example 19
Source File: SingleExecutionTime.java From cron-utils with Apache License 2.0 | 5 votes |
/** * If date is not match, will return next closest match. * If date is match, will return this date. * * @param date - reference ZonedDateTime instance - never null; * @return ZonedDateTime instance, never null. Value obeys logic specified above. * @throws NoSuchValueException if there is no potential next year */ private ZonedDateTime nextClosestMatch(final ZonedDateTime date) throws NoSuchValueException { ExecutionTimeResult result = new ExecutionTimeResult(date, false); for (int i = 0; i < MAX_ITERATIONS; i++) { result = potentialNextClosestMatch(result.getTime()); if (result.isMatch()) { return result.getTime(); } if (result.getTime().getYear() - date.getYear() > 100) { throw new NoSuchValueException(); } } throw new NoSuchValueException(); }
Example 20
Source File: SyslogUtils.java From metron with Apache License 2.0 | 4 votes |
public static long parseTimestampToEpochMillis(String logTimestamp, Clock deviceClock) throws ParseException { ZoneId deviceTimeZone = deviceClock.getZone(); // RFC3164 (standard syslog timestamp; no year) // MMM ppd HH:mm:ss // Oct 9 2015 13:42:11 if (Pattern.matches("[A-Z][a-z]{2}(?:(?:\\s{2}\\d)|(?:\\s\\d{2}))\\s\\d{2}:\\d{2}:\\d{2}", logTimestamp)) { DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("MMM ppd HH:mm:ss").withZone(deviceTimeZone); TemporalAccessor inputDate = inputFormat.parse(logTimestamp); int inputMonth = inputDate.get(MONTH_OF_YEAR); int inputDay = inputDate.get(DAY_OF_MONTH); int inputHour = inputDate.get(HOUR_OF_DAY); int inputMinute = inputDate.get(MINUTE_OF_HOUR); int inputSecond = inputDate.get(SECOND_OF_MINUTE); ZonedDateTime currentDate = ZonedDateTime.now(deviceClock); int currentYear = currentDate.getYear(); ZonedDateTime inputDateWithCurrentYear = ZonedDateTime.of(currentYear, inputMonth, inputDay, inputHour, inputMinute, inputSecond, 0, deviceTimeZone); // Since no year is provided, one must be derived. Assume that any date more than 4 days in the future is in the past. if(inputDateWithCurrentYear.isAfter(currentDate.plusDays(4L))) { ZonedDateTime inputDateWithPreviousYear = ZonedDateTime.of(currentYear-1, inputMonth, inputDay, inputHour, inputMinute, inputSecond, 0, deviceTimeZone); return inputDateWithPreviousYear.toInstant().toEpochMilli(); } else return inputDateWithCurrentYear.toInstant().toEpochMilli(); } // CISCO timestamp (standard syslog + year) // MMM dd yyyy HH:mm:ss // Oct 09 2015 13:42:11 else if (Pattern.matches("[A-Z][a-z]{2}\\s\\d{2}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}", logTimestamp)) return convertToEpochMillis(logTimestamp, DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm:ss").withZone(deviceTimeZone)); // RFC5424 (ISO timestamp) // 2015-10-09T13:42:11.52Z or 2015-10-09T13:42:11.52-04:00 else if (Pattern.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})", logTimestamp)) return convertToEpochMillis(logTimestamp, DateTimeFormatter.ISO_OFFSET_DATE_TIME); else throw new ParseException(String.format("Unsupported date format: '%s'", logTimestamp)); }