< Summary

Information
Class: MyNet.Primitives.Temporal.DateTimeHelper
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Temporal/DateTimeHelper.cs
Tag: 323_28699572109
Line coverage
14%
Covered lines: 1
Uncovered lines: 6
Coverable lines: 7
Total lines: 58
Line coverage: 14.2%
Branch coverage
16%
Covered branches: 1
Total branches: 6
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetCurrentDateTimeFormatInfo()16.66%29614.28%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Temporal/DateTimeHelper.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeHelper.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Globalization;
 8using System.Linq;
 9
 10namespace MyNet.Primitives.Temporal;
 11
 12/// <summary>
 13/// Helper class for DateTime operations.
 14/// </summary>
 15public static class DateTimeHelper
 16{
 17    /// <summary>
 18    /// Defines the number of days in a week, and the maximum and minimum number of weeks in a month.
 19    /// </summary>
 20    public const int DaysPerWeek = 7;
 21
 22    /// <summary>
 23    /// Defines the average number of days in a year and a month. The average number of days in a year is calculated bas
 24    /// </summary>
 25    public const double DaysPerYear = 365.2425; // see https://en.wikipedia.org/wiki/Gregorian_calendar
 26
 27    /// <summary>
 28    /// Defines the average number of days in a month, calculated by dividing the average number of days in a year by 12
 29    /// </summary>
 30    public const double DaysPerMonth = DaysPerYear / 12;
 31
 32    /// <summary>
 33    /// Defines the maximum and minimum number of weeks in a month. The maximum is 6 because some months can start on th
 34    /// </summary>
 35    public const int MaxNumberOfWeeksPerMonth = 6;
 36
 37    /// <summary>
 38    /// Defines the minimum number of weeks in a month. The minimum is 4 because some months can start on the first day 
 39    /// </summary>
 40    public const int MinNumberOfWeeksPerMonth = 4;
 41
 42    /// <summary>
 43    /// Gets the DateTimeFormatInfo for the current culture, ensuring that it uses a Gregorian calendar. If the current 
 44    /// </summary>
 45    /// <remarks>This method ensures that the returned DateTimeFormatInfo always uses a Gregorian calendar, which is use
 46    /// <returns>The DateTimeFormatInfo for the current culture, using a Gregorian calendar.</returns>
 47    public static DateTimeFormatInfo GetCurrentDateTimeFormatInfo()
 48    {
 649        if (CultureInfo.CurrentCulture.Calendar is GregorianCalendar) return CultureInfo.CurrentCulture.DateTimeFormat;
 050        Calendar? calendar =
 051            CultureInfo.CurrentCulture.OptionalCalendars.OfType<GregorianCalendar>().FirstOrDefault();
 052        var cultureName = calendar is null ? CultureInfo.InvariantCulture.Name : CultureInfo.CurrentCulture.Name;
 053        var dt = new CultureInfo(cultureName).DateTimeFormat;
 054        dt.Calendar = calendar ?? new GregorianCalendar();
 055        return dt;
 56    }
 57}
 58

Methods/Properties

GetCurrentDateTimeFormatInfo()