/// <summary> /// Determines whether the date and (optionally) time of the given Calendar /// instance falls on a scheduled fire-time of this trigger. /// <para> /// Note that the value returned is NOT validated against the related /// ICalendar (if any). /// </para> /// </summary> /// <param name="test">The date to compare</param> /// <param name="dayOnly">If set to true, the method will only determine if the /// trigger will fire during the day represented by the given Calendar /// (hours, minutes and seconds will be ignored).</param> /// <returns></returns> public bool WillFireOn(DateTimeOffset test, bool dayOnly) { test = new DateTime(test.Year, test.Month, test.Day, test.Hour, test.Minute, test.Second); if (dayOnly) { test = new DateTime(test.Year, test.Month, test.Day, 0, 0, 0); } DateTimeOffset?fta = GetFireTimeAfter(test.AddMilliseconds(-1 * 1000)); if (fta == null) { return(false); } DateTimeOffset p = TimeZoneUtil.ConvertTime(fta.Value, TimeZone); if (dayOnly) { return(p.Year == test.Year && p.Month == test.Month && p.Day == test.Day); } while (fta.Value < test) { fta = GetFireTimeAfter(fta); } if (fta.Equals(test)) { return(true); } return(false); }
public void TestCrossingDSTBoundary() { TimeZoneInfo cetTimeZone = TimeZoneUtil.FindTimeZoneById("Central European Standard Time"); DateTimeOffset startCalendar = TimeZoneUtil.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone); CalendarIntervalTriggerImpl dailyTrigger = new CalendarIntervalTriggerImpl(); dailyTrigger.StartTimeUtc = startCalendar; dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day; dailyTrigger.RepeatInterval = 1; dailyTrigger.TimeZone = cetTimeZone; dailyTrigger.PreserveHourOfDayAcrossDaylightSavings = true; var fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); //none of these should match the previous fire time. for (int i = 1; i < fireTimes.Count; i++) { var previousFire = fireTimes[i - 1]; var currentFire = fireTimes[i]; Assert.AreNotEqual(previousFire, currentFire); } }
public void TestMovingAcrossDSTAvoidsInfiniteLoop() { TimeZoneInfo est = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time"); DateTimeOffset startDate = new DateTimeOffset(1990, 10, 27, 0, 0, 0, TimeSpan.FromHours(-4)); CalendarIntervalTriggerImpl t = new CalendarIntervalTriggerImpl(); t.RepeatInterval = 1; t.RepeatIntervalUnit = IntervalUnit.Day; t.PreserveHourOfDayAcrossDaylightSavings = true; t.SkipDayIfHourDoesNotExist = false; t.StartTimeUtc = startDate; t.TimeZone = est; var fireTimes = TriggerUtils.ComputeFireTimes(t, null, 10); var firstFire = fireTimes[0]; var secondFire = fireTimes[1]; Assert.AreNotEqual(firstFire, secondFire); //try to trigger a shift in month startDate = new DateTimeOffset(2012, 6, 1, 0, 0, 0, TimeSpan.FromHours(-4)); t = new CalendarIntervalTriggerImpl(); t.RepeatInterval = 1; t.RepeatIntervalUnit = IntervalUnit.Month; t.PreserveHourOfDayAcrossDaylightSavings = true; t.SkipDayIfHourDoesNotExist = false; t.StartTimeUtc = startDate; t.TimeZone = est; fireTimes = TriggerUtils.ComputeFireTimes(t, null, 10); Assert.AreNotEqual(firstFire, secondFire); }
ITrigger CreateTrigger(RecurringSchedule schedule, IJobDetail jobDetail, TriggerKey triggerKey) { var tz = TimeZoneInfo.Local; if (!string.IsNullOrWhiteSpace(schedule.TimeZoneId) && schedule.TimeZoneId != tz.Id) { tz = TimeZoneUtil.FindTimeZoneById(schedule.TimeZoneId); } var triggerBuilder = TriggerBuilder.Create() .ForJob(jobDetail) .WithIdentity(triggerKey) .StartAt(schedule.StartTime) .WithDescription(schedule.Description) .WithCronSchedule(schedule.CronExpression, x => { x.InTimeZone(tz); switch (schedule.MisfirePolicy) { case MissedEventPolicy.Skip: x.WithMisfireHandlingInstructionDoNothing(); break; case MissedEventPolicy.Send: x.WithMisfireHandlingInstructionFireAndProceed(); break; } }); if (schedule.EndTime.HasValue) { triggerBuilder.EndAt(schedule.EndTime); } return(triggerBuilder.Build()); }
/// <summary> /// Determine the next time (in milliseconds) that is 'included' by the /// Calendar after the given time. Return the original value if timeStamp is /// included. Return DateTime.MinValue if all days are excluded. /// <para> /// Note that this Calendar is only has full-day precision. /// </para> /// </summary> public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc) { if (excludeAll) { return(DateTimeOffset.MinValue); } // Call base calendar implementation first DateTimeOffset baseTime = base.GetNextIncludedTimeUtc(timeUtc); if ((baseTime != DateTimeOffset.MinValue) && (baseTime > timeUtc)) { timeUtc = baseTime; } //apply the timezone timeUtc = TimeZoneUtil.ConvertTime(timeUtc, this.TimeZone); // Get timestamp for 00:00:00, in the correct timezone offset DateTimeOffset newTimeStamp = new DateTimeOffset(timeUtc.Date, timeUtc.Offset); int day = newTimeStamp.Day; if (!IsDayExcluded(day)) { return(newTimeStamp); } // return the original value with the correct offset time. while (IsDayExcluded(day)) { newTimeStamp = newTimeStamp.AddDays(1); day = newTimeStamp.Day; } return(newTimeStamp); }
/// <summary> /// Determine whether the given time is 'included' by the /// Calendar. /// </summary> /// <param name="timeUtc"></param> /// <returns></returns> public override bool IsTimeIncluded(DateTimeOffset timeUtc) { if (CalendarBase != null && CalendarBase.IsTimeIncluded(timeUtc) == false) { return(false); } //Before we start, apply the correct timezone offsets. timeUtc = TimeZoneUtil.ConvertTime(timeUtc, TimeZone); DateTimeOffset startOfDayInMillis = GetStartOfDay(timeUtc); DateTimeOffset endOfDayInMillis = GetEndOfDay(timeUtc); DateTimeOffset timeRangeStartingTimeInMillis = GetTimeRangeStartingTimeUtc(timeUtc); DateTimeOffset timeRangeEndingTimeInMillis = GetTimeRangeEndingTimeUtc(timeUtc); if (!InvertTimeRange) { if (timeUtc > startOfDayInMillis && timeUtc < timeRangeStartingTimeInMillis || timeUtc > timeRangeEndingTimeInMillis && timeUtc < endOfDayInMillis) { return(true); } return(false); } if (timeUtc >= timeRangeStartingTimeInMillis && timeUtc <= timeRangeEndingTimeInMillis) { return(true); } return(false); }
protected DateTimeOffset GetLocalTime(DateTimeOffset dateTimeOffset) { return(TimeZoneUtil.ConvertTime(dateTimeOffset, _timeZoneInfo)); }
protected override TriggerPropertyBundle GetTriggerPropertyBundle(SimplePropertiesTriggerProperties props) { int repeatCount = (int)props.Long1; int interval = props.Int1; string intervalUnitStr = props.String1; string daysOfWeekStr = props.String2; string timeOfDayStr = props.String3; IntervalUnit intervalUnit = (IntervalUnit)Enum.Parse(typeof(IntervalUnit), intervalUnitStr, true); DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder.Create() .WithInterval(interval, intervalUnit) .WithRepeatCount(repeatCount); if (!string.IsNullOrEmpty(props.TimeZoneId)) { scheduleBuilder.InTimeZone(TimeZoneUtil.FindTimeZoneById(props.TimeZoneId)); } if (daysOfWeekStr != null) { var daysOfWeek = new HashSet <DayOfWeek>(); string[] nums = daysOfWeekStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (nums.Length > 0) { foreach (string num in nums) { daysOfWeek.Add((DayOfWeek)int.Parse(num)); } scheduleBuilder.OnDaysOfTheWeek(daysOfWeek); } } else { scheduleBuilder.OnDaysOfTheWeek(DailyTimeIntervalScheduleBuilder.AllDaysOfTheWeek); } if (timeOfDayStr != null) { string[] nums = timeOfDayStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); TimeOfDay startTimeOfDay; if (nums.Length >= 3) { int hour = int.Parse(nums[0]); int min = int.Parse(nums[1]); int sec = int.Parse(nums[2]); startTimeOfDay = new TimeOfDay(hour, min, sec); } else { startTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0); } scheduleBuilder.StartingDailyAt(startTimeOfDay); TimeOfDay endTimeOfDay; if (nums.Length >= 6) { int hour = int.Parse(nums[3]); int min = int.Parse(nums[4]); int sec = int.Parse(nums[5]); endTimeOfDay = new TimeOfDay(hour, min, sec); } else { endTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59); } scheduleBuilder.EndingDailyAt(endTimeOfDay); } else { scheduleBuilder.StartingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0)); scheduleBuilder.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59)); } int timesTriggered = props.Int2; string[] statePropertyNames = { "timesTriggered" }; object[] statePropertyValues = { timesTriggered }; return(new TriggerPropertyBundle(scheduleBuilder, statePropertyNames, statePropertyValues)); }
protected virtual void ProcessInternal(string xml) { PrepForProcessing(); ValidateXml(xml); MaybeThrowValidationException(); // deserialize as object model XmlSerializer xs = new XmlSerializer(typeof(QuartzXmlConfiguration20)); QuartzXmlConfiguration20 data = (QuartzXmlConfiguration20)xs.Deserialize(new StringReader(xml)); if (data == null) { throw new SchedulerConfigException("Job definition data from XML was null after deserialization"); } // // Extract pre-processing commands // if (data.preprocessingcommands != null) { foreach (preprocessingcommandsType command in data.preprocessingcommands) { if (command.deletejobsingroup != null) { foreach (string s in command.deletejobsingroup) { var deleteJobGroup = s.NullSafeTrim(); if (!string.IsNullOrEmpty(deleteJobGroup)) { jobGroupsToDelete.Add(deleteJobGroup); } } } if (command.deletetriggersingroup != null) { foreach (string s in command.deletetriggersingroup) { var deleteTriggerGroup = s.NullSafeTrim(); if (!string.IsNullOrEmpty(deleteTriggerGroup)) { triggerGroupsToDelete.Add(deleteTriggerGroup); } } } if (command.deletejob != null) { foreach (preprocessingcommandsTypeDeletejob s in command.deletejob) { var name = s.name.TrimEmptyToNull(); var group = s.group.TrimEmptyToNull(); if (name == null) { throw new SchedulerConfigException("Encountered a 'delete-job' command without a name specified."); } jobsToDelete.Add(new JobKey(name, group !)); } } if (command.deletetrigger != null) { foreach (preprocessingcommandsTypeDeletetrigger s in command.deletetrigger) { var name = s.name.TrimEmptyToNull(); var group = s.group.TrimEmptyToNull(); if (name == null) { throw new SchedulerConfigException("Encountered a 'delete-trigger' command without a name specified."); } triggersToDelete.Add(new TriggerKey(name, group !)); } } } } if (Log.IsDebugEnabled()) { Log.Debug("Found " + jobGroupsToDelete.Count + " delete job group commands."); Log.Debug("Found " + triggerGroupsToDelete.Count + " delete trigger group commands."); Log.Debug("Found " + jobsToDelete.Count + " delete job commands."); Log.Debug("Found " + triggersToDelete.Count + " delete trigger commands."); } // // Extract directives // if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool overWrite = data.processingdirectives[0].overwriteexistingdata; Log.Debug("Directive 'overwrite-existing-data' specified as: " + overWrite); OverWriteExistingData = overWrite; } else { Log.Debug("Directive 'overwrite-existing-data' not specified, defaulting to " + OverWriteExistingData); } if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool ignoreduplicates = data.processingdirectives[0].ignoreduplicates; Log.Debug("Directive 'ignore-duplicates' specified as: " + ignoreduplicates); IgnoreDuplicates = ignoreduplicates; } else { Log.Debug("Directive 'ignore-duplicates' not specified, defaulting to " + IgnoreDuplicates); } if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool scheduleRelative = data.processingdirectives[0].scheduletriggerrelativetoreplacedtrigger; Log.Debug("Directive 'schedule-trigger-relative-to-replaced-trigger' specified as: " + scheduleRelative); ScheduleTriggerRelativeToReplacedTrigger = scheduleRelative; } else { Log.Debug("Directive 'schedule-trigger-relative-to-replaced-trigger' not specified, defaulting to " + ScheduleTriggerRelativeToReplacedTrigger); } // // Extract Job definitions... // List <jobdetailType> jobNodes = new List <jobdetailType>(); if (data.schedule != null) { foreach (var schedule in data.schedule) { if (schedule?.job != null) { jobNodes.AddRange(schedule.job); } } } Log.Debug("Found " + jobNodes.Count + " job definitions."); foreach (jobdetailType jobDetailType in jobNodes) { var jobName = jobDetailType.name.TrimEmptyToNull(); var jobGroup = jobDetailType.group.TrimEmptyToNull(); var jobDescription = jobDetailType.description.TrimEmptyToNull(); var jobTypeName = jobDetailType.jobtype.TrimEmptyToNull(); bool jobDurability = jobDetailType.durable; bool jobRecoveryRequested = jobDetailType.recover; Type jobType = TypeLoadHelper.LoadType(jobTypeName !) !; IJobDetail jobDetail = JobBuilder.Create(jobType !) .WithIdentity(jobName !, jobGroup !) .WithDescription(jobDescription) .StoreDurably(jobDurability) .RequestRecovery(jobRecoveryRequested) .Build(); if (jobDetailType.jobdatamap != null && jobDetailType.jobdatamap.entry != null) { foreach (entryType entry in jobDetailType.jobdatamap.entry) { var key = entry.key.Trim(); var value = entry.value.TrimEmptyToNull(); jobDetail.JobDataMap.Add(key, value !); } } if (Log.IsDebugEnabled()) { Log.Debug("Parsed job definition: " + jobDetail); } AddJobToSchedule(jobDetail); } // // Extract Trigger definitions... // List <triggerType> triggerEntries = new List <triggerType>(); if (data.schedule != null) { foreach (var schedule in data.schedule) { if (schedule != null && schedule.trigger != null) { triggerEntries.AddRange(schedule.trigger); } } } Log.Debug("Found " + triggerEntries.Count + " trigger definitions."); foreach (triggerType triggerNode in triggerEntries) { var triggerName = triggerNode.Item.name.TrimEmptyToNull() !; var triggerGroup = triggerNode.Item.group.TrimEmptyToNull() !; var triggerDescription = triggerNode.Item.description.TrimEmptyToNull(); var triggerCalendarRef = triggerNode.Item.calendarname.TrimEmptyToNull(); string triggerJobName = triggerNode.Item.jobname.TrimEmptyToNull() !; string triggerJobGroup = triggerNode.Item.jobgroup.TrimEmptyToNull() !; int triggerPriority = TriggerConstants.DefaultPriority; if (!triggerNode.Item.priority.IsNullOrWhiteSpace()) { triggerPriority = Convert.ToInt32(triggerNode.Item.priority); } DateTimeOffset triggerStartTime = SystemTime.UtcNow(); if (triggerNode.Item.Item != null) { if (triggerNode.Item.Item is DateTime time) { triggerStartTime = new DateTimeOffset(time); } else { triggerStartTime = triggerStartTime.AddSeconds(Convert.ToInt32(triggerNode.Item.Item)); } } DateTime?triggerEndTime = triggerNode.Item.endtimeSpecified ? triggerNode.Item.endtime : (DateTime?)null; IScheduleBuilder sched; if (triggerNode.Item is simpleTriggerType simpleTrigger) { var repeatCountString = simpleTrigger.repeatcount.TrimEmptyToNull(); var repeatIntervalString = simpleTrigger.repeatinterval.TrimEmptyToNull(); int repeatCount = ParseSimpleTriggerRepeatCount(repeatCountString !); TimeSpan repeatInterval = repeatIntervalString == null ? TimeSpan.Zero : TimeSpan.FromMilliseconds(Convert.ToInt64(repeatIntervalString)); sched = SimpleScheduleBuilder.Create() .WithInterval(repeatInterval) .WithRepeatCount(repeatCount); if (!simpleTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((SimpleScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(simpleTrigger.misfireinstruction)); } } else if (triggerNode.Item is cronTriggerType) { cronTriggerType cronTrigger = (cronTriggerType)triggerNode.Item; var cronExpression = cronTrigger.cronexpression.TrimEmptyToNull(); var timezoneString = cronTrigger.timezone.TrimEmptyToNull(); TimeZoneInfo?tz = timezoneString != null?TimeZoneUtil.FindTimeZoneById(timezoneString) : null; sched = CronScheduleBuilder.CronSchedule(cronExpression !) .InTimeZone(tz !); if (!cronTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((CronScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(cronTrigger.misfireinstruction)); } } else if (triggerNode.Item is calendarIntervalTriggerType) { calendarIntervalTriggerType calendarIntervalTrigger = (calendarIntervalTriggerType)triggerNode.Item; var repeatIntervalString = calendarIntervalTrigger.repeatinterval.TrimEmptyToNull(); IntervalUnit intervalUnit = ParseDateIntervalTriggerIntervalUnit(calendarIntervalTrigger.repeatintervalunit.TrimEmptyToNull()); int repeatInterval = repeatIntervalString == null ? 0 : Convert.ToInt32(repeatIntervalString); sched = CalendarIntervalScheduleBuilder.Create() .WithInterval(repeatInterval, intervalUnit); if (!calendarIntervalTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((CalendarIntervalScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(calendarIntervalTrigger.misfireinstruction)); } } else { throw new SchedulerConfigException("Unknown trigger type in XML configuration"); } IMutableTrigger trigger = (IMutableTrigger)TriggerBuilder.Create() .WithIdentity(triggerName, triggerGroup) .WithDescription(triggerDescription) .ForJob(triggerJobName, triggerJobGroup) .StartAt(triggerStartTime) .EndAt(triggerEndTime) .WithPriority(triggerPriority) .ModifiedByCalendar(triggerCalendarRef) .WithSchedule(sched) .Build(); if (triggerNode.Item.jobdatamap != null && triggerNode.Item.jobdatamap.entry != null) { foreach (entryType entry in triggerNode.Item.jobdatamap.entry) { string key = entry.key.TrimEmptyToNull() !; var value = entry.value.TrimEmptyToNull(); trigger.JobDataMap.Add(key, value !); } } if (Log.IsDebugEnabled()) { Log.Debug("Parsed trigger definition: " + trigger); } AddTriggerToSchedule(trigger); } }
public virtual void DateShouldBeAffectedByDateTimeZone() { PlatformDate expectedResult = DateUtil.GetDate(2008, 5, 24, 23, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/New_York")); string value = "20080625"; XmlNode node = CreateNode("<something value=\"" + value + "\" specializationType=\"TS.FULLDATE\" />"); ParseContext context = ParseContextImpl.Create("TS.FULLDATE", typeof(PlatformDate), SpecificationVersion.R02_04_02, TimeZoneUtil .GetTimeZone("GMT-3"), null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.POPULATED, null, null, null, null, false); PlatformDate date = (PlatformDate) new TsElementParser().Parse(context, node, this.xmlResult).BareValue; AssertDateEquals("should not be different even though different time zone", MarshallingTestCase.FULL_DATE, expectedResult , date); }
public virtual void TestParseLowWidth() { PlatformDate expectedResultCenter = DateUtil.GetDate(2005, 7, 15, 0, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/Toronto") ); XmlNode node = CreateNode("<effectiveTime><low value=\"20050810\" /><width value=\"10\" unit=\"d\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE, ParseDate("2005-08-10"), interval.Low); AssertDateEquals("high", MarshallingTestCase.FULL_DATE, ParseDate("2005-08-20"), interval.High); AssertDateEquals("center", MarshallingTestCase.FULL_DATE_TIME, expectedResultCenter, interval.Centre); Assert.AreEqual(new BigDecimal("10"), ((DateDiff)interval.Width).ValueAsPhysicalQuantity.Quantity, "width"); }
public void TestSkipDayIfItDoesNotExistsIsFalse() { TimeZoneInfo timeZone = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time"); //March 11, 2012, EST DST starts at 2am and jumps to 3. // 3/11/2012 2:00:00 AM is an invalid time //expected target will always be the on the next valid time, (3/11/2012 3am) in this case DateTimeOffset expectedTarget = new DateTimeOffset(2012, 3, 11, 3, 0, 0, TimeSpan.FromHours(-4)); //------------------------------------------------- // DAILY //------------------------------------------------- CalendarIntervalTriggerImpl trigger = new CalendarIntervalTriggerImpl(); trigger.TimeZone = timeZone; trigger.RepeatInterval = 1; trigger.RepeatIntervalUnit = IntervalUnit.Day; trigger.PreserveHourOfDayAcrossDaylightSavings = true; trigger.SkipDayIfHourDoesNotExist = false; DateTimeOffset startDate = new DateTimeOffset(2012, 3, 10, 2, 0, 0, 0, TimeSpan.FromHours(-5)); trigger.StartTimeUtc = startDate; var fires = TriggerUtils.ComputeFireTimes(trigger, null, 5); var targetTime = fires[1]; //get second fire Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist."); Assert.AreEqual(expectedTarget, targetTime); //------------------------------------------------- // WEEKLY //------------------------------------------------- trigger = new CalendarIntervalTriggerImpl(); trigger.TimeZone = timeZone; trigger.RepeatInterval = 1; trigger.RepeatIntervalUnit = IntervalUnit.Week; trigger.PreserveHourOfDayAcrossDaylightSavings = true; trigger.SkipDayIfHourDoesNotExist = false; startDate = new DateTimeOffset(2012, 3, 4, 2, 0, 0, 0, TimeSpan.FromHours(-5)); trigger.StartTimeUtc = startDate; fires = TriggerUtils.ComputeFireTimes(trigger, null, 5); targetTime = fires[1]; //get second fire Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist."); Assert.AreEqual(expectedTarget, targetTime); //------------------------------------------------- // MONTHLY //------------------------------------------------- trigger = new CalendarIntervalTriggerImpl(); trigger.TimeZone = timeZone; trigger.RepeatInterval = 1; trigger.RepeatIntervalUnit = IntervalUnit.Month; trigger.PreserveHourOfDayAcrossDaylightSavings = true; trigger.SkipDayIfHourDoesNotExist = false; startDate = new DateTimeOffset(2012, 2, 11, 2, 0, 0, 0, TimeSpan.FromHours(-5)); trigger.StartTimeUtc = startDate; fires = TriggerUtils.ComputeFireTimes(trigger, null, 5); targetTime = fires[1]; //get second fire Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist."); Assert.AreEqual(expectedTarget, targetTime); //------------------------------------------------- // YEARLY //------------------------------------------------- trigger = new CalendarIntervalTriggerImpl(); trigger.TimeZone = timeZone; trigger.RepeatInterval = 1; trigger.RepeatIntervalUnit = IntervalUnit.Year; trigger.PreserveHourOfDayAcrossDaylightSavings = true; trigger.SkipDayIfHourDoesNotExist = false; startDate = new DateTimeOffset(2011, 3, 11, 2, 0, 0, 0, TimeSpan.FromHours(-5)); trigger.StartTimeUtc = startDate; fires = TriggerUtils.ComputeFireTimes(trigger, null, 5); targetTime = fires[1]; //get second fire Assert.IsFalse(timeZone.IsInvalidTime(targetTime.DateTime), "did not seem to skip the day with an hour that doesn't exist."); Assert.AreEqual(expectedTarget, targetTime); }
public virtual void TestParseLowHigh() { PlatformDate expectedResultLow = DateUtil.GetDate(2006, 7, 10, 12, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/Toronto")); PlatformDate expectedResultHigh = DateUtil.GetDate(2006, 7, 12, 15, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/Toronto")); int offset = TimeZoneUtil.GetUTCOffset("America/Toronto", expectedResultLow); int hours = -1 * offset / (1000 * 60 * 60); XmlNode node = CreateNode("<effectiveTime><low value=\"20060810120000-0" + hours + "00\" /><high value=\"20060812150000-0" + hours + "00\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS.DATETIME>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE_TIME, expectedResultLow, interval.Low); AssertDateEquals("high", MarshallingTestCase.FULL_DATE_TIME, expectedResultHigh, interval.High); }
public virtual void TestParsePartTimeDateWithSpecializationType() { PlatformDate expectedResultLow = DateUtil.GetDate(2013, 2, 11, 16, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/Toronto")); int offset = TimeZoneUtil.GetUTCOffset("America/Toronto", expectedResultLow); int hours = -1 * offset / (1000 * 60 * 60); XmlNode node = CreateNode("<effectiveTime specializationType=\"IVL_TS.FULLDATEPARTTIME\"><low value=\"2013031116-0" + hours + "00\"/><high nullFlavor=\"NA\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS.FULLDATEWITHTIME>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE_TIME, expectedResultLow, interval.Low); Assert.IsNull(interval.High); Assert.AreEqual(Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.NOT_APPLICABLE.CodeValue, interval.HighNullFlavor .CodeValue); }
protected void Page_Load(object sender, System.EventArgs e) { if (this.Module.CurrentArticleId > 0 && (!base.HasCachedOutput || this.Page.IsPostBack) || this.Page.User.Identity.IsAuthenticated) { // Article view this._activeArticle = this.Module.GetArticleById(this.Module.CurrentArticleId); this.litTitle.Text = this._activeArticle.Title; this.litContent.Text = this._activeArticle.Content; if (this.Module.AllowComments || this.Module.ShowAuthor || this.Module.ShowCategory || this.Module.ShowDateTime) { this.pnlArticleInfo.Visible = true; this.lblDateOnline.Text = TimeZoneUtil.AdjustDateToUserTimeZone(this._activeArticle.PublishedAt.Value, this.Page.User.Identity).ToString(); this.lblDateOnline.Visible = this.Module.ShowDateTime; this.litAuthor.Text = base.GetText("PUBLISHED") + " " + base.GetText("BY"); this.litAuthor.Visible = this.Module.ShowAuthor; this.hplAuthor.NavigateUrl = this.Module.GetProfileUrl(this._activeArticle.CreatedBy.Id); this.hplAuthor.Text = this._activeArticle.CreatedBy.FullName; this.hplAuthor.Visible = this.Module.ShowAuthor; this.litCategory.Text = base.GetText("CATEGORY"); this.litCategory.Visible = this.Module.ShowCategory; // TODO: categories this.cadCategories.SectionBaseUrl = UrlUtil.GetUrlFromSection(Module.Section); this.cadCategories.Categories = this._activeArticle.Categories.ToDictionary(cat => cat.Id, cat => cat.Name); this.cadCategories.Visible = this.Module.ShowCategory; if (this.Module.AllowComments) { this.hplComments.NavigateUrl = UrlHelper.GetUrlFromSection(this.Module.Section) + String.Format("/{0}#comments", this._activeArticle.Id); this.hplComments.Text = base.GetText("COMMENTS") + " " + this._activeArticle.Comments.Count.ToString(); } else { this.hplComments.Visible = false; } } else { this.pnlArticleInfo.Visible = false; } this.hplBack.NavigateUrl = UrlUtil.GetUrlFromSection(this.Module.Section); this.hplBack.Text = base.GetText("BACK"); this.btnSaveComment.Text = base.GetText("BTNSAVECOMMENT"); this.rfvName.ErrorMessage = base.GetText("NAMEREQUIRED"); this.rfvComment.ErrorMessage = base.GetText("COMMENTREQUIRED"); this.pnlArticleDetails.Visible = true; this.pnlComments.Visible = this.Module.AllowComments && this._activeArticle.Comments.Count > 0; if (this.Module.AllowAnonymousComments || (this.Page.User.Identity.IsAuthenticated && this.Module.AllowComments)) { this.pnlComment.Visible = true; this.pnlAnonymous.Visible = (!this.Page.User.Identity.IsAuthenticated); } else { this.pnlComment.Visible = false; } // Comments this.rptComments.DataSource = this._activeArticle.Comments; this.rptComments.ItemDataBound += new RepeaterItemEventHandler(rptComments_ItemDataBound); this.rptComments.DataBind(); } }
/// <summary> /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will /// fire, after the given time. If the trigger will not fire after the given /// time, <see langword="null" /> will be returned. /// </summary> /// <param name="afterTime"></param> /// <returns></returns> public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTime) { // Check if trigger has completed or not. if (complete) { return(null); } // Check repeatCount limit if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount) { return(null); } // a. Increment afterTime by a second, so that we are comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } // if afterTime is before startTime, then return startTime directly. if (afterTime <= startTimeUtc) { return(startTimeUtc); } // now change to local time zone afterTime = TimeZoneUtil.ConvertTime(afterTime.Value, TimeZone); // b.Check to see if afterTime is after endTimeOfDay or not. // If yes, then we need to advance to next day as well. bool afterTimePassEndTimeOfDay = false; if (endTimeOfDay != null) { afterTimePassEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value; } DateTimeOffset?fireTime = AdvanceToNextDayOfWeek(afterTime.Value, afterTimePassEndTimeOfDay); if (fireTime == null) { return(null); } // apply timezone for this date & time fireTime = new DateTimeOffset(fireTime.Value.DateTime, TimeZone.GetUtcOffset(fireTime.Value)); // c. Calculate and save fireTimeEndDate variable for later use DateTimeOffset fireTimeEndDate; if (endTimeOfDay == null) { fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value; } else { fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value; } // apply the proper offset for the end date fireTimeEndDate = new DateTimeOffset(fireTimeEndDate.DateTime, this.TimeZone.GetUtcOffset(fireTimeEndDate.DateTime)); // e. Check fireTime against startTime or startTimeOfDay to see which go first. DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value; // apply the proper offset for the start date fireTimeStartDate = new DateTimeOffset(fireTimeStartDate.DateTime, this.TimeZone.GetUtcOffset(fireTimeStartDate.DateTime)); if (fireTime < startTimeUtc && startTimeUtc < fireTimeStartDate) { return(fireTimeStartDate); } if (fireTime < startTimeUtc && startTimeUtc > fireTimeStartDate) { return(startTimeUtc); } if (fireTime > startTimeUtc && fireTime < fireTimeStartDate) { return(fireTimeStartDate); } // Always adjust the startTime to be startTimeOfDay startTimeUtc = fireTimeStartDate.ToUniversalTime(); // f. Continue to calculate the fireTime by incremental unit of intervals. startTimeUtc = TimeZoneUtil.ConvertTime(startTimeUtc, TimeZone); long secondsAfterStart = (long)(fireTime.Value - startTimeUtc).TotalSeconds; long repeatLong = RepeatInterval; DateTimeOffset sTime = startTimeUtc; IntervalUnit repeatUnit = RepeatIntervalUnit; if (repeatUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart / repeatLong; if (secondsAfterStart % repeatLong != 0) { jumpCount++; } sTime = sTime.AddSeconds(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart / (repeatLong * 60L); if (secondsAfterStart % (repeatLong * 60L) != 0) { jumpCount++; } sTime = sTime.AddMinutes(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart / (repeatLong * 60L * 60L); if (secondsAfterStart % (repeatLong * 60L * 60L) != 0) { jumpCount++; } sTime = sTime.AddHours(RepeatInterval * (int)jumpCount); fireTime = sTime; } // g. Ensure this new fireTime is within one day, or else we need to advance to next day. if (fireTime > fireTimeEndDate) { // Check to see if fireTime has pass fireTime's end of day. If not, we need to advance by one day. DateTimeOffset fireTimeEndOfDay = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTimeEndDate).Value; if (fireTime > fireTimeEndOfDay) { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, false); } else { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, true); } if (fireTime == null) { return(null); } // Check to see if next day fireTime is before startTimeOfDay, if not, we need to set to startTimeOfDay. DateTimeOffset nextDayfireTimeStartDate = StartTimeOfDay.GetTimeOfDayForDate(fireTime).Value; if (fireTime < nextDayfireTimeStartDate) { fireTime = nextDayfireTimeStartDate; } } // i. Return calculated fireTime. return(fireTime.Value.ToUniversalTime()); }
public virtual void DateInterpretedAsSaskShouldBeGreaterThanSameTimeInterpretedAsOntario() { XmlNode node = CreateNode("<something value=\"19990303000000\" />"); PlatformDate saskDate = ((PlatformDate) new TsElementParser().Parse(CreateContextWithTimeZone(TimeZoneUtil.GetTimeZone("Canada/Saskatchewan" )), node, this.xmlResult).BareValue); PlatformDate ontarioDate = ((PlatformDate) new TsElementParser().Parse(CreateContextWithTimeZone(TimeZoneUtil.GetTimeZone( "Canada/Ontario")), node, this.xmlResult).BareValue); Assert.IsTrue(saskDate.CompareTo(ontarioDate) > 0); }
public virtual void TimeZoneHandling() { GeneralTimingSpecification gts = new GeneralTimingSpecification(IntervalFactory.CreateLowHigh <PlatformDate>(DateUtil.GetDate (1969, 11, 31), DateUtil.GetDate(1969, 11, 31)), PeriodicIntervalTime.CreateFrequency(2, new PhysicalQuantity(BigDecimal .TEN, Ca.Infoway.Messagebuilder.Domainvalue.Basic.UnitsOfMeasureCaseSensitive.DAY))); string result = new GtsBoundedPivlFormatter().Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl (this.result, null, "name", "GTS.BOUNDEDPIVL", null, null, false, SpecificationVersion.V01R04_3, TimeZoneUtil.GetTimeZone ("GMT-7"), null, null, false), new GTSImpl(gts)); AssertXml("result", "<name xsi:type=\"SXPR_TS\">" + "<comp operator=\"I\" xsi:type=\"IVL_TS\">" + "<low value=\"19691230\"/>" + "<high value=\"19691230\"/></comp>" + "<comp xsi:type=\"PIVL_TS\">" + "<frequency><numerator value=\"2\"/><denominator unit=\"d\" value=\"10\"/></frequency></comp></name>" , result); Assert.IsTrue(this.result.IsValid()); }
public virtual void TestParseLowHighAlt() { PlatformDate expectedResultCenter = DateUtil.GetDate(2006, 7, 11, 0, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/Toronto") ); XmlNode node = CreateNode("<effectiveTime><low value=\"20060810\" /><high value=\"20060812\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE, ParseDate("2006-08-10"), interval.Low); AssertDateEquals("high", MarshallingTestCase.FULL_DATE, ParseDate("2006-08-12"), interval.High); AssertDateEquals("center", MarshallingTestCase.FULL_DATE_TIME, expectedResultCenter, interval.Centre); Assert.AreEqual(DateUtils.MILLIS_PER_DAY * 2L, interval.Width.Value.Time, "width"); }
public virtual void TestParseLowFullDateTime() { PlatformDate expectedResultlow = DateUtil.GetDate(2005, 7, 10, 23, 3, 27, 0, TimeZoneUtil.GetTimeZone("America/Toronto")); XmlNode node = CreateNode("<effectiveTime><low value=\"20050810230327\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS>"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE_TIME, expectedResultlow, interval.Low); Assert.IsNull(interval.High, "high"); Assert.IsNull(interval.Centre, "centre"); Assert.IsNull(interval.Width, "width"); }
public virtual void TestParseEffectiveTimeDateWithSpecializationTypeAlternative() { PlatformDate expectedResultLow = DateUtil.GetDate(2013, 2, 11, 16, 44, 2, 0, TimeZoneUtil.GetTimeZone("America/Toronto")); int offset = TimeZoneUtil.GetUTCOffset("America/Toronto", expectedResultLow); int hours = -1 * offset / (1000 * 60 * 60); // specializationType should not have to be specified as "IVL<TS.FULLDATETIME>", but should be accepted as "IVL_TS.FULLDATETIME" (which is how the MB formatter would write it) XmlNode node = CreateNode("<effectiveTime specializationType=\"IVL_TS.FULLDATETIME\"><low value=\"20130311164402.7530-0" + hours + "00\"/><high nullFlavor=\"NA\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL<TS.FULLDATEWITHTIME>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE_TIME, expectedResultLow, interval.Low); Assert.IsNull(interval.High); Assert.AreEqual(Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.NOT_APPLICABLE.CodeValue, interval.HighNullFlavor .CodeValue); }
public virtual void ShouldBeConvertedDueToTimeZone() { PlatformDate expectedResult = DateUtil.GetDate(2008, 5, 24, 23, 0, 0, 0, TimeZoneUtil.GetTimeZone("America/New_York")); string value = "20080625"; XmlNode node = CreateNode("<something value=\"" + value + "\" />"); ParseContext context = ParseContextImpl.Create("TS", typeof(PlatformDate), SpecificationVersion.R02_04_02, TimeZoneUtil.GetTimeZone ("GMT-3"), TimeZoneUtil.GetTimeZone("GMT-3"), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.POPULATED, null, null, null , null, false); MbDate mbDate = (MbDate) new TsR2ElementParser().Parse(context, node, this.xmlResult).BareValue; AssertDateEquals("should have been converted due to time zone", MarshallingTestCase.FULL_DATE_TIME, expectedResult, mbDate .Value); }
public virtual void TestParseLow() { PlatformDate expectedResultLow = DateUtil.GetDate(2005, 7, 10, 14, 34, 56, 0, TimeZoneUtil.GetTimeZone("America/Toronto") ); int offset = TimeZoneUtil.GetUTCOffset("America/Toronto", expectedResultLow); int hours = -1 * offset / (1000 * 60 * 60); XmlNode node = CreateNode("<effectiveTime><low value=\"20050810143456-0" + hours + "00\" /></effectiveTime>"); Interval <PlatformDate> interval = Parse(node, "IVL.LOW<TS>"); Assert.IsTrue(this.result.IsValid(), "valid"); Assert.IsNotNull(interval, "null"); AssertDateEquals("low", MarshallingTestCase.FULL_DATE_TIME, expectedResultLow, interval.Low); Assert.IsNull(interval.High, "high"); Assert.IsNull(interval.Centre, "centre"); Assert.IsNull(interval.Width, "width"); }
/// <summary> /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will /// fire, after the given time. If the trigger will not fire after the given /// time, <see langword="null" /> will be returned. /// </summary> /// <param name="afterTime"></param> /// <returns></returns> public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTime) { // Check if trigger has completed or not. if (complete) { return(null); } // Check repeatCount limit if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount) { return(null); } // a. Increment afterTime by a second, so that we are comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } // make sure afterTime is at least startTime if (afterTime < startTimeUtc) { afterTime = startTimeUtc; } // now change to local time zone afterTime = TimeZoneUtil.ConvertTime(afterTime.Value, TimeZone); // b.Check to see if afterTime is after endTimeOfDay or not. // If yes, then we need to advance to next day as well. bool afterTimePastEndTimeOfDay = false; if (endTimeOfDay != null) { afterTimePastEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value; } // c. now we need to move to the next valid day of week if either: // the given time is past the end time of day, or given time is not on a valid day of week DateTimeOffset?fireTime = AdvanceToNextDayOfWeekIfNecessary(afterTime.Value, afterTimePastEndTimeOfDay); if (fireTime == null) { return(null); } // apply timezone for this date & time fireTime = new DateTimeOffset(fireTime.Value.DateTime, TimeZoneUtil.GetUtcOffset(fireTime.Value, TimeZone)); // d. Calculate and save fireTimeEndDate variable for later use DateTimeOffset fireTimeEndDate; if (endTimeOfDay == null) { fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value; } else { fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value; } // apply the proper offset for the end date fireTimeEndDate = new DateTimeOffset(fireTimeEndDate.DateTime, TimeZone.GetUtcOffset(fireTimeEndDate.DateTime)); // e. Check fireTime against startTime or startTimeOfDay to see which go first. DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value; // apply the proper offset for the start date fireTimeStartDate = new DateTimeOffset(fireTimeStartDate.DateTime, TimeZone.GetUtcOffset(fireTimeStartDate.DateTime)); if (fireTime < fireTimeStartDate) { return(fireTimeStartDate.ToUniversalTime()); } // f. Continue to calculate the fireTime by incremental unit of intervals. // recall that if fireTime was less that fireTimeStartDate, we didn't get this far startTimeUtc = TimeZoneUtil.ConvertTime(fireTimeStartDate, TimeZone); long secondsAfterStart = (long)(fireTime.Value - startTimeUtc).TotalSeconds; long repeatLong = RepeatInterval; DateTimeOffset sTime = fireTimeStartDate; IntervalUnit repeatUnit = RepeatIntervalUnit; if (repeatUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart / repeatLong; if (secondsAfterStart % repeatLong != 0) { jumpCount++; } sTime = sTime.AddSeconds(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart / (repeatLong * 60L); if (secondsAfterStart % (repeatLong * 60L) != 0) { jumpCount++; } sTime = sTime.AddMinutes(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart / (repeatLong * 60L * 60L); if (secondsAfterStart % (repeatLong * 60L * 60L) != 0) { jumpCount++; } sTime = sTime.AddHours(RepeatInterval * (int)jumpCount); fireTime = sTime; } // g. Ensure this new fireTime is within the day, or else we need to advance to next day. if (fireTime > fireTimeEndDate) { fireTime = AdvanceToNextDayOfWeekIfNecessary(fireTime.Value, IsSameDay(fireTime.Value, fireTimeEndDate)); // make sure we hit the startTimeOfDay on the new day fireTime = startTimeOfDay.GetTimeOfDayForDate(fireTime); } // i. Return calculated fireTime. if (fireTime == null) { return(null); } // apply proper offset var d = fireTime.Value; d = new DateTimeOffset(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, TimeZone.GetUtcOffset(d.DateTime)); return(d.ToUniversalTime()); }
public void TestDaylightSavingsTransitions() { // Pick a day before a spring daylight savings transition... DateTimeOffset startCalendar = DateBuilder.DateOf(9, 30, 17, 12, 3, 2010); var dailyTrigger = new CalendarIntervalTriggerImpl { StartTimeUtc = startCalendar, RepeatIntervalUnit = IntervalUnit.Day, RepeatInterval = 5 // every 5 days }; DateTimeOffset targetCalendar = startCalendar.AddDays(10); // jump 10 days (2 intervals) IList <DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); DateTimeOffset testTime = fireTimes[2]; // get the third fire time Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over spring 2010 daylight savings transition."); // And again, Pick a day before a spring daylight savings transition... (QTZ-240) startCalendar = new DateTime(2011, 3, 12, 1, 0, 0); dailyTrigger = new CalendarIntervalTriggerImpl(); dailyTrigger.StartTimeUtc = startCalendar; dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day; dailyTrigger.RepeatInterval = 1; // every day targetCalendar = startCalendar.AddDays(2); // jump 2 days (2 intervals) fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); testTime = fireTimes[2]; // get the third fire time Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over spring 2011 daylight savings transition."); // And again, Pick a day before a spring daylight savings transition... (QTZ-240) - and prove time of day is not preserved without setPreserveHourOfDayAcrossDaylightSavings(true) var cetTimeZone = TimeZoneUtil.FindTimeZoneById("Central European Standard Time"); startCalendar = TimeZoneInfo.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone); dailyTrigger = new CalendarIntervalTriggerImpl(); dailyTrigger.StartTimeUtc = startCalendar; dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day; dailyTrigger.RepeatInterval = 1; // every day targetCalendar = TimeZoneUtil.ConvertTime(startCalendar, cetTimeZone); targetCalendar = targetCalendar.AddDays(2); // jump 2 days (2 intervals) fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); testTime = fireTimes[2]; // get the third fire time DateTimeOffset testCal = TimeZoneUtil.ConvertTime(testTime, cetTimeZone); Assert.AreNotEqual(targetCalendar.Hour, testCal.Hour, "Day increment time-of-day result not as expected over spring 2011 daylight savings transition."); // And again, Pick a day before a spring daylight savings transition... (QTZ-240) - and prove time of day is preserved with setPreserveHourOfDayAcrossDaylightSavings(true) startCalendar = TimeZoneUtil.ConvertTime(new DateTime(2011, 3, 26, 4, 0, 0), cetTimeZone); dailyTrigger = new CalendarIntervalTriggerImpl(); dailyTrigger.StartTimeUtc = startCalendar; dailyTrigger.RepeatIntervalUnit = IntervalUnit.Day; dailyTrigger.RepeatInterval = 1; // every day dailyTrigger.TimeZone = cetTimeZone; dailyTrigger.PreserveHourOfDayAcrossDaylightSavings = true; targetCalendar = startCalendar.AddDays(2); // jump 2 days (2 intervals) fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); testTime = fireTimes[1]; // get the second fire time testCal = TimeZoneUtil.ConvertTime(testTime, cetTimeZone); Assert.AreEqual(targetCalendar.Hour, testCal.Hour, "Day increment time-of-day result not as expected over spring 2011 daylight savings transition."); // Pick a day before a fall daylight savings transition... startCalendar = new DateTimeOffset(2010, 10, 31, 9, 30, 17, TimeSpan.Zero); dailyTrigger = new CalendarIntervalTriggerImpl { StartTimeUtc = startCalendar, RepeatIntervalUnit = IntervalUnit.Day, RepeatInterval = 5 // every 5 days }; targetCalendar = startCalendar.AddDays(15); // jump 15 days (3 intervals) fireTimes = TriggerUtils.ComputeFireTimes(dailyTrigger, null, 6); testTime = fireTimes[3]; // get the fourth fire time Assert.AreEqual(targetCalendar, testTime, "Day increment result not as expected over fall daylight savings transition."); }
protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, nameof(e)); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } Item currentItem = GetCurrentItem(); if (currentItem != null) { if (currentItem.IsFallback) { HtmlGenericControl htmlGenericControl = new HtmlGenericControl("div"); htmlGenericControl.InnerText = Translate.Text("No version exists in the current language. You see a fallback version from '{0}' language.", (object)currentItem.OriginalLanguage); htmlGenericControl.Attributes["class"] = "versionNumSelected"; Context.ClientPage.AddControl(Versions, htmlGenericControl); } else { Item[] versions = currentItem.Versions.GetVersions(); for (int index = versions.Length - 1; index >= 0; --index) { Item obj = versions[index]; XmlControl control = ControlFactory.GetControl("Gallery.Versions.Option") as XmlControl; Assert.IsNotNull(control, typeof(XmlControl), "Xml Control \"{0}\" not found", (object)"Gallery.Versions.Option"); Context.ClientPage.AddControl(Versions, control); CultureInfo culture = Context.User.Profile.Culture; string str1 = obj.Statistics.Updated == DateTime.MinValue ? Translate.Text("[Not set]") : DateUtil.FormatShortDateTime(TimeZoneUtil.ToUserTime(obj.Statistics.Updated), culture); string str2 = obj.Statistics.UpdatedBy.Length == 0 ? "-" : obj.Statistics.UpdatedBy; string str3 = obj.Version + "."; string str4 = obj.Version.Number != currentItem.Version.Number ? "<div class=\"versionNum\">" + str3 + "</div>" : "<div class=\"versionNumSelected\">" + str3 + "</div>"; control["Number"] = str4; control["Header"] = Translate.Text("Modified <b>{0}</b> by <b>{1}</b>.", str1, str2); control["Click"] = $"item:load(id={currentItem.ID},language={currentItem.Language},version={obj.Version.Number})"; } } } Item obj1 = Client.CoreDatabase.GetItem("/sitecore/content/Applications/Content Editor/Menues/Versions"); if (obj1 == null || !obj1.HasChildren) { return; } string queryString = WebUtil.GetQueryString("id"); Options.AddFromDataSource(obj1, queryString, new CommandContext(currentItem)); }
private DateTimeOffset CreateCalendarTime(DateTimeOffset dateTime) { return(TimeZoneUtil.ConvertTime(dateTime, TimeZone)); }
public async Task Test(IScheduler scheduler, bool clearJobs, bool scheduleJobs) { try { if (clearJobs) { await scheduler.Clear(); } if (scheduleJobs) { ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?"); ICalendar holidayCalendar = new HolidayCalendar(); // QRTZNET-86 ITrigger t = await scheduler.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup")); Assert.IsNull(t); AnnualCalendar cal = new AnnualCalendar(); await scheduler.AddCalendar("annualCalendar", cal, false, true); IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5)); calendarsTrigger.CalendarName = "annualCalendar"; JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob)); await scheduler.ScheduleJob(jd, calendarsTrigger); // QRTZNET-93 await scheduler.AddCalendar("annualCalendar", cal, true, true); await scheduler.AddCalendar("baseCalendar", new BaseCalendar(), false, true); await scheduler.AddCalendar("cronCalendar", cronCalendar, false, true); await scheduler.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true); await scheduler.AddCalendar("holidayCalendar", holidayCalendar, false, true); await scheduler.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true); await scheduler.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true); await scheduler.AddCalendar("cronCalendar", cronCalendar, true, true); await scheduler.AddCalendar("holidayCalendar", holidayCalendar, true, true); Assert.IsNotNull(scheduler.GetCalendar("annualCalendar")); JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob)); lonelyJob.Durable = true; lonelyJob.RequestsRecovery = true; await scheduler.AddJob(lonelyJob, false); await scheduler.AddJob(lonelyJob, true); string schedId = scheduler.SchedulerInstanceId; int count = 1; JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5)); trigger.JobDataMap.Add("key", "value"); trigger.EndTimeUtc = DateTime.UtcNow.AddYears(10); trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L); await scheduler.ScheduleJob(job, trigger); // check that trigger was stored ITrigger persisted = await scheduler.GetTrigger(new TriggerKey("trig_" + count, schedId)); Assert.IsNotNull(persisted); Assert.IsTrue(persisted is SimpleTriggerImpl); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5)); trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(2000L); await scheduler.ScheduleJob(job, trigger); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3)); trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L); await scheduler.ScheduleJob(job, trigger); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4)); trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L); await scheduler.ScheduleJob(job, trigger); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500)); await scheduler.ScheduleJob(job, trigger); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; IOperableTrigger ct = new CronTriggerImpl("cron_trig_" + count, schedId, "0/10 * * * * ?"); ct.JobDataMap.Add("key", "value"); ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000); await scheduler.ScheduleJob(job, ct); count++; job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); // ask scheduler to re-Execute this job if it was in progress when // the scheduler went down... job.RequestsRecovery = true; var timeZone1 = TimeZoneUtil.FindTimeZoneById("Central European Standard Time"); var timeZone2 = TimeZoneUtil.FindTimeZoneById("Mountain Standard Time"); DailyTimeIntervalTriggerImpl nt = new DailyTimeIntervalTriggerImpl("nth_trig_" + count, schedId, new TimeOfDay(1, 1, 1), new TimeOfDay(23, 30, 0), IntervalUnit.Hour, 1); nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000); nt.TimeZone = timeZone1; await scheduler.ScheduleJob(job, nt); var loadedNt = (IDailyTimeIntervalTrigger)await scheduler.GetTrigger(nt.Key); Assert.That(loadedNt.TimeZone.Id, Is.EqualTo(timeZone1.Id)); nt.TimeZone = timeZone2; await scheduler.RescheduleJob(nt.Key, nt); loadedNt = (IDailyTimeIntervalTrigger)await scheduler.GetTrigger(nt.Key); Assert.That(loadedNt.TimeZone.Id, Is.EqualTo(timeZone2.Id)); DailyTimeIntervalTriggerImpl nt2 = new DailyTimeIntervalTriggerImpl(); nt2.Key = new TriggerKey("nth_trig2_" + count, schedId); nt2.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000); nt2.JobKey = job.Key; await scheduler.ScheduleJob(nt2); // GitHub issue #92 await scheduler.GetTrigger(nt2.Key); // GitHub issue #98 nt2.StartTimeOfDay = new TimeOfDay(1, 2, 3); nt2.EndTimeOfDay = new TimeOfDay(2, 3, 4); await scheduler.UnscheduleJob(nt2.Key); await scheduler.ScheduleJob(nt2); var triggerFromDb = (IDailyTimeIntervalTrigger)await scheduler.GetTrigger(nt2.Key); Assert.That(triggerFromDb.StartTimeOfDay.Hour, Is.EqualTo(1)); Assert.That(triggerFromDb.StartTimeOfDay.Minute, Is.EqualTo(2)); Assert.That(triggerFromDb.StartTimeOfDay.Second, Is.EqualTo(3)); Assert.That(triggerFromDb.EndTimeOfDay.Hour, Is.EqualTo(2)); Assert.That(triggerFromDb.EndTimeOfDay.Minute, Is.EqualTo(3)); Assert.That(triggerFromDb.EndTimeOfDay.Second, Is.EqualTo(4)); job.RequestsRecovery = true; CalendarIntervalTriggerImpl intervalTrigger = new CalendarIntervalTriggerImpl( "calint_trig_" + count, schedId, DateTime.UtcNow.AddMilliseconds(300), DateTime.UtcNow.AddMinutes(1), IntervalUnit.Second, 8); intervalTrigger.JobKey = job.Key; await scheduler.ScheduleJob(intervalTrigger); // custom time zone const string CustomTimeZoneId = "Custom TimeZone"; var webTimezone = TimeZoneInfo.CreateCustomTimeZone( CustomTimeZoneId, TimeSpan.FromMinutes(22), null, null); TimeZoneUtil.CustomResolver = id => { if (id == CustomTimeZoneId) { return(webTimezone); } return(null); }; var customTimeZoneTrigger = TriggerBuilder.Create() .WithIdentity("customTimeZoneTrigger") .WithCronSchedule("0/5 * * * * ?", x => x.InTimeZone(webTimezone)) .StartNow() .ForJob(job) .Build(); await scheduler.ScheduleJob(customTimeZoneTrigger); var loadedCustomTimeZoneTrigger = (ICronTrigger)await scheduler.GetTrigger(customTimeZoneTrigger.Key); Assert.That(loadedCustomTimeZoneTrigger.TimeZone.BaseUtcOffset, Is.EqualTo(TimeSpan.FromMinutes(22))); // bulk operations var info = new Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> >(); IJobDetail detail = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob)); ITrigger simple = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500)); var triggers = new List <ITrigger>(); triggers.Add(simple); info[detail] = triggers; await scheduler.ScheduleJobs(info, true); Assert.IsTrue(await scheduler.CheckExists(detail.Key)); Assert.IsTrue(await scheduler.CheckExists(simple.Key)); // QRTZNET-243 await scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains("a").DeepClone()); await scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEndsWith("a").DeepClone()); await scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupStartsWith("a").DeepClone()); await scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEquals("a").DeepClone()); await scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupContains("a").DeepClone()); await scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEndsWith("a").DeepClone()); await scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupStartsWith("a").DeepClone()); await scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals("a").DeepClone()); await scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(3)); await scheduler.PauseAll(); await scheduler.ResumeAll(); await scheduler.PauseJob(new JobKey("job_1", schedId)); await scheduler.ResumeJob(new JobKey("job_1", schedId)); await scheduler.PauseJobs(GroupMatcher <JobKey> .GroupEquals(schedId)); await Task.Delay(TimeSpan.FromSeconds(1)); await scheduler.ResumeJobs(GroupMatcher <JobKey> .GroupEquals(schedId)); await scheduler.PauseTrigger(new TriggerKey("trig_2", schedId)); await scheduler.ResumeTrigger(new TriggerKey("trig_2", schedId)); await scheduler.PauseTriggers(GroupMatcher <TriggerKey> .GroupEquals(schedId)); var pausedTriggerGroups = await scheduler.GetPausedTriggerGroups(); Assert.AreEqual(1, pausedTriggerGroups.Count); await Task.Delay(TimeSpan.FromSeconds(3)); await scheduler.ResumeTriggers(GroupMatcher <TriggerKey> .GroupEquals(schedId)); Assert.IsNotNull(scheduler.GetTrigger(new TriggerKey("trig_2", schedId))); Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_1", schedId))); Assert.IsNotNull(scheduler.GetMetaData()); Assert.IsNotNull(scheduler.GetCalendar("weeklyCalendar")); var genericjobKey = new JobKey("genericJob", "genericGroup"); GenericJobType.Reset(); var genericJob = JobBuilder.Create <GenericJobType>() .WithIdentity(genericjobKey) .StoreDurably() .Build(); await scheduler.AddJob(genericJob, false); genericJob = await scheduler.GetJobDetail(genericjobKey); Assert.That(genericJob, Is.Not.Null); await scheduler.TriggerJob(genericjobKey); GenericJobType.WaitForTrigger(TimeSpan.FromSeconds(20)); Assert.That(GenericJobType.TriggeredCount, Is.EqualTo(1)); await scheduler.Standby(); CollectionAssert.IsNotEmpty(await scheduler.GetCalendarNames()); CollectionAssert.IsNotEmpty(await scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(schedId))); CollectionAssert.IsNotEmpty(await scheduler.GetTriggersOfJob(new JobKey("job_2", schedId))); Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_2", schedId))); await scheduler.DeleteCalendar("cronCalendar"); await scheduler.DeleteCalendar("holidayCalendar"); await scheduler.DeleteJob(new JobKey("lonelyJob", "lonelyGroup")); await scheduler.DeleteJob(job.Key); await scheduler.GetJobGroupNames(); await scheduler.GetCalendarNames(); await scheduler.GetTriggerGroupNames(); await TestMatchers(scheduler); } } finally { await scheduler.Shutdown(false); } }
protected DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTime, bool ignoreEndTime) { // increment afterTime by a second, so that we are // comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } DateTimeOffset startMillis = StartTimeUtc; DateTimeOffset afterMillis = afterTime.Value; DateTimeOffset endMillis = (EndTimeUtc == null) ? DateTimeOffset.MaxValue : EndTimeUtc.Value; if (!ignoreEndTime && (endMillis <= afterMillis)) { return(null); } if (afterMillis < startMillis) { return(startMillis); } long secondsAfterStart = (long)(afterMillis - startMillis).TotalSeconds; DateTimeOffset?time = null; long repeatLong = RepeatInterval; DateTimeOffset sTime = StartTimeUtc; if (timeZone != null) { sTime = TimeZoneUtil.ConvertTime(sTime, timeZone); } if (RepeatIntervalUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart / repeatLong; if (secondsAfterStart % repeatLong != 0) { jumpCount++; } time = sTime.AddSeconds(RepeatInterval * (int)jumpCount); } else if (RepeatIntervalUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart / (repeatLong * 60L); if (secondsAfterStart % (repeatLong * 60L) != 0) { jumpCount++; } time = sTime.AddMinutes(RepeatInterval * (int)jumpCount); } else if (RepeatIntervalUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart / (repeatLong * 60L * 60L); if (secondsAfterStart % (repeatLong * 60L * 60L) != 0) { jumpCount++; } time = sTime.AddHours(RepeatInterval * (int)jumpCount); } else { // intervals a day or greater ... int initialHourOfDay = sTime.Hour; if (RepeatIntervalUnit == IntervalUnit.Day) { // Because intervals greater than an hour have an non-fixed number // of seconds in them (due to daylight savings, variation number of // days in each month, leap year, etc. ) we can't jump forward an // exact number of seconds to calculate the fire time as we can // with the second, minute and hour intervals. But, rather // than slowly crawling our way there by iteratively adding the // increment to the start time until we reach the "after time", // we can first make a big leap most of the way there... long jumpCount = secondsAfterStart / (repeatLong * 24L * 60L * 60L); // if we need to make a big jump, jump most of the way there, // but not all the way because in some cases we may over-shoot or under-shoot if (jumpCount > 20) { if (jumpCount < 50) { jumpCount = (long)(jumpCount * 0.80); } else if (jumpCount < 500) { jumpCount = (long)(jumpCount * 0.90); } else { jumpCount = (long)(jumpCount * 0.95); } sTime = sTime.AddDays(RepeatInterval * jumpCount); } // now baby-step the rest of the way there... while (sTime.UtcDateTime < afterTime.Value.UtcDateTime && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddDays(RepeatInterval); MakeHourAdjustmentIfNeeded(ref sTime, initialHourOfDay); //hours can shift due to DST } while (DaylightSavingHourShiftOccurredAndAdvanceNeeded(ref sTime, initialHourOfDay) && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddDays(RepeatInterval); } time = sTime; } else if (RepeatIntervalUnit == IntervalUnit.Week) { // Because intervals greater than an hour have an non-fixed number // of seconds in them (due to daylight savings, variation number of // days in each month, leap year, etc. ) we can't jump forward an // exact number of seconds to calculate the fire time as we can // with the second, minute and hour intervals. But, rather // than slowly crawling our way there by iteratively adding the // increment to the start time until we reach the "after time", // we can first make a big leap most of the way there... long jumpCount = secondsAfterStart / (repeatLong * 7L * 24L * 60L * 60L); // if we need to make a big jump, jump most of the way there, // but not all the way because in some cases we may over-shoot or under-shoot if (jumpCount > 20) { if (jumpCount < 50) { jumpCount = (long)(jumpCount * 0.80); } else if (jumpCount < 500) { jumpCount = (long)(jumpCount * 0.90); } else { jumpCount = (long)(jumpCount * 0.95); } sTime = sTime.AddDays((int)(RepeatInterval * jumpCount * 7)); } while (sTime.UtcDateTime < afterTime.Value.UtcDateTime && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddDays(RepeatInterval * 7); MakeHourAdjustmentIfNeeded(ref sTime, initialHourOfDay); //hours can shift due to DST } while (DaylightSavingHourShiftOccurredAndAdvanceNeeded(ref sTime, initialHourOfDay) && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddDays(RepeatInterval * 7); } time = sTime; } else if (RepeatIntervalUnit == IntervalUnit.Month) { // because of the large variation in size of months, and // because months are already large blocks of time, we will // just advance via brute-force iteration. while (sTime.UtcDateTime < afterTime.Value.UtcDateTime && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddMonths(RepeatInterval); MakeHourAdjustmentIfNeeded(ref sTime, initialHourOfDay); //hours can shift due to DST } while (DaylightSavingHourShiftOccurredAndAdvanceNeeded(ref sTime, initialHourOfDay) && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddMonths(RepeatInterval); } time = sTime; } else if (RepeatIntervalUnit == IntervalUnit.Year) { while (sTime.UtcDateTime < afterTime.Value.UtcDateTime && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddYears(RepeatInterval); MakeHourAdjustmentIfNeeded(ref sTime, initialHourOfDay); //hours can shift due to DST } while (DaylightSavingHourShiftOccurredAndAdvanceNeeded(ref sTime, initialHourOfDay) && sTime.Year < YearToGiveupSchedulingAt) { sTime = sTime.AddYears(RepeatInterval); } time = sTime; } } // case of interval of a day or greater if (!ignoreEndTime && endMillis <= time) { return(null); } sTime = TimeZoneUtil.ConvertTime(sTime, this.TimeZone); //apply the timezone before we return the time. return(time); }
public virtual void TestGetValueGeneratesDifferentStringsForDifferentTimeZones() { PlatformDate calendar = DateUtil.GetDate(1999, 3, 23, 10, 11, 12, 0); string gmtSixValue = new TsFullDateTimePropertyFormatterTest.TestableTsFullDateTimePropertyFormatter().GetValueForTest(calendar , CreateFormatContextWithTimeZone(TimeZoneUtil.GetTimeZone("GMT-6")), null); string gmtFiveValue = new TsFullDateTimePropertyFormatterTest.TestableTsFullDateTimePropertyFormatter().GetValueForTest(calendar , CreateFormatContextWithTimeZone(TimeZoneUtil.GetTimeZone("GMT-5")), null); Assert.IsFalse(StringUtils.Equals(gmtSixValue, gmtFiveValue)); }