Skip to content

Commit

Permalink
add - doc - Made RecurrenceRule more public
Browse files Browse the repository at this point in the history
---

We've finally added properties to the recurrence rule instance.

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 30, 2024
1 parent 15041ef commit 6fb7c8e
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 1 deletion.
172 changes: 172 additions & 0 deletions VisualCard.Calendar/Parsers/Recurrence/RecurrenceRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace VisualCard.Calendar.Parsers.Recurrence
{
/// <summary>
/// Recurrence rule instance
/// </summary>
[DebuggerDisplay("RecurRule (v{Version}, {Frequency}) | I: {Interval}, D: {Duration}")]
public class RecurrenceRule
{
// Frequency and interval
Expand All @@ -36,6 +38,36 @@ public class RecurrenceRule
internal int duration = 2;
internal DateTimeOffset endDate;

/// <summary>
/// Rule version
/// </summary>
public Version Version =>
ruleVersion;

/// <summary>
/// Indicates the frequency of the rule
/// </summary>
public RecurrenceRuleFrequency Frequency =>
frequency;

/// <summary>
/// Repeat frequency
/// </summary>
public int Interval =>
interval;

/// <summary>
/// Number of occurrences that this rule generates
/// </summary>
public int Duration =>
duration;

/// <summary>
/// Specifies whether this date is the last time to repeat
/// </summary>
public DateTimeOffset EndDate =>
endDate;

#region Version 1.0 rules
// Time period (daily)
internal List<(bool isEnd, TimeSpan time)> timePeriods = [];
Expand All @@ -50,6 +82,62 @@ public class RecurrenceRule
// Yearly (in a month and in a day)
internal List<(bool isEnd, int monthNum)> yearlyMonthNumbers = [];
internal List<(bool isEnd, int dayNum)> yearlyDayNumbers = [];

/// <summary>
/// Time periods for daily frequency (<see cref="RecurrenceRuleFrequency.Daily"/>). isEnd indicates the end
/// marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, seconds list (<see cref="V2Seconds"/>), minutes list, and/or hours list is equivalent to this property.
/// </remarks>
public (bool isEnd, TimeSpan time)[] V1TimePeriods =>
[.. timePeriods];

/// <summary>
/// Days of week for weekly frequency (<see cref="RecurrenceRuleFrequency.Weekly"/>). isEnd indicates the end
/// marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, days list is equivalent to this property.
/// </remarks>
public (bool isEnd, DayOfWeek time)[] V1DayTimes =>
[.. dayTimes];

/// <summary>
/// Monthly occurrences (<see cref="RecurrenceRuleFrequency.MonthlyPos"/>). isEnd indicates the end marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, positions list is equivalent to this property.
/// </remarks>
public (bool isEnd, (int occurrence, bool negative))[] V1MonthlyOccurrences =>
[.. monthlyOccurrences];

/// <summary>
/// Monthly by day numbers (<see cref="RecurrenceRuleFrequency.MonthlyDay"/>). isEnd indicates the end marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, days of month list is equivalent to this property.
/// </remarks>
public (bool isEnd, (int dayNum, bool negative, bool isLastDay))[] V1MonthlyDayNumbers =>
[.. monthlyDayNumbers];

/// <summary>
/// Yearly by month numbers (<see cref="RecurrenceRuleFrequency.YearlyMonth"/>). isEnd indicates the end marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, months list is equivalent to this property.
/// </remarks>
public (bool isEnd, int monthNum)[] V1YearlyMonthNumbers =>
[.. yearlyMonthNumbers];

/// <summary>
/// Yearly by day numbers (<see cref="RecurrenceRuleFrequency.YearlyDay"/>). isEnd indicates the end marker.
/// </summary>
/// <remarks>
/// For v2.0 recurrence rules, days of year list is equivalent to this property.
/// </remarks>
public (bool isEnd, int dayNum)[] V1YearlyDayNumbers =>
[.. yearlyDayNumbers];
#endregion

#region Version 2.0 rules
Expand All @@ -63,6 +151,90 @@ public class RecurrenceRule
internal List<int> monthsList = [];
internal List<(bool negative, int position)> positionsList = [];
internal DayOfWeek weekStart = DayOfWeek.Sunday;

/// <summary>
/// A day that defines the start of the week.
/// </summary>
public DayOfWeek StartWeekday =>
weekStart;

/// <summary>
/// List of seconds (<see cref="RecurrenceRuleFrequency.Second"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, time period list (<see cref="V1TimePeriods"/>) is equivalent to this property.
/// </remarks>
public int[] V2Seconds =>
[.. secondsList];

/// <summary>
/// List of minutes (<see cref="RecurrenceRuleFrequency.Minute"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, time period list (<see cref="V1TimePeriods"/>) is equivalent to this property.
/// </remarks>
public int[] V2Minutes =>
[.. minutesList];

/// <summary>
/// List of hours (<see cref="RecurrenceRuleFrequency.Hourly"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, time period list (<see cref="V1TimePeriods"/>) is equivalent to this property.
/// </remarks>
public int[] V2Hours =>
[.. hoursList];

/// <summary>
/// List of days (<see cref="RecurrenceRuleFrequency.Daily"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, day time list (<see cref="V1DayTimes"/>) is equivalent to this property.
/// </remarks>
public (bool negative, int weekNum, DayOfWeek time)[] V2Days =>
[.. daysList];

/// <summary>
/// List of days of month (<see cref="RecurrenceRuleFrequency.Monthly"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, monthly days list (<see cref="V1MonthlyDayNumbers"/>) is equivalent to this property.
/// </remarks>
public (bool negative, int dayOfMonth)[] V2MonthlyDays =>
[.. daysOfMonthList];

/// <summary>
/// List of days of year (<see cref="RecurrenceRuleFrequency.Yearly"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, yearly days list (<see cref="V1YearlyDayNumbers"/>) is equivalent to this property.
/// </remarks>
public (bool negative, int dayOfYear)[] V2YearlyDays =>
[.. daysOfYearList];

/// <summary>
/// List of week numbers.
/// </summary>
public (bool negative, int weekNum)[] V2WeekNumbers =>
[.. weeksList];

/// <summary>
/// List of month numbers (<see cref="RecurrenceRuleFrequency.Yearly"/>).
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, yearly months list (<see cref="V1YearlyMonthNumbers"/>) is equivalent to this property.
/// </remarks>
public int[] V2MonthNumbers =>
[.. monthsList];

/// <summary>
/// List of positions.
/// </summary>
/// <remarks>
/// For v1.0 recurrence rules, monthly occurrence list (<see cref="V1MonthlyOccurrences"/>) is almost equivalent to this property.
/// </remarks>
public (bool negative, int position)[] V2Positions =>
[.. positionsList];
#endregion
}
}
3 changes: 2 additions & 1 deletion VisualCard/Parsers/VcardCommonTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static DateTimeOffset ParsePosixDate(string posixDateRepresentation, bool
throw new ArgumentException($"Date representation is not provided.");

// Now, check the representation
if (DateTimeOffset.TryParseExact(posixDateRepresentation, dateOnly ? supportedDateFormats : supportedDateTimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var date))
bool assumeUtc = posixDateRepresentation[posixDateRepresentation.Length - 1] == 'Z';
if (DateTimeOffset.TryParseExact(posixDateRepresentation, dateOnly ? supportedDateFormats : supportedDateTimeFormats, CultureInfo.InvariantCulture, assumeUtc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal, out var date))
return date;
throw new ArgumentException($"Can't parse date {posixDateRepresentation}");
}
Expand Down

0 comments on commit 6fb7c8e

Please sign in to comment.