Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="NodaTime" Version="3.3.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public void WhenUtcDateIsSpecified_ThenReturnInstantFromUtcDate()
}

[Fact]
public void WhenFromUnixTimeTicksMethodIsCalled_ThenReturnInstantFromUnixTicks()
public void WhenFromUnixTimeSecondsMethodIsCalled_ThenReturnInstantFromUnixSeconds()
{
var epochTime = 1693153840;

var instant = Instant.FromUnixTimeTicks(epochTime);
var unixTimeTicks = instant.ToUnixTimeTicks();
var instant = Instant.FromUnixTimeSeconds(epochTime);
var unixTimeSeconds = instant.ToUnixTimeSeconds();

Assert.Equal(epochTime, unixTimeTicks);
Assert.Equal(epochTime, unixTimeSeconds);
Assert.Equal(Instant.FromUtc(2023, 8, 27, 16, 30, 40), instant);
}

[Fact]
Expand Down Expand Up @@ -109,14 +110,14 @@ public void WhenDifferentTimesArePassed_ThenCompareThemAndReturnResult()
}

[Fact]
public void WhenLocalDateTimezoneAndDateTimezoneAreCombined_ThenReturnZoneDateTime()
public void WhenLocalDateTimezoneAndDateTimezoneAreCombined_ThenReturnZonedDateTime()
{
var localDateTime = new LocalDateTime(2023, 8, 31, 15, 30);
var timezone = DateTimeZoneProviders.Tzdb["Africa/Cairo"];

var zoneDateTime = localDateTime.InZoneLeniently(timezone);
var zonedDateTime = localDateTime.InZoneLeniently(timezone);

Assert.Equal("Africa/Cairo", zoneDateTime.Zone.Id);
Assert.Equal("Africa/Cairo", zonedDateTime.Zone.Id);
}

[Fact]
Expand All @@ -127,7 +128,7 @@ public void WhenDurationsAreAdded_ThenReturnSumOfDuration()

var sumOfDurations = durationInDays + durationInHours;

Assert.Equal( 1.125, sumOfDurations.TotalDays);
Assert.Equal(1.125, sumOfDurations.TotalDays);
}

[Fact]
Expand Down Expand Up @@ -224,5 +225,49 @@ public void WhenTimeZoneIsSpecified_ThenReturnDateTimeZone()
Assert.NotNull(newYorkTimeZone);
Assert.Equal(timeZoneId, newYorkTimeZone.Id);
}
}

[Fact]
public void WhenDurationIsAddedToZonedDateTime_ThenElapsedTimeCrossesTheDstGap()
{
var newYork = DateTimeZoneProviders.Tzdb["America/New_York"];
var start = new LocalDateTime(2026, 3, 8, 1, 30).InZoneStrictly(newYork);

var later = start + Duration.FromHours(1);

Assert.Equal(new LocalDateTime(2026, 3, 8, 3, 30), later.LocalDateTime);
Assert.Equal(Duration.FromHours(1), later.ToInstant() - start.ToInstant());
}

[Fact]
public void WhenPeriodIsAddedToLocalDateTime_ThenOnlyTheWallClockMoves()
{
var newYork = DateTimeZoneProviders.Tzdb["America/New_York"];
var start = new LocalDateTime(2026, 3, 8, 1, 30);

var later = start + Period.FromHours(1);

Assert.Equal(new LocalDateTime(2026, 3, 8, 2, 30), later);
Assert.Throws<SkippedTimeException>(() => later.InZoneStrictly(newYork));
}

[Fact]
public void WhenDurationIsAddedAsNanoseconds_ThenLocalDateTimeMovesByThatAmount()
{
var start = new LocalDateTime(2026, 3, 8, 1, 30);
var duration = Duration.FromMinutes(90);

var later = start.PlusNanoseconds(duration.ToInt64Nanoseconds());

Assert.Equal(new LocalDateTime(2026, 3, 8, 3, 0), later);
}

[Fact]
public void WhenTimeProviderIsConvertedToClock_ThenReturnCurrentInstant()
{
IClock clock = TimeProvider.System.ToClock();

var instant = clock.GetCurrentInstant();

Assert.True(instant != default);
}
}
10 changes: 5 additions & 5 deletions dotnet-datetime/HandlingDatesWithNodaTime/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading