-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Parquet.File.Values.Primitives; | ||
using Xunit; | ||
|
||
namespace Parquet.Test.File.Values.Primitives | ||
{ | ||
public class NanoTimeTest | ||
{ | ||
[Fact] | ||
public void ConvertToDateTimeOffset_PreservesTicks() | ||
{ | ||
var dto = new DateTimeOffset(2021, 05, 14, 17, 52, 31, TimeSpan.Zero); | ||
dto = dto.Add(TimeSpan.FromTicks(1234567)); | ||
var nanoTime = new NanoTime(dto); | ||
var convertedDto = (DateTimeOffset) nanoTime; | ||
namespace Parquet.Test.File.Values.Primitives { | ||
public class NanoTimeTest { | ||
[Theory] | ||
[InlineData(637566187511234567)] // 2021-05-14T17:52:31.1234567+00:00 - Works before fix | ||
[InlineData(637807514459104071)] // 2022-02-18T02:24:05.9104071+00:00 - Does not work before fix | ||
[MemberData(nameof(GenerateRandomDateTime), 1000)] // Generate a bunch of random date times | ||
public void ConvertToDateTimeOffset_PreservesTicks(long ticks) { | ||
DateTimeOffset dto = new DateTime(ticks).ToUniversalTime(); | ||
var nanoTime = new NanoTime(dto); | ||
var convertedDto = (DateTimeOffset)nanoTime; | ||
|
||
Assert.Equal(dto, convertedDto); | ||
} | ||
} | ||
Assert.Equal(dto, convertedDto); | ||
} | ||
|
||
public static IEnumerable<object[]> GenerateRandomDateTime(int num) { | ||
var rand = new Random(); | ||
for(int i = 0; i < num; i++) { | ||
var dateTime = new DateTimeOffset(2022, rand.Next(1, 13), rand.Next(1, 28), rand.Next(0, 24), | ||
rand.Next(0, 60), rand.Next(0, 60), rand.Next(0, 1000), TimeSpan.Zero); | ||
dateTime = dateTime.AddTicks(rand.Next(0, (int)TimeSpan.TicksPerMillisecond)); | ||
yield return new object[] { dateTime.Ticks }; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters