-
Notifications
You must be signed in to change notification settings - Fork 247
Replace DateTime with CalDateTime in RecurrencePatternEvaluator and related code
#742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| using System; | ||
| using System.Globalization; | ||
| using Ical.Net.DataTypes; | ||
|
|
||
| namespace Ical.Net; | ||
|
|
||
|
|
@@ -13,7 +14,7 @@ public static class CalendarExtensions | |
| /// <summary> | ||
| /// Calculate the week number according to ISO.8601, as required by RFC 5545. | ||
| /// </summary> | ||
| public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calendar, DateTime time, DayOfWeek firstDayOfWeek) | ||
| public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calendar, CalDateTime time, DayOfWeek firstDayOfWeek) | ||
axunonb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // A week is defined as a | ||
| // seven day period, starting on the day of the week defined to be | ||
|
|
@@ -24,7 +25,7 @@ public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calend | |
| // We add 3 to make sure the test date is in the 'right' year, because | ||
| // otherwise we might end up with week 53 in a year that only has 52. | ||
| var tTest = GetStartOfWeek(time, firstDayOfWeek).AddDays(3); | ||
| var res = calendar.GetWeekOfYear(tTest, CalendarWeekRule.FirstFourDayWeek, firstDayOfWeek); | ||
| var res = calendar.GetWeekOfYear(tTest.Value, CalendarWeekRule.FirstFourDayWeek, firstDayOfWeek); | ||
|
|
||
| return res; | ||
| } | ||
|
|
@@ -33,7 +34,7 @@ public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calend | |
| /// Calculate and return the date that represents the first day of the week the given date is | ||
| /// in, according to the week numbering required by RFC 5545. | ||
| /// </summary> | ||
| private static DateTime GetStartOfWeek(this DateTime t, DayOfWeek firstDayOfWeek) | ||
| private static CalDateTime GetStartOfWeek(this CalDateTime t, DayOfWeek firstDayOfWeek) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also be DateOnly
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| { | ||
| var t0 = ((int) firstDayOfWeek) % 7; | ||
| var tn = ((int) t.DayOfWeek) % 7; | ||
|
|
@@ -49,7 +50,7 @@ private static DateTime GetStartOfWeek(this DateTime t, DayOfWeek firstDayOfWeek | |
| /// E.g. for `2019-12-31` with first day of the week being Monday, the method will return 2020, | ||
| /// because the week that contains `2019-12-31` is the first week of 2020. | ||
| /// </remarks> | ||
| public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calendar, DateTime time, DayOfWeek firstDayOfWeek) | ||
| public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calendar, CalDateTime time, DayOfWeek firstDayOfWeek) | ||
| { | ||
| var year = time.Year; | ||
| if ((time.Month >= 12) && (calendar.GetIso8601WeekOfYear(time, firstDayOfWeek) == 1)) | ||
|
|
@@ -66,7 +67,7 @@ public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calend | |
| public static int GetIso8601WeeksInYear(this System.Globalization.Calendar calendar, int year, DayOfWeek firstDayOfWeek) | ||
| { | ||
| // The last week of the year is the week that contains the 4th-last day of the year (which is the 28th of December in Gregorian Calendar). | ||
| var testTime = new DateTime(year + 1, 1, 1, 0, 0, 0, DateTimeKind.Unspecified).AddDays(-4); | ||
| var testTime = new CalDateTime(year + 1, 1, 1, 0, 0, 0, null).AddDays(-4); | ||
| return calendar.GetIso8601WeekOfYear(testTime, firstDayOfWeek); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.