Skip to content

Commit 54dd621

Browse files
committed
Improve datetime regexes
1 parent 99f4574 commit 54dd621

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

WebUntisAPI.Client/Extensions/DateTimeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public static void ToWebUntisTimeFormat(this DateTime dateTime, out string dateS
4646
/// <exception cref="FormatException">Thrown when one of the given strings isn't in the right format</exception>
4747
public static DateTime FromWebUntisTimeFormat(this DateTime dateTime, string dateString, string timeString)
4848
{
49-
Regex dateRegex = new Regex(@"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$"); // Regex for the WebUntis date format
50-
Regex timeRegex = new Regex("^([0-9]|1[0-9]|2[0-3])[0-5][0-9]$"); // Regex for the WebUntis time format
49+
Regex dateRegex = new Regex(@"^\d{4}-(0\d|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$"); // Regex for the WebUntis date format
50+
Regex timeRegex = new Regex(@"^(\d|1\d|2[0-3])[0-5]\d$"); // Regex for the WebUntis time format
5151

5252
// Check if the date- and time strings are valid
5353
bool isDateValid = dateRegex.IsMatch(dateString);

0 commit comments

Comments
 (0)