@@ -18,6 +18,8 @@ namespace EstateManagementUI.BlazorServer.Components.Pages.Merchants;
1818 public partial class Edit {
1919 [ Parameter ] public Guid MerchantId { get ; set ; }
2020
21+ private static readonly String [ ] OpeningHoursFormats = [ "HHmm" , "Hmm" , "HH:mm" , "H:mm" ] ;
22+
2123 private MerchantModels . MerchantModel ? merchant ;
2224 private bool isLoading = true ;
2325 private bool isSaving = false ;
@@ -426,21 +428,7 @@ private IReadOnlyList<OpeningHoursRow> GetOpeningHoursRows() =>
426428
427429 private Boolean TryNormaliseAndValidateOpeningHours ( out String validationError ) {
428430 foreach ( OpeningHoursRow row in this . GetOpeningHoursRows ( ) ) {
429- row . Hours . Opening = NormaliseOpeningHoursValue ( row . Hours . Opening ) ;
430- row . Hours . Closing = NormaliseOpeningHoursValue ( row . Hours . Closing ) ;
431-
432- if ( TryParseOpeningHoursValue ( row . Hours . Opening , out TimeSpan openingTime ) == false ) {
433- validationError = $ "{ row . DayName } opening time must be entered in HHmm format.";
434- return false ;
435- }
436-
437- if ( TryParseOpeningHoursValue ( row . Hours . Closing , out TimeSpan closingTime ) == false ) {
438- validationError = $ "{ row . DayName } closing time must be entered in HHmm format.";
439- return false ;
440- }
441-
442- if ( closingTime <= openingTime ) {
443- validationError = $ "{ row . DayName } closing time must be later than opening time.";
431+ if ( TryValidateOpeningHoursRow ( row , out validationError ) == false ) {
444432 return false ;
445433 }
446434 }
@@ -457,7 +445,7 @@ private Boolean TryNormaliseAndValidateOpeningHours(out String validationError)
457445 String trimmedValue = value . Trim ( ) ;
458446
459447 if ( DateTime . TryParseExact ( trimmedValue ,
460- [ "HHmm" , "Hmm" , "HH:mm" , "H:mm" ] ,
448+ OpeningHoursFormats ,
461449 CultureInfo . InvariantCulture ,
462450 DateTimeStyles . None ,
463451 out DateTime parsed ) == false ) {
@@ -474,8 +462,35 @@ private static Boolean TryParseOpeningHoursValue(String? value, out TimeSpan tim
474462 return false ;
475463 }
476464
477- return DateTime . TryParseExact ( value , "HHmm" , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime parsed )
478- && ( time = parsed . TimeOfDay ) >= TimeSpan . Zero ;
465+ if ( DateTime . TryParseExact ( value , "HHmm" , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime parsed ) == false ) {
466+ return false ;
467+ }
468+
469+ time = parsed . TimeOfDay ;
470+ return true ;
471+ }
472+
473+ private static Boolean TryValidateOpeningHoursRow ( OpeningHoursRow row , out String validationError ) {
474+ row . Hours . Opening = NormaliseOpeningHoursValue ( row . Hours . Opening ) ;
475+ row . Hours . Closing = NormaliseOpeningHoursValue ( row . Hours . Closing ) ;
476+
477+ if ( TryParseOpeningHoursValue ( row . Hours . Opening , out TimeSpan openingTime ) == false ) {
478+ validationError = $ "{ row . DayName } opening time must be entered in HHmm format.";
479+ return false ;
480+ }
481+
482+ if ( TryParseOpeningHoursValue ( row . Hours . Closing , out TimeSpan closingTime ) == false ) {
483+ validationError = $ "{ row . DayName } closing time must be entered in HHmm format.";
484+ return false ;
485+ }
486+
487+ if ( closingTime <= openingTime ) {
488+ validationError = $ "{ row . DayName } closing time must be later than opening time.";
489+ return false ;
490+ }
491+
492+ validationError = String . Empty ;
493+ return true ;
479494 }
480495
481496 // inside partial class Edit (add the following fields and methods)
0 commit comments