< Summary

Information
Class: ValidateLib.TabularData.Datatypes.DateDatatypes.DateTimeDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\DateDatatypes\DateTimeDT.cs
Line coverage
83%
Covered lines: 20
Uncovered lines: 4
Coverable lines: 24
Total lines: 52
Line coverage: 83.3%
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
DateTimeDT()20
DateTimeDT(...)262
CompareTo(...)63

File(s)

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

#LineLine coverage
 1using ValidateLib.ErrorsAndWarnings.Errors;
 2using ValidateLib.Metadata.Descriptors;
 3
 4namespace ValidateLib.TabularData.Datatypes.DateDatatypes
 5{
 6    public class DateTimeDT : DateBaseDT
 7    {
 18        public virtual string DefaultFormatDateTime { get; } = "yyyy-MM-ddTHH:mm:sszzz";
 19        public DateTimeOffset Value { get; set; }
 110        public DateTimeDT() { }
 111        public DateTimeDT(string StringValue, FormatDescriptor format) : base(StringValue, format)
 12        {
 13            try
 14            {
 115                if (format.pattern is null)
 16                {
 117                    stringValue = NormalizeStringValueToZZZ(StringValue, null);
 118                    Value = DateTimeOffset.ParseExact(stringValue, DefaultFormatDateTime, null);
 19                }
 20                else
 21                {
 22
 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
 30
 131                    Value = DateTimeOffset.ParseExact(stringValue, modifiedPattern, null);
 32                }
 33
 134            }
 135            catch (Exception)
 36            {
 137                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 038            }
 139        }
 40
 41        override public int CompareTo(BaseDT? other)
 42        {
 143            if (other is null)
 044                return 1;
 145            if (other is not DateTimeDT)
 046                throw new ArgumentException();
 147            var typedOther = (DateTimeDT)other;
 148            return Value.CompareTo(typedOther.Value);
 49
 50        }
 51    }
 52}