@@ -311,7 +311,6 @@ public void Parse_ExplicitDateWithOperations_ReturnsCorrectResult(string express
311311 [ InlineData ( " " ) ]
312312 [ InlineData ( "invalid" ) ]
313313 [ InlineData ( "now+1x" ) ] // Invalid unit
314- [ InlineData ( "2023-01-01" ) ] // Missing ||
315314 [ InlineData ( "||+1d" ) ] // Missing anchor
316315 [ InlineData ( "now/x" ) ] // Invalid rounding unit
317316 [ InlineData ( "2023-13-01||" ) ] // Invalid month
@@ -344,6 +343,7 @@ public void Parse_NullExpression_ThrowsArgumentException()
344343 [ InlineData ( "now" ) ]
345344 [ InlineData ( "now+1h" ) ]
346345 [ InlineData ( "now-1d/d" ) ]
346+ [ InlineData ( "2023-06-15" ) ]
347347 [ InlineData ( "2023-06-15||" ) ]
348348 [ InlineData ( "2023-06-15||+1M/d" ) ]
349349 [ InlineData ( "2025-01-01T01:25:35Z||+3d/d" ) ]
@@ -368,7 +368,6 @@ public void TryParse_ValidExpressions_ReturnsTrueAndCorrectResult(string express
368368 [ InlineData ( "" ) ]
369369 [ InlineData ( "invalid" ) ]
370370 [ InlineData ( "now+" ) ]
371- [ InlineData ( "2023-01-01" ) ] // Missing ||
372371 [ InlineData ( "||+1d" ) ] // Missing anchor
373372 [ InlineData ( "2001.02.01||" ) ] // Dotted format no longer supported
374373 [ InlineData ( "now/d+1h" ) ] // Rounding must be final operation
@@ -398,9 +397,69 @@ public void TryParse_NullExpression_ReturnsFalse()
398397 Assert . Equal ( default , result ) ;
399398 }
400399
400+ [ Fact ]
401+ public void TryParse_FallbackExplicitDate_AppliesBaseOffset ( )
402+ {
403+ const string expression = "2023-04-01" ;
404+ _logger . LogDebug ( "Testing TryParse fallback with expression: '{Expression}', BaseTime: {BaseTime}" , expression , _baseTime ) ;
405+
406+ bool success = DateMath . TryParse ( expression , _baseTime , false , out var result ) ;
407+
408+ _logger . LogDebug ( "TryParse success: {Success}, Result: {Result}" , success , result ) ;
409+
410+ Assert . True ( success ) ;
411+ var expected = new DateTimeOffset ( 2023 , 4 , 1 , 0 , 0 , 0 , _baseTime . Offset ) ;
412+ Assert . Equal ( expected , result ) ;
413+ }
414+
415+ [ Fact ]
416+ public void TryParse_FallbackExplicitDateUpperLimit_AdjustsToEndOfDay ( )
417+ {
418+ const string expression = "2023-07-10" ;
419+ _logger . LogDebug ( "Testing TryParse fallback upper limit with expression: '{Expression}', BaseTime: {BaseTime}" , expression , _baseTime ) ;
420+
421+ bool success = DateMath . TryParse ( expression , _baseTime , true , out var result ) ;
422+
423+ _logger . LogDebug ( "TryParse success: {Success}, Result: {Result}" , success , result ) ;
424+
425+ Assert . True ( success ) ;
426+ var expected = new DateTimeOffset ( 2023 , 7 , 10 , 23 , 59 , 59 , 999 , _baseTime . Offset ) ;
427+ Assert . Equal ( expected , result ) ;
428+ }
429+
430+ [ Fact ]
431+ public void TryParse_FallbackExplicitDateWithTimezone_PreservesOffset ( )
432+ {
433+ const string expression = "2023-05-05T18:45:00-07:00" ;
434+ _logger . LogDebug ( "Testing TryParse fallback with explicit offset expression: '{Expression}'" , expression ) ;
435+
436+ bool success = DateMath . TryParse ( expression , _baseTime , false , out var result ) ;
437+
438+ _logger . LogDebug ( "TryParse success: {Success}, Result: {Result}" , success , result ) ;
439+
440+ Assert . True ( success ) ;
441+ Assert . Equal ( new DateTimeOffset ( 2023 , 5 , 5 , 18 , 45 , 0 , TimeSpan . FromHours ( - 7 ) ) , result ) ;
442+ }
443+
444+ [ Fact ]
445+ public void TryParse_FallbackExplicitDateWithTimeZoneInfo_UsesProvidedOffset ( )
446+ {
447+ const string expression = "2023-09-15" ;
448+ var customZone = TimeZoneInfo . CreateCustomTimeZone ( "TestPlusThree" , TimeSpan . FromHours ( 3 ) , "Test +3" , "Test +3" ) ;
449+ _logger . LogDebug ( "Testing TryParse fallback with TimeZoneInfo: '{Expression}', TimeZone: {TimeZone}" , expression , customZone ) ;
450+
451+ bool success = DateMath . TryParse ( expression , customZone , false , out var result ) ;
452+
453+ _logger . LogDebug ( "TryParse success: {Success}, Result: {Result}" , success , result ) ;
454+
455+ Assert . True ( success ) ;
456+ Assert . Equal ( new DateTimeOffset ( 2023 , 9 , 15 , 0 , 0 , 0 , customZone . BaseUtcOffset ) , result ) ;
457+ }
458+
401459 [ Theory ]
402460 [ InlineData ( "now+1h" , false ) ]
403461 [ InlineData ( "now-1d/d" , true ) ]
462+ [ InlineData ( "2023-06-15" , false ) ]
404463 [ InlineData ( "2023-06-15||+1M" , false ) ]
405464 [ InlineData ( "2025-01-01T01:25:35Z||+3d/d" , true ) ]
406465 public void Parse_And_TryParse_ReturnSameResults ( string expression , bool isUpperLimit )
@@ -556,7 +615,7 @@ public void ParseTimeZone_Now_ReturnsCorrectTimezone(string timeZoneId, int expe
556615 public void ParseTimeZone_ExplicitDateWithoutTimezone_UsesSpecifiedTimezone ( )
557616 {
558617 var easternTimeZone = TimeZoneInfo . FindSystemTimeZoneById ( "US/Eastern" ) ;
559- const string expression = "2023-06-15T14:30:00|| " ;
618+ const string expression = "2023-06-15T14:30:00" ;
560619
561620 _logger . LogDebug ( "Testing Parse with TimeZoneInfo for expression: '{Expression}', TimeZone: {TimeZone}" ,
562621 expression , easternTimeZone . Id ) ;
@@ -581,7 +640,7 @@ public void ParseTimeZone_ExplicitDateWithoutTimezone_UsesSpecifiedTimezone()
581640 public void ParseTimeZone_ExplicitDateWithTimezone_PreservesOriginalTimezone ( )
582641 {
583642 var pacificTimeZone = TimeZoneInfo . FindSystemTimeZoneById ( "US/Pacific" ) ;
584- const string expression = "2023-06-15T14:30:00+05:00|| " ; // Explicit +05:00 timezone
643+ const string expression = "2023-06-15T14:30:00+05:00" ; // Explicit +05:00 timezone
585644
586645 _logger . LogDebug ( "Testing Parse with TimeZoneInfo for expression: '{Expression}', TimeZone: {TimeZone}" ,
587646 expression , pacificTimeZone . Id ) ;
0 commit comments