Closed zgsxtyzgd closed 4 years ago
in source code 115 row UTC is not quite right, should be: `bool utc = false; // Parse the zone information (the default is UTC). if (match.Groups["zone"].Value != string.Empty) { utc = true; if (match.Groups["zone"].Value != "Z") { // Parse the numeric values. int zoneHours, zoneMinutes = 0; if (int.TryParse(match.Groups["zoneHours"].Value, out zoneHours) == false) return DateTime.MinValue; if (match.Groups["zoneMinutes"].Value != string.Empty) { if (int.TryParse(match.Groups["zoneMinutes"].Value, out zoneMinutes) == false) return DateTime.MinValue; } // Validate the components. if (zoneHours >= 24) return DateTime.MinValue; if (zoneMinutes >= 60) return DateTime.MinValue;
// Calculate the zone offset, in minutes.
offsetInMinutes -= zoneHours < 0 ? zoneHours * 60 - zoneMinutes : zoneHours * 60 + zoneMinutes;
}
}
`
I'm sorry, my English is very bad
I've checked in a fix, and "2020-10-01 05:12+1" now parses successfully. Thanks for the bug report!
I've checked in a fix, and "2020-10-01 05:12+1" now parses successfully. Thanks for the bug report!
Similar to 2020-04-20t20:34 or 2020t20:34 the Date format with t, you should use the strict judgment, rather than using regular expressions, in the case of strictly judge failed to consider using regular expressions.Which judgment can be faster than a regular expression.There are time zone issues, tail prefix Z should use UTC time, and there is no Z should use the local time. Thank you for your work, I'm just some of the best advice. Thank you
in Library/Date/DateParser.cs "2020-10-01 05:12+1" In v8 is correct, but is wrong in Jurassic
Regex regex = new Regex( @"^( (?<year> [0-9]{4} ) (- (?<month> [0-9]{2} ) (- (?<day> [0-9]{2} ))?)?) (T (?<hour> [0-9]{2} ) : (?<minute> [0-9]{2} ) (: (?<second> [0-9]{2} ) (\. (?<millisecond> [0-9]{1,3} ) [0-9]* )?)? (?<zone> Z | (?<zoneHours> [+-][0-9]{2} ) (: (?<zoneMinutes> [0-9]{2} ))? )?)?$", RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace)
Should be modified:Regex regex = new Regex( @"^( (?<year> [0-9]{4} ) (- (?<month> [0-9]{1,2} ) (- (?<day> [0-9]{1,2} ))?)?) ((T|(\s+)) (?<hour> [0-9]{1,2} ) : (?<minute> [0-9]{1,2} ) (: (?<second> [0-9]{1,2} ) (\. (?<millisecond> [0-9]{1,3} ) [0-9]* )?)? (?<zone> Z | (?<zoneHours> [\+\-][0-9]{1,2} ) (: (?<zoneMinutes> [0-9]{1,2} ))? )?)?$", RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace)
Day time string should contain a T part used in faster processing instead of using the regx expression, it is too slowDateTime d; if (Str2UTCDate(input, out d)) return d; // Match the regex. var match = regex_Parser.Match(input); if (match.Success == true) {
Str2UTCDate: ` static bool checkNumber(char c, out int v) { var x = c - 48; if (x < 0 || x > 9) { v = -1; return false; } v = x; return true; } static bool Str2UTCDate(string str, out DateTime date) { int offset = 0, year, month = 1, day = 1, ms = 0; bool utc = false; int length = str.Length; int v; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; year = v 1000; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; year += v 100; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; year += v 10; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; year += v; if (offset < length && (str[offset] == 'T' || str[offset] == 't')) goto HOUR; //MONTH: if (offset >= length || str[offset++] != '-') goto ERR; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; month = v 10; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; month += v; if (month > 12) goto ERR; if (offset < length && (str[offset] == 'T' || str[offset] == 't')) goto HOUR; //day if (offset >= length || str[offset++] != '-') goto ERR; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; day = v * 10; if (offset >= length || !checkNumber(str[offset++], out v)) goto ERR; day += v; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (day > 31) goto ERR; break; case 2: if (year % 4 == 0) { if (day > 29) goto ERR; } else if (day > 28) goto ERR; break; default: if (day > 30) goto ERR; break; }