@@ -24,7 +24,7 @@ public static class DateTimeExtensions
2424 /// <param name="timeString">Time string</param>
2525 public static void ToWebUntisTimeFormat ( this DateTime dateTime , out string dateString , out string timeString )
2626 {
27- dateString = dateTime . ToString ( "yyyy-MM-dd " ) ;
27+ dateString = dateTime . ToString ( "yyyyMMdd " ) ;
2828 timeString = dateTime . Hour + dateTime . ToString ( "mm" ) ;
2929 }
3030
@@ -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\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
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 ) ;
@@ -59,8 +59,8 @@ public static DateTime FromWebUntisTimeFormat(this DateTime dateTime, string dat
5959
6060 // Parse the numbers in the string to value
6161 int year = int . Parse ( dateString . Substring ( 0 , 4 ) ) ;
62- int month = int . Parse ( dateString . Substring ( 5 , 2 ) ) ;
63- int day = int . Parse ( dateString . Substring ( 8 , 2 ) ) ;
62+ int month = int . Parse ( dateString . Substring ( 4 , 2 ) ) ;
63+ int day = int . Parse ( dateString . Substring ( 6 , 2 ) ) ;
6464
6565 bool is4Letters = timeString . Length == 4 ;
6666 int hour = int . Parse ( is4Letters ? timeString . Substring ( 0 , 2 ) : timeString [ 0 ] . ToString ( ) ) ;
0 commit comments