Added TimeZone method to CronTimer

This commit is contained in:
Ziver Koc 2017-03-07 17:46:24 +01:00
parent bb038dce1f
commit a6c34fa7ba
2 changed files with 28 additions and 11 deletions

View file

@ -41,6 +41,8 @@ import java.util.*;
*/
public class CronTimer implements Iterator<Long>, Iterable<Long>{
private TimeZone timeZone;
private int[] minutes;
private int[] hours;
private int[] dayOfMonths;
@ -129,6 +131,13 @@ public class CronTimer implements Iterator<Long>, Iterable<Long>{
}
/**
* Set the TimeZone that should be used by the cron algorithm
*/
public void setTimeZone(TimeZone timeZone){
this.timeZone = timeZone;
}
@Override
public boolean hasNext() {
@ -252,9 +261,9 @@ public class CronTimer implements Iterator<Long>, Iterable<Long>{
}
protected Calendar getCalendar(long timestamp){
Calendar cal = Calendar.getInstance(
TimeZone.getTimeZone("UTC"),
new Locale("sv","SE"));
Calendar cal = Calendar.getInstance();
if (timeZone != null)
cal.setTimeZone(timeZone);
cal.setTimeInMillis(timestamp);
return cal;
}