Skip to content

Commit da946f9

Browse files
authored
Fixes an issue where the default timestamp was set to 0 (#34)
Since `DateTime` is a value type, we must define it as nullable otherwise it's default value will be 0 (resulting in default timestamps of `0001-01-01T00:00:00.000Z`).
1 parent 60aa89b commit da946f9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Float.TinCan.ActivityLibrary.Tests/TinCanStatementBuilder.tests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,16 @@ public void TestBuildStatement()
1313
.Build();
1414
Assert.NotNull(statement);
1515
}
16+
17+
[Fact]
18+
public void TestDefaultStatementTimestamp()
19+
{
20+
var statement = new TinCanStatementBuilder()
21+
.Build();
22+
23+
// The default timestamp should be (approximately) now.
24+
Assert.InRange(statement.timestamp ?? new System.DateTime(), System.DateTime.UtcNow.AddSeconds(-1), System.DateTime.UtcNow);
25+
System.Console.WriteLine(statement.ToJSON());
26+
}
1627
}
1728
}

Float.TinCan.ActivityLibrary/TinCanStatementBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TinCanStatementBuilder
3636
/// <summary>
3737
/// The timestamp for the statement to be built. Optional.
3838
/// </summary>
39-
DateTime timestamp;
39+
DateTime? timestamp;
4040

4141
/// <summary>
4242
/// Gets the session ID for the statement to be build. Optional.

0 commit comments

Comments
 (0)