| | 1 | | using System.Text.RegularExpressions; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | |
|
| | 5 | | namespace ValidateLib.TabularData.Datatypes.DateDatatypes |
| | 6 | | { |
| | 7 | |
|
| | 8 | | public class DateDT : DateTimeDT |
| | 9 | | { |
| 1 | 10 | | public override string DefaultFormatDateTime { get; } = "yyyy-MM-ddzzz"; |
| 1 | 11 | | public static string dateRegex = @"-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(Z|(\+|- |
| 1 | 12 | | public DateDT() { } |
| 1 | 13 | | public DateDT(string stringValue, FormatDescriptor format) : base(stringValue, format) |
| | 14 | | { |
| 1 | 15 | | if (format.pattern is not null) |
| | 16 | | { |
| 1 | 17 | | if (!isPatternValid(format.pattern)) |
| 1 | 18 | | ErrorFactory.ThrowInvalidFormatError(format.pattern); |
| | 19 | | } |
| 1 | 20 | | else CheckLexicalSpace(stringValue); |
| 1 | 21 | | } |
| | 22 | |
|
| | 23 | | public static void CheckLexicalSpace(string stringValue) |
| | 24 | | { |
| 1 | 25 | | if (!Regex.IsMatch(stringValue, dateRegex)) |
| 0 | 26 | | ErrorFactory.ThrowDatatypeValidationError(); |
| 1 | 27 | | } |
| | 28 | |
|
| | 29 | | new protected bool isPatternValid(string pattern) |
| | 30 | | { |
| 1 | 31 | | char[] forbiddenChars = new char[] |
| 1 | 32 | | { |
| 1 | 33 | | 'h', |
| 1 | 34 | | 'H', |
| 1 | 35 | | 'm', |
| 1 | 36 | | 's', |
| 1 | 37 | | 'S' |
| 1 | 38 | | }; |
| 1 | 39 | | foreach (var c in forbiddenChars) |
| 1 | 40 | | if (pattern.Contains(c)) |
| 1 | 41 | | return false; |
| | 42 | |
|
| 1 | 43 | | return true; |
| | 44 | | } |
| | 45 | | } |
| | 46 | | } |