Skip to content

Commit 24954e9

Browse files
authored
Change CronExpression equality operators to accept null operands (#87)
Co-authored-by: Pierre-Henri SCHOFFIT <[email protected]>
1 parent 60b6b54 commit 24954e9

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/Cronos/CronExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ public override int GetHashCode()
406406
/// <summary>
407407
/// Implements the operator ==.
408408
/// </summary>
409-
public static bool operator ==(CronExpression left, CronExpression right) => Equals(left, right);
409+
public static bool operator ==(CronExpression? left, CronExpression? right) => Equals(left, right);
410410

411411
/// <summary>
412412
/// Implements the operator !=.
413413
/// </summary>
414-
public static bool operator !=(CronExpression left, CronExpression right) => !Equals(left, right);
414+
public static bool operator !=(CronExpression? left, CronExpression? right) => !Equals(left, right);
415415

416416
private DateTimeOffset? GetOccurrenceConsideringTimeZone(DateTimeOffset fromUtc, TimeZoneInfo zone, bool inclusive)
417417
{

tests/Cronos.Tests/CronExpressionFacts.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public void TryParse_ReturnsTrue_WhenAbleToParseTheGivenExpression_WithCorrectCr
517517
var result = CronExpression.TryParse("* * * * *", out var cron);
518518

519519
Assert.True(result);
520-
Assert.Equal(Today.AddMinutes(1), cron.GetNextOccurrence(Today));
520+
Assert.Equal(Today.AddMinutes(1), cron!.GetNextOccurrence(Today));
521521
}
522522

523523
[Fact]
@@ -542,7 +542,7 @@ public void TryParse_WithSecondsSpecified_ReturnsTrue_AndGivesSecondBasedCronExp
542542
var result = CronExpression.TryParse("* * * * * *", CronFormat.IncludeSeconds, out var cron);
543543

544544
Assert.True(result);
545-
Assert.Equal(Today.AddSeconds(1), cron.GetNextOccurrence(Today));
545+
Assert.Equal(Today.AddSeconds(1), cron!.GetNextOccurrence(Today));
546546
}
547547

548548
[Theory]
@@ -2785,6 +2785,7 @@ public void Equals_ReturnsFalse_WhenOtherIsNull()
27852785

27862786
Assert.False(cronExpression.Equals(null));
27872787
Assert.False(cronExpression == null);
2788+
Assert.True(cronExpression != null);
27882789
}
27892790

27902791
[Theory]

tests/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
33
<PropertyGroup>
44
<SignAssembly>true</SignAssembly><!-- InernalsVisibleTo requires test assemblies to be signed too -->
5+
<Nullable>enable</Nullable>
6+
<WarningsAsErrors>Nullable</WarningsAsErrors>
57
</PropertyGroup>
68

79
<ItemGroup>

0 commit comments

Comments
 (0)