MmsCore.Calendar provides a business calendar that excludes holidays and specific dates. It offers features to exclude weekdays or weekends, add specific excluded dates, get the next or previous business day, calculate the number of business days within a specified period, and get the date after a specified number of business days. This allows users to customise the calendar according to their business needs.
$ dotnet add package MmsCore.Calendar[!IMPORTANT] This Project is not yet stable. Breaking changes may occur at any time.
MmsCore.Calendarは、祝日や特定日を除外したビジネスカレンダーを提供します。MmsCore.Calendarでは、平日や土日を除外する機能、特定の除外日を追加する機能、翌営業日や前営業日を取得する機能、指定した期間内の営業日数を計算する機能、指定した営業日数後の日付を取得する機能などを提供しています。これにより、ユーザーはビジネスニーズに応じてカレンダーをカスタマイズすることができます。
AddBusinessDaysAddBusinessDays を使用して週末を除いた営業日を加算する方法の例です。
var calendar = new BusinessCalendar(excludeWeekends: true);
var startDate = new DateOnly(2023, 4, 10); // Monday
var resultDate = calendar.AddBusinessDays(startDate, 5);
Assert.Equal(new DateOnly(2023, 4, 17), resultDate);
AddBusinessDays (for subtraction)AddBusinessDays を使用して週末を除いた営業日を減算する方法の例です。
var calendar = new BusinessCalendar(excludeWeekends: true);
var startDate = new DateOnly(2023, 4, 10); // Monday
var resultDate = calendar.AddBusinessDays(startDate, -3); // Subtract 3 business days
Assert.Equal(new DateOnly(2023, 4, 5), resultDate);
GetNextBusinessDayGetNextBusinessDay を使用して、週末を除いた次の営業日を取得する方法の例です。
var calendar = new BusinessCalendar(excludeWeekends: true);
var startDate = new DateOnly(2023, 4, 7); // Friday
var resultDate = calendar.GetNextBusinessDay(startDate); // Skip Saturday and Sunday
Assert.Equal(new DateOnly(2023, 4, 10), resultDate);
GetPreviousBusinessDayGetPreviousBusinessDay を使用して、週末を除いた前の営業日を取得する方法の例です。
var calendar = new BusinessCalendar(excludeWeekends: true);
var givenDate = new DateOnly(2023, 4, 10); // Monday
var resultDate = calendar.GetPreviousBusinessDay(givenDate);
Assert.Equal(new DateOnly(2023, 4, 7), resultDate);
AddExcludedDate特定の日付を除外するために AddExcludedDay を使用する方法の例です。
var calendar = new BusinessCalendar();
calendar.ExcludeWeekends(); // Exclude weekends.
var startDate = new DateOnly(2023, 4, 1); // Saturday
var excludedDate = new DateOnly(2023, 4, 3); // Monday
calendar.AddExcludedDay(excludedDate); // Exclude specific date.
var resultDate = calendar.AddBusinessDays(startDay, 1); // Skip Sunday and Monday
Assert.Equal(new DateOnly(2023, 4, 4), result);
CalculateBusinessDays開始日と終了日を含む、2つの日付間の営業日数を計算するために CalculateBusinessDays を使用する方法の例です。
var calendar = new BusinessCalendar();
calendar.ExcludeWeekends(); // Exclude weekends.
var startDate = new DateOnly(2023, 4, 10); // Monday
var endDate = new DateOnly(2023, 4, 17); // Monday
var businessDays = calendar.CalculateBusinessDays(startDate, endDate, includeStartDate: true, includeEndDate: true);
Assert.Equal(7, businessDays); // Expected result: Monday, Tuesday, Wednesday, Thursday, Friday, Monday, Monday