Merge pull request #2824 from daniel-beck/JENKINS-43228

[FIX JENKINS-43228] Consider time zone for cron validation
This commit is contained in:
Daniel Beck authored and GitHub committed 2017-04-08 12:24:01 +02:00
commit 98ad8e4d73
3 files changed
+38 -2

No files matched your search

@@ -24,9 +24,14 @@
package hudson.triggers;
import antlr.ANTLRException;
import hudson.scheduler.CronTabList;
import hudson.scheduler.Hash;
import org.junit.Assert;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import java.util.TimeZone;
/**
* @author Kanstantsin Shautsou
*/
@@ -36,4 +41,22 @@ public class TimerTriggerTest {
public void testNoNPE() throws ANTLRException {
new TimerTrigger("").run();
}
@Issue("JENKINS-43328")
@Test
public void testTimeZoneOffset() throws Exception {
TimeZone defaultTz = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
try {
String cron = "TZ=GMT\nH 0 * * *";
CronTabList ctl = CronTabList.create(cron, Hash.from("whatever"));
Assert.assertEquals("previous occurrence is in GMT", "GMT", ctl.previous().getTimeZone().getID());
cron = "TZ=America/Denver\nH 0 * * *";
ctl = CronTabList.create(cron, Hash.from("whatever"));
Assert.assertEquals("next occurrence is in America/Denver", "America/Denver", ctl.next().getTimeZone().getID());
} finally {
TimeZone.setDefault(defaultTz);
}
}
}