本文整理汇总了C#中RecurrencePattern类的典型用法代码示例。如果您正苦于以下问题:C# RecurrencePattern类的具体用法?C# RecurrencePattern怎么用?C# RecurrencePattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecurrencePattern类属于命名空间,在下文中一共展示了RecurrencePattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateiCalTimeZoneInfo
static private void PopulateiCalTimeZoneInfo(ITimeZoneInfo tzi, System.TimeZoneInfo.TransitionTime transition, int year)
{
Calendar c = CultureInfo.CurrentCulture.Calendar;
RecurrencePattern recurrence = new RecurrencePattern();
recurrence.Frequency = FrequencyType.Yearly;
recurrence.ByMonth.Add(transition.Month);
recurrence.ByHour.Add(transition.TimeOfDay.Hour);
recurrence.ByMinute.Add(transition.TimeOfDay.Minute);
if (transition.IsFixedDateRule)
{
recurrence.ByMonthDay.Add(transition.Day);
}
else
{
recurrence.ByDay.Add(new WeekDay(transition.DayOfWeek));
int daysInMonth = c.GetDaysInMonth(year, transition.Month);
int offset = (transition.Week * 7) - 7;
if (offset + 7 > daysInMonth)
offset = daysInMonth - 7;
// Add the possible days of the month this could occur.
for (int i = 1; i <= 7; i++)
recurrence.ByMonthDay.Add(i + offset + (int)transition.DayOfWeek);
}
tzi.RecurrenceRules.Add(recurrence);
}
示例2: IsOccurrenceInRange
public static bool IsOccurrenceInRange(string valueToParse, DateTime start, DateTime end)
{
RecurrencePattern pattern = new RecurrencePattern();
if (RecurrencePatternHelper.TryParseRecurrencePattern(valueToParse, out pattern))
{
return pattern.GetOccurrences(start, start, end).Count() > 0;
}
return false;
}
示例3: ProcessRecurrencePattern
private IRecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
{
RecurrencePattern r = new RecurrencePattern();
r.CopyFrom(Pattern);
// Convert the UNTIL value to one that matches the same time information as the reference date
if (r.Until != DateTime.MinValue)
r.Until = DateUtil.MatchTimeZone(referenceDate, new iCalDateTime(r.Until)).Value;
if (r.Frequency > FrequencyType.Secondly &&
r.BySecond.Count == 0 &&
referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
r.BySecond.Add(referenceDate.Second);
if (r.Frequency > FrequencyType.Minutely &&
r.ByMinute.Count == 0 &&
referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
r.ByMinute.Add(referenceDate.Minute);
if (r.Frequency > FrequencyType.Hourly &&
r.ByHour.Count == 0 &&
referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
r.ByHour.Add(referenceDate.Hour);
// If BYDAY, BYYEARDAY, or BYWEEKNO is specified, then
// we don't default BYDAY, BYMONTH or BYMONTHDAY
if (r.ByDay.Count == 0 &&
r.ByYearDay.Count == 0 &&
r.ByWeekNo.Count == 0)
{
// If the frequency is weekly, and
// no day of week is specified, use
// the original date's day of week.
// NOTE: fixes WeeklyCount1() and WeeklyUntil1() handling
if (r.Frequency == FrequencyType.Weekly)
r.ByDay.Add(new WeekDay(referenceDate.DayOfWeek));
// If BYMONTHDAY is not specified,
// default to the current day of month
// NOTE: fixes YearlyByMonth1() handling, added BYYEARDAY exclusion
// to fix YearlyCountByYearDay1() handling
if (r.Frequency > FrequencyType.Weekly &&
r.ByMonthDay.Count == 0)
r.ByMonthDay.Add(referenceDate.Day);
// If BYMONTH is not specified, default to
// the current month.
// NOTE: fixes YearlyCountByYearDay1() handling
if (r.Frequency > FrequencyType.Monthly &&
r.ByMonth.Count == 0)
r.ByMonth.Add(referenceDate.Month);
}
return r;
}
示例4: Create
public ActionResult Create(GroupInstance groupinstance)
{
if (ModelState.IsValid)
{
//default recurrence once a week forever
RecurrencePattern rp = new RecurrencePattern(FrequencyType.Weekly);
groupinstance.RecurrenceRule = "RRULE:" + rp.ToString();
db.GroupInstances.Add(groupinstance);
db.SaveChanges();
return Content(Boolean.TrueString);
}
//TODO: review error handling. This will fail since it is not filtering dropdowns for overlapping events!!!
ViewBag.GroupId = new SelectList(db.Groups, "GroupId", "Name", groupinstance.GroupId);
ViewBag.ClassroomId = new SelectList(db.Classrooms, "ClassroomID", "Name", groupinstance.ClassroomId);
return Content("Please review your form");
}
示例5: Example
// From: http://sourcefield.blogspot.com/2011/06/dday-ical-example.html
public void Example()
{
// #1: Monthly meetings that occur on the last Wednesday from 6pm - 7pm
// Create an iCalendar
var iCal = new iCalendar();
// Create the event
var evt = iCal.Create<Event>();
evt.Summary = "Test Event";
evt.Start = new iCalDateTime(2008, 1, 1, 18, 0, 0); // Starts January 1, 2008 @ 6:00 P.M.
evt.Duration = TimeSpan.FromHours(1);
// Add a recurrence pattern to the event
var rp = new RecurrencePattern {Frequency = FrequencyType.Monthly};
rp.ByDay.Add(new WeekDay(DayOfWeek.Wednesday, FrequencyOccurrence.Last));
evt.RecurrenceRules.Add(rp);
// #2: Yearly events like holidays that occur on the same day each year.
// The same as #1, except:
var rp2 = new RecurrencePattern {Frequency = FrequencyType.Yearly};
evt.RecurrenceRules.Add(rp2);
// #3: Yearly events like holidays that occur on a specific day like the first monday.
// The same as #1, except:
var rp3 = new RecurrencePattern {Frequency = FrequencyType.Yearly};
rp3.ByMonth.Add(3);
rp3.ByDay.Add(new WeekDay(DayOfWeek.Monday, FrequencyOccurrence.First));
evt.RecurrenceRules.Add(rp3);
/*
Note that all events occur on their start time, no matter their
recurrence pattern. So, for example, you could occur on the first Monday
of every month, but if your event is scheduled for a Friday (i.e.
evt.Start = new iCalDateTime(2008, 3, 7, 18, 0, 0)), then it will first
occur on that Friday, and then the first Monday of every month after
that.
this can be worked around by doing this:
IPeriod nextOccurrence = pattern.GetNextOccurrence(dt);
evt.Start = nextOccurrence.StartTime;
*/
}
示例6: RecurrenceForm
public RecurrenceForm(RecurrencePattern pattern, RecurrenceRange range)
{
InitializeComponent();
StringBuilder dow = new StringBuilder();
int n = dgRecurrencePattern.Rows.Add();
dgRecurrencePattern.Rows[n].Cells[0].Value = pattern.Type;
dgRecurrencePattern.Rows[n].Cells[1].Value = pattern.Interval;
dgRecurrencePattern.Rows[n].Cells[2].Value = pattern.DayOfMonth;
dgRecurrencePattern.Rows[n].Cells[3].Value = pattern.Month;
foreach (var item in pattern.DaysOfWeek)
{
dow.Append(item + "-");
}
dgRecurrencePattern.Rows[n].Cells[4].Value = dow;
dgRecurrencePattern.Rows[n].Cells[5].Value = pattern.FirstDayOfWeek;
dgRecurrencePattern.Rows[n].Cells[6].Value = pattern.Index;
int x = dgRecurrenceRange.Rows.Add();
dgRecurrenceRange.Rows[n].Cells[0].Value = range.Type;
dgRecurrenceRange.Rows[n].Cells[1].Value = range.StartDate;
dgRecurrenceRange.Rows[n].Cells[2].Value = range.EndDate;
dgRecurrenceRange.Rows[n].Cells[3].Value = range.NumberOfOccurrences;
dgRecurrenceRange.Rows[n].Cells[4].Value = range.RecurrenceTimeZone;
}
示例7: TickRRule
public TickRRule(string iCalString)
{
if (iCalString.Contains(TT_COMPLETED_COUNT_KEY))
{
//CompletedRepeatCount = RepeatUtils.GetIntFromRRule(TT_COMPLETED_COUNT_KEY, iCalString);
//iCalString = RepeatUtils.RemoveKeyValueFromRRule(TT_COMPLETED_COUNT_KEY, iCalString);
}
String iCal;
if (iCalString.Contains(LUNAR_RRULE_NAME))
{
iCal = iCalString.Replace(LUNAR_RRULE_NAME, RRULE_NAME);
IsLunar = true;
}
else
{
iCal = iCalString;
IsLunar = false;
}
//rRule = new RRule(iCal);
//RecurringComponent = new DDay.iCal.RecurringComponent();
RRule = new RecurrencePattern();
//RRule = new RecurrencePattern(iCal);
//RecurringComponent.RecurrenceRules.Add(RRule);
}
示例8: PopulateiCalTimeZoneInfo
static private void PopulateiCalTimeZoneInfo(ITimeZoneInfo tzi, System.TimeZoneInfo.TransitionTime transition, int year)
{
Calendar c = CultureInfo.CurrentCulture.Calendar;
RecurrencePattern recurrence = new RecurrencePattern();
recurrence.Frequency = FrequencyType.Yearly;
recurrence.ByMonth.Add(transition.Month);
recurrence.ByHour.Add(transition.TimeOfDay.Hour);
recurrence.ByMinute.Add(transition.TimeOfDay.Minute);
if (transition.IsFixedDateRule)
{
recurrence.ByMonthDay.Add(transition.Day);
}
else
{
if( transition.Week != 5 )
recurrence.ByDay.Add(new WeekDay(transition.DayOfWeek, transition.Week ));
else
recurrence.ByDay.Add( new WeekDay( transition.DayOfWeek, -1 ) );
}
tzi.RecurrenceRules.Add(recurrence);
}
示例9: ConvertToRecurrencePattern
public override RecurrencePattern ConvertToRecurrencePattern()
{
RecurrencePattern pattern = new RecurrencePattern();
pattern.Frequency = RecurrenceFrequency.Yearly;
pattern.DayOrdinal = DayOfWeekIndexConverter.ConvertToDayOrdinal(DayOfWeekIndex);
pattern.DaysOfWeekMask = DaysOfWeekStringConverter.ConvertToRecurrenceDay(DaysOfWeek);
pattern.Month = (RecurrenceMonth) Enum.Parse(typeof(RecurrenceMonth), Month.ToString());
return pattern;
}
示例10: CountToUntilReplace
/// <summary>
/// Counts to until replace. For recurrence pattern
/// </summary>
/// <param name="dtStart">The dt start.</param>
/// <param name="until">The until.</param>
/// <param name="rpattern">The rpattern.</param>
private static void CountToUntilReplace(iCalDateTime dtStart, iCalDateTime until, RecurrencePattern pattern)
{
//COUNT is specified
if (pattern.Count > 0)
{
List<iCalDateTime> occurs = pattern.Evaluate(dtStart, dtStart, until);
if (occurs.Count != 0 && occurs[occurs.Count - 1] >= until)
{
//Remove COUNT
pattern.Count = int.MinValue;
pattern.Until = until;
}
}
else
{
pattern.Until = until;
}
}
示例11: Test2
public void Test2()
{
IICalendar iCal = new iCalendar();
IEvent evt = iCal.Create<Event>();
evt.Summary = "Event summary";
evt.Start = new iCalDateTime(DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc));
IRecurrencePattern recur = new RecurrencePattern();
recur.Frequency = FrequencyType.Daily;
recur.Count = 3;
recur.ByDay.Add(new WeekDay(DayOfWeek.Monday));
recur.ByDay.Add(new WeekDay(DayOfWeek.Wednesday));
recur.ByDay.Add(new WeekDay(DayOfWeek.Friday));
evt.RecurrenceRules.Add(recur);
RecurrencePatternSerializer serializer = new RecurrencePatternSerializer();
Assert.IsTrue(string.Compare(serializer.SerializeToString(recur), "FREQ=DAILY;COUNT=3;BYDAY=MO,WE,FR") == 0,
"Serialized recurrence string is incorrect");
}
示例12: Test4
public void Test4()
{
IRecurrencePattern rpattern = new RecurrencePattern();
rpattern.ByDay.Add(new WeekDay(DayOfWeek.Saturday));
rpattern.ByDay.Add(new WeekDay(DayOfWeek.Sunday));
rpattern.Frequency = FrequencyType.Weekly;
IDateTime evtStart = new iCalDateTime(2006, 12, 1);
IDateTime evtEnd = new iCalDateTime(2007, 1, 1);
IEvaluator evaluator = rpattern.GetService(typeof(IEvaluator)) as IEvaluator;
Assert.IsNotNull(evaluator);
// Add the exception dates
IList<IPeriod> periods = evaluator.Evaluate(
evtStart,
DateUtil.GetSimpleDateTimeData(evtStart),
DateUtil.SimpleDateTimeToMatch(evtEnd, evtStart),
false);
Assert.AreEqual(10, periods.Count);
Assert.AreEqual(2, periods[0].StartTime.Day);
Assert.AreEqual(3, periods[1].StartTime.Day);
Assert.AreEqual(9, periods[2].StartTime.Day);
Assert.AreEqual(10, periods[3].StartTime.Day);
Assert.AreEqual(16, periods[4].StartTime.Day);
Assert.AreEqual(17, periods[5].StartTime.Day);
Assert.AreEqual(23, periods[6].StartTime.Day);
Assert.AreEqual(24, periods[7].StartTime.Day);
Assert.AreEqual(30, periods[8].StartTime.Day);
Assert.AreEqual(31, periods[9].StartTime.Day);
}
示例13: RecurrencePattern2
public void RecurrencePattern2()
{
// NOTE: evaluators are generally not meant to be used directly like this.
// However, this does make a good test to ensure they behave as they should.
RecurrencePattern pattern = new RecurrencePattern("FREQ=MINUTELY;INTERVAL=1");
CultureInfo us = CultureInfo.CreateSpecificCulture("en-US");
iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/31/2008 12:00:10 AM", us));
iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:08:10 AM", us));
iCalDateTime toDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:43:23 AM", us));
IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator;
Assert.IsNotNull(evaluator);
IList<IPeriod> occurrences = evaluator.Evaluate(
startDate,
DateUtil.SimpleDateTimeToMatch(fromDate, startDate),
DateUtil.SimpleDateTimeToMatch(toDate, startDate),
false);
Assert.AreNotEqual(0, occurrences.Count);
}
示例14: Test1
public void Test1()
{
IICalendar iCal = new iCalendar();
IEvent evt = iCal.Create<Event>();
evt.Summary = "Event summary";
evt.Start = new iCalDateTime(DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc));
IRecurrencePattern recur = new RecurrencePattern();
evt.RecurrenceRules.Add(recur);
try
{
IList<Occurrence> occurrences = evt.GetOccurrences(DateTime.Today.AddDays(1), DateTime.Today.AddDays(2));
Assert.Fail("An exception should be thrown when evaluating a recurrence with no specified FREQUENCY");
}
catch { }
}
示例15: RecurrencePattern1
public void RecurrencePattern1()
{
// NOTE: evaluators are not generally meant to be used directly like this.
// However, this does make a good test to ensure they behave as they should.
IRecurrencePattern pattern = new RecurrencePattern("FREQ=SECONDLY;INTERVAL=10");
pattern.RestrictionType = RecurrenceRestrictionType.NoRestriction;
CultureInfo us = CultureInfo.CreateSpecificCulture("en-US");
iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us));
iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us));
iCalDateTime toDate = new iCalDateTime(DateTime.Parse("3/31/08 12:00:11 AM", us));
IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator;
Assert.IsNotNull(evaluator);
IList<IPeriod> occurrences = evaluator.Evaluate(
startDate,
DateUtil.SimpleDateTimeToMatch(fromDate, startDate),
DateUtil.SimpleDateTimeToMatch(toDate, startDate),
false);
Assert.AreEqual(4, occurrences.Count);
Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:40 PM", us)), occurrences[0].StartTime);
Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:50 PM", us)), occurrences[1].StartTime);
Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:00 AM", us)), occurrences[2].StartTime);
Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:10 AM", us)), occurrences[3].StartTime);
}