public void TestCronTriggerTimeZone_TimeZoneShouldChangeWhenChanged() { string tzStr = "FLE Standard Time"; if (TimeZone.Local.Id == tzStr) { tzStr = "GMT Standard Time"; } TimeZone tz = TimeZone.FindSystemTimeZoneById(tzStr); CronTrigger trigger = new CronTrigger(); trigger.Name = "Quartz-579"; trigger.Group = SchedulerConstants.DefaultGroup; trigger.TimeZone = tz; trigger.CronExpressionString = "0 0 12 * * ?"; Assert.AreEqual(tz, trigger.TimeZone, "TimeZone was changed"); }
public void TestTimeZone() { TimeZone GMT = TimeZone.FindSystemTimeZoneById("GMT Standard Time"); TimeZone EST = TimeZone.FindSystemTimeZoneById("Eastern Standard Time"); // Calendar startTime = Calendar.getInstance(EST); var startTime = new DateTime(2006, 3, 7, 7, 0, 0, DateTimeKind.Utc); startTime = TimeZone.ConvertTimeFromUtc(startTime, EST); // Same timezone { NthIncludedDayTrigger t = new NthIncludedDayTrigger("name", "group"); t.IntervalType = NthIncludedDayTrigger.IntervalTypeWeekly; t.N = 3; t.StartTimeUtc = startTime.ToUniversalTime(); t.FireAtTime = "8:00"; t.TimeZone = EST; DateTime?firstTime = t.ComputeFirstFireTimeUtc(null); // Calendar firstTimeCal = Calendar.getInstance(EST); DateTime firstTimeCal = new DateTime(startTime.Year, startTime.Month, startTime.Day, 8, 0, 0, 0, DateTimeKind.Utc); firstTimeCal = TimeZone.ConvertTimeFromUtc(firstTimeCal, EST); //roll start date forward to first day of the next week while (firstTimeCal.DayOfWeek != t.TriggerCalendarFirstDayOfWeek) { firstTimeCal = firstTimeCal.AddDays(-1); } //first day of the week counts as one. add two more to get N=3. firstTimeCal = firstTimeCal.AddDays(2); //if we went back too far, shift forward a week. if (firstTimeCal < startTime) { firstTimeCal = firstTimeCal.AddDays(7); } Assert.AreEqual(firstTime, firstTimeCal); } // Different timezones { NthIncludedDayTrigger t = new NthIncludedDayTrigger("name", "group"); t.IntervalType = NthIncludedDayTrigger.IntervalTypeWeekly; t.N = 3; t.StartTimeUtc = startTime; t.FireAtTime = "8:00"; t.TimeZone = GMT; DateTime?firstTime = t.ComputeFirstFireTimeUtc(null); // Calendar firstTimeCal = Calendar.getInstance(EST); DateTime firstTimeCal = new DateTime(startTime.Year, startTime.Month, startTime.Day, 8, 0, 0, 0); //EST is GMT-5 firstTimeCal.AddHours(-5); //roll start date forward to first day of the next week while (firstTimeCal.DayOfWeek != t.TriggerCalendarFirstDayOfWeek) { firstTimeCal = firstTimeCal.AddDays(-1); } //first day of the week counts as one. add two more to get N=3. firstTimeCal = firstTimeCal.AddDays(2); //if we went back too far, shift forward a week. if (firstTimeCal < startTime) { firstTimeCal = firstTimeCal.AddDays(7); } Assert.AreEqual(firstTime, firstTimeCal); } }