| | | 1 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | | 2 | | using ValidateLib.Metadata.Descriptors; |
| | | 3 | | |
| | | 4 | | namespace ValidateLib.TabularData.Datatypes.DateDatatypes |
| | | 5 | | { |
| | | 6 | | public class DateTimeDT : DateBaseDT |
| | | 7 | | { |
| | 1 | 8 | | public virtual string DefaultFormatDateTime { get; } = "yyyy-MM-ddTHH:mm:sszzz"; |
| | 1 | 9 | | public DateTimeOffset Value { get; set; } |
| | 1 | 10 | | public DateTimeDT() { } |
| | 1 | 11 | | public DateTimeDT(string StringValue, FormatDescriptor format) : base(StringValue, format) |
| | | 12 | | { |
| | | 13 | | try |
| | | 14 | | { |
| | 1 | 15 | | if (format.pattern is null) |
| | | 16 | | { |
| | 1 | 17 | | stringValue = NormalizeStringValueToZZZ(StringValue, null); |
| | 1 | 18 | | Value = DateTimeOffset.ParseExact(stringValue, DefaultFormatDateTime, null); |
| | | 19 | | } |
| | | 20 | | else |
| | | 21 | | { |
| | | 22 | | |
| | 1 | 23 | | stringValue = NormalizeStringValueToZZZ(StringValue, format.pattern!); |
| | 1 | 24 | | var modifiedPattern = format.pattern!.Replace('S', 'f'); |
| | 1 | 25 | | modifiedPattern = NormalizeFormatToZZZ(modifiedPattern); |
| | | 26 | | |
| | 1 | 27 | | if (!isPatternValid(format.pattern)) |
| | 0 | 28 | | ErrorFactory.ThrowInvalidFormatError(modifiedPattern); |
| | | 29 | | |
| | | 30 | | |
| | 1 | 31 | | Value = DateTimeOffset.ParseExact(stringValue, modifiedPattern, null); |
| | | 32 | | } |
| | | 33 | | |
| | 1 | 34 | | } |
| | 1 | 35 | | catch (Exception) |
| | | 36 | | { |
| | 1 | 37 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| | 0 | 38 | | } |
| | 1 | 39 | | } |
| | | 40 | | |
| | | 41 | | override public int CompareTo(BaseDT? other) |
| | | 42 | | { |
| | 1 | 43 | | if (other is null) |
| | 0 | 44 | | return 1; |
| | 1 | 45 | | if (other is not DateTimeDT) |
| | 0 | 46 | | throw new ArgumentException(); |
| | 1 | 47 | | var typedOther = (DateTimeDT)other; |
| | 1 | 48 | | return Value.CompareTo(typedOther.Value); |
| | | 49 | | |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |