Skip to content

Commit 1138e79

Browse files
committed
Storing datetime value as UTC time as from the SDK expected
1 parent 97109fb commit 1138e79

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text;
1+
using System.Text;
22
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts;
33
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions;
44
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models;
@@ -34,7 +34,7 @@ public async Task VerifyImportFromJson()
3434
storageContext.AddAttributeMapper(typeof(DemoModel2), tableName1);
3535

3636
// define the import data
37-
var staticExportData = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]";
37+
var staticExportData = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"},{\"PropertyName\":\"CreatedAt\",\"PropertyType\":3,\"PropertyValue\":\"2023-01-30T22:58:40.5859427+00:00\"}]}]";
3838
var staticExportDataStream = new MemoryStream(Encoding.UTF8.GetBytes(staticExportData ?? ""));
3939

4040
// check if we have an empty tabel before import
@@ -53,7 +53,13 @@ public async Task VerifyImportFromJson()
5353
// get the data
5454
var data = await storageContext.Query<DemoModel2>().Now();
5555
Assert.Equal("1", data.First().P);
56-
Assert.Equal("2", data.First().R);
56+
Assert.Equal("2", data.First().R);
57+
58+
var createdAtDate = DateTime.Parse("2023-01-30T22:58:40.5859427+00:00");
59+
var createdAtDateFromDataLoad = data.First().CreatedAt;
60+
61+
Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad);
62+
Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad.ToUniversalTime());
5763

5864
// drop table
5965
await storageContext.DropTableAsync<DemoModel2>();

CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class DemoModel2
1212

1313
[RowKey]
1414
public string R { get; set; } = "R1";
15+
16+
public DateTime CreatedAt { get; set; } = DateTime.MinValue;
1517
}
1618
}
1719

CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public async Task ImportFromJsonAsync(string tableName, StreamReader reader, Act
123123
if ((ExportEdmType)property.PropertyType == ExportEdmType.String && property.PropertyValue is DateTime)
124124
{
125125
property.PropertyValue = ((DateTime)property.PropertyValue).ToString("o");
126+
} else if ((ExportEdmType)property.PropertyType == ExportEdmType.DateTime) {
127+
property.PropertyValue = ((DateTime)property.PropertyValue).ToUniversalTime();
126128
}
127129
}
128130

0 commit comments

Comments
 (0)