Summary

Class:FakeXrmEasy.Extensions.DateTimeExtensions
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\Extensions\DateTimeExtensions.cs
Covered lines:9
Uncovered lines:10
Coverable lines:19
Total lines:43
Line coverage:47.3%
Branch coverage:0%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
ToDayOfWeek(...)1100100
ToDayOfDeltaWeek(...)1100100
ToLastDayOfDeltaWeek(...)1100100
ToFirstDayOfDeltaWeek(...)1100100
ToFirstDayOfMonth(...)100
ToFirstDayOfMonth(...)100
ToLastDayOfMonth(...)300
ToLastDayOfMonth(...)100

File(s)

F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\Extensions\DateTimeExtensions.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace FakeXrmEasy.Extensions
 5{
 6    public static class DateTimeExtensions
 7    {
 8        public static DateTime ToDayOfWeek(this DateTime dateTime, Int32 week, DayOfWeek dayOfWeek)
 369        {
 3610            DateTime startOfYear = dateTime.AddDays(1 - dateTime.DayOfYear);
 3611            return startOfYear.AddDays(7 * (week - 2) + ((dayOfWeek - startOfYear.DayOfWeek + 7) % 7));
 3612        }
 13
 14        public static DateTime ToDayOfDeltaWeek(this DateTime dateTime, Int32 deltaWeek, DayOfWeek dayOfWeek)
 3615            => dateTime.ToDayOfWeek(CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime
 3616                , CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule
 3617                , CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek) + deltaWeek, dayOfWeek);
 18
 19        public static DateTime ToLastDayOfDeltaWeek(this DateTime dateTime, Int32 deltaWeek = 0)
 1820            => dateTime.ToDayOfDeltaWeek(deltaWeek, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek).AddDays(6)
 21
 22        public static DateTime ToFirstDayOfDeltaWeek(this DateTime dateTime, Int32 deltaWeek = 0)
 1823            => dateTime.ToDayOfDeltaWeek(deltaWeek, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
 24
 25        public static DateTime ToFirstDayOfMonth(this DateTime dateTime, Int32 month)
 026            => dateTime.AddDays(1 - dateTime.Day).AddMonths(month - dateTime.Month);
 27
 28        public static DateTime ToFirstDayOfMonth(this DateTime dateTime)
 029            => dateTime.ToFirstDayOfMonth(dateTime.Month);
 30
 31        public static DateTime ToLastDayOfMonth(this DateTime dateTime, Int32 month)
 032        {
 033             Int32 addYears = month > 12 ? month % 12 : 0;
 034            month = month - 12 * addYears;
 035            return dateTime
 036                .AddDays(CultureInfo.CurrentCulture.Calendar.GetDaysInMonth(dateTime.Year + addYears, month) - dateTime.
 037                .AddMonths(month - dateTime.Month).AddYears(addYears);
 038        }
 39
 40        public static DateTime ToLastDayOfMonth(this DateTime dateTime)
 041            => dateTime.ToLastDayOfMonth(dateTime.Month);
 42    }
 43}