-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from rianjs/ByWeekNo
BYWEEKNO & BYMONTH fix & ISO 8601 week number fix
- Loading branch information
Showing
3 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Ical.Net | ||
{ | ||
public static class CalendarExtensions | ||
{ | ||
/// <summary> | ||
/// https://blogs.msdn.microsoft.com/shawnste/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net/ | ||
/// </summary> | ||
public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calendar, DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek) | ||
{ | ||
// Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll | ||
// be the same week# as whatever Thursday, Friday or Saturday are, | ||
// and we always get those right | ||
var day = calendar.GetDayOfWeek(time); | ||
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday) | ||
{ | ||
time = time.AddDays(3); | ||
} | ||
|
||
// Return the week of our adjusted day | ||
return calendar.GetWeekOfYear(time, rule, firstDayOfWeek); | ||
} | ||
} | ||
} |
This file contains 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