.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
Hello, here is the first entry of my proposals for functionalities to import from my current CommonNET project to the Microsoft Community Toolkit, I hope you find it useful (and if not, nothing happens).
In case you need to take as a reference the start or end day of the week in the Gregorian calendar for a given date, also contemplating whether the start of the week is on Monday or Sunday.
This helps to determine ranges for a specific week, for example if you need to do specific logic on a calendar.
For example, I needed it to establish some business rules on a user, for a specific week given a date X.
In the case presented, I'm using DateTime, but of course can be also used from DateTimeOffset and/or DateOnly
API breakdown
namespace CommunityToolkit.Common;
public static class DateTimeExtensions
{
public static DateTime GetFirstWeekDate(this DateTime date, WeekCalendarType weekCalendarType = WeekCalendarType.MondayFirst)
{
//Logic
}
public static DateTime GetLastWeekDate(this DateTime date, WeekCalendarType weekCalendarType = WeekCalendarType.MondayFirst)
{
//Logic
}
}
Usage example
var givenDate = new DateTime(2021, 10, 18);
//By default in the proposal, starting on Monday
var initialDay = givenDate.GetFirstWeekDate();
var endDay = givenDate.GetLastWeekDate();
//In this case if week start on Sunday, however the default behaviour can be switched
var initialDay = givenDate.GetFirstWeekDate(WeekCalendarType.SundayFirst);
var endDay = givenDate.GetLastWeekDate(WeekCalendarType.SundayFirst);
Add as part of the boilerplate code in requiring project.
No current SDK implementation AFAIK.
Additional context
This is the first proposal of a series of implementations that I made during time in a common project used for the projects of my OpenSource organization, personal projects and projects of the company in which I work.
Currently, I would prefer to include what is practical in a repository with greater scope and practicality, and eliminate what is not necessary or could be improved, leaving the library in a state of maintenance without new developments.
Overview
Hello, here is the first entry of my proposals for functionalities to import from my current CommonNET project to the Microsoft Community Toolkit, I hope you find it useful (and if not, nothing happens).
In case you need to take as a reference the start or end day of the week in the Gregorian calendar for a given date, also contemplating whether the start of the week is on Monday or Sunday.
This helps to determine ranges for a specific week, for example if you need to do specific logic on a calendar.
For example, I needed it to establish some business rules on a user, for a specific week given a date X.
In the case presented, I'm using DateTime, but of course can be also used from DateTimeOffset and/or DateOnly
API breakdown
Usage example
Examples in current test case file here
Breaking change?
No
Alternatives
Add as part of the boilerplate code in requiring project.
No current SDK implementation AFAIK.
Additional context
This is the first proposal of a series of implementations that I made during time in a common project used for the projects of my OpenSource organization, personal projects and projects of the company in which I work.
Currently, I would prefer to include what is practical in a repository with greater scope and practicality, and eliminate what is not necessary or could be improved, leaving the library in a state of maintenance without new developments.
Please refer to this project
Help us help you
Yes, I'd like to be assigned to work on this item