Java Code Examples for org.apache.logging.log4j.core.util.CronExpression#setTimeZone()

The following examples show how to use org.apache.logging.log4j.core.util.CronExpression#setTimeZone() . 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: CronTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserTimeZoneVsPodTimeZone() throws ParseException {
    // the "user" writes the cron expression in his timezone
    // every second, every minute, hour 14 to 15 every day --> from 14:00 to 15:59
    CronExpression cronExpression = new CronExpression("* * 14-15 * * ?");

    // the pod is running on a "Pacific/Easter" timezone data center, so cron expression needs the right timezone for evaluation
    cronExpression.setTimeZone(TimeZone.getTimeZone(ZoneId.of("Europe/Rome")));

    // it's really 08:00 in "Pacific/Easter" but 14:00 for "user"
    Date d = Date.from(LocalDateTime.of(2018, 11, 26, 8, 00, 0).atZone(ZoneId.of("Pacific/Easter")).toInstant());
    assertThat(cronExpression.isSatisfiedBy(d), is(true));
}
 
Example 2
Source File: CronTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testUtcTimeZone() throws ParseException {
    // the "user" writes the cron expression in UTC timezone, but let's imagine he is in Europe/Rome timezone
    // every second, every minute, hour 15 to 16 every day --> from 15:00 to 15:59
    CronExpression cronExpression = new CronExpression("* * 14-15 * * ?");

    // the pod is running on a "Pacific/Easter" timezone data center, so cron expression needs the right timezone for evaluation
    cronExpression.setTimeZone(TimeZone.getTimeZone("GMT"));

    // it's really 09:00 in "Pacific/Easter" but 15:00 for "user" so 14:00 in UTC
    Date d = Date.from(LocalDateTime.of(2018, 11, 26, 9, 00, 0).atZone(ZoneId.of("Pacific/Easter")).toInstant());
    assertThat(cronExpression.isSatisfiedBy(d), is(true));
}