< Summary

Information
Class: ValidateLib.TabularData.Datatypes.DateDatatypes.TimeDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\DateDatatypes\TimeDT.cs
Line coverage
72%
Covered lines: 18
Uncovered lines: 7
Coverable lines: 25
Total lines: 53
Line coverage: 72%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
TimeDT()20
TimeDT(...)60
TimeDT(...)131
CheckLexicalSpace(...)40
CompareTo(...)09

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\DateDatatypes\TimeDT.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2using System.Xml;
 3using ValidateLib.ErrorsAndWarnings.Errors;
 4using ValidateLib.Metadata.Descriptors;
 5
 6namespace ValidateLib.TabularData.Datatypes.DateDatatypes
 7{
 8    // Does not support 24:00:00...
 9    public class TimeDT : DateBaseDT
 10    {
 111        public TimeDT() { }
 112        public DateTime Value { get; set; }
 113        public TimeDT(string stringValue) : base(stringValue, new FormatDescriptor())
 14        {
 115            CheckLexicalSpace(stringValue);
 116            Value = XmlConvert.ToDateTime(stringValue, XmlDateTimeSerializationMode.RoundtripKind);
 17
 118        }
 19
 120        public TimeDT(string stringValue, FormatDescriptor format) : base(stringValue, format)
 21        {
 122            this.format = format;
 123            stringValue = NormalizeStringValueToZZZ(stringValue, format.pattern!);
 124            var modifiedPattern = format.pattern!.Replace('S', 'f');
 125            modifiedPattern = NormalizeFormatToZZZ(modifiedPattern);
 26
 127            if (!isPatternValid(format.pattern))
 028                ErrorFactory.ThrowInvalidFormatError(modifiedPattern);
 29
 130            Value = XmlConvert.ToDateTime(stringValue, modifiedPattern);
 31
 32
 133        }
 34
 35        void CheckLexicalSpace(string stringValue)
 36        {
 137            string pattern = @"((([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?)|(24:00:00(\.0+)?)|(Z|(\+|-)((0[0-9
 138            if (!Regex.IsMatch(stringValue, pattern))
 139                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 140        }
 41
 42        override public int CompareTo(BaseDT? other)
 43        {
 044            if (other is null)
 045                return 1;
 046            if (other is not TimeDT)
 047                throw new ArgumentException();
 048            var typedOther = (TimeDT)other;
 049            return Value.CompareTo(typedOther.Value);
 50
 51        }
 52    }
 53}