Skip to content

Commit

Permalink
[FIX JENKINS-43228] Consider time zone for cron validation
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Mar 30, 2017
1 parent a3b9398 commit 43d612f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/scheduler/CronTab.java
Expand Up @@ -532,4 +532,17 @@ private String toString(String key, long bit) {
return null;
}
}

/**
* Returns the configured time zone, or null if none is configured
*
* @return the configured time zone, or null if none is configured
* @since TODO
*/
@CheckForNull public TimeZone getTimeZone() {
if (this.specTimezone == null) {
return null;
}
return TimeZone.getTimeZone(this.specTimezone);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/scheduler/CronTabList.java
Expand Up @@ -131,7 +131,7 @@ public static CronTabList create(@Nonnull String format, Hash hash) throws ANTLR
public @CheckForNull Calendar previous() {
Calendar nearest = null;
for (CronTab tab : tabs) {
Calendar scheduled = tab.floor(Calendar.getInstance());
Calendar scheduled = tab.floor(tab.getTimeZone() == null ? Calendar.getInstance() : Calendar.getInstance(tab.getTimeZone()));
if (nearest == null || nearest.before(scheduled)) {
nearest = scheduled;
}
Expand All @@ -143,7 +143,7 @@ public static CronTabList create(@Nonnull String format, Hash hash) throws ANTLR
public @CheckForNull Calendar next() {
Calendar nearest = null;
for (CronTab tab : tabs) {
Calendar scheduled = tab.ceil(Calendar.getInstance());
Calendar scheduled = tab.ceil(tab.getTimeZone() == null ? Calendar.getInstance() : Calendar.getInstance(tab.getTimeZone()));
if (nearest == null || nearest.after(scheduled)) {
nearest = scheduled;
}
Expand Down

0 comments on commit 43d612f

Please sign in to comment.