< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.Infrastructure.Core.HijriText
Assembly: ZhEaIsNsAaBn.Infrastructure.Core
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/EFValueConverters/HijriText.cs
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 56
Line coverage: 91.6%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Format(...)100%22100%
Parse(...)75%5466.66%
HijriFormat(...)100%44100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/EFValueConverters/HijriText.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.Infrastructure.Core;
 2
 3/// <summary>
 4/// Hijri column text shared by the Hijri converters: written as <c>yyyy-MM-dd</c> or 24-hour <c>yyyy-MM-dd HH:mm:ss</c>
 5/// invariant separators; read in those forms and in the old 12-hour <c>yyyy-MM-dd hh:mm:ss tt</c> form (<c>ص</c>/<c>م</
 6/// </summary>
 7internal static class HijriText
 8{
 9    /// <summary>Length of the date-only text.</summary>
 10    internal const int DateLength = 10;
 11
 12    /// <summary>Length of the date-and-time text.</summary>
 13    internal const int DateTimeLength = 19;
 14
 15    private const string DateFormat     = "yyyy'-'MM'-'dd";
 16    private const string DateTimeFormat = "yyyy'-'MM'-'dd HH':'mm':'ss";
 17
 418    private static readonly string[] _readFormats = [ DateTimeFormat, "yyyy'-'MM'-'dd hh':'mm':'ss tt", DateFormat ];
 19
 420    private static readonly DateTimeFormatInfo _arabicDesignators = HijriFormat( null, null );
 421    private static readonly DateTimeFormatInfo _latinDesignators  = HijriFormat( "AM", "PM" );
 22
 23
 24    /// <summary>Formats <paramref name="date"/> for the column.</summary>
 4025    internal static string Format( HijriDate date, bool withTime ) => date.ToString( withTime ? DateTimeFormat : DateFor
 26
 27    /// <summary>Reads column text written by any version of the converters.</summary>
 28    /// <exception cref="HijriDateException"><paramref name="text"/> isn't a supported Hijri date.</exception>
 29    internal static HijriDate Parse( string text )
 30    {
 20031        foreach ( var format in new[] { _arabicDesignators, _latinDesignators } )
 32        {
 13233            if ( DateTime.TryParseExact( text, _readFormats, format, DateTimeStyles.AllowWhiteSpaces, out var parsed ) )
 34        }
 35
 36
 037        return new HijriDate( text, isHijri: true );
 38    }
 39
 40
 41    private static DateTimeFormatInfo HijriFormat( string? am, string? pm )
 42    {
 843        var format = (DateTimeFormatInfo) CultureInfo.GetCultureInfo( "ar-SA" ).DateTimeFormat.Clone();
 44
 845        format.Calendar = new HijriCalendar();
 46
 47
 1248        if ( am is not null ) { format.AMDesignator = am; }
 49
 50
 1251        if ( pm is not null ) { format.PMDesignator = pm; }
 52
 53
 854        return format;
 55    }
 56}