Skip to content

Commit

Permalink
Storing datetime value as UTC time as from the SDK expected
Browse files Browse the repository at this point in the history
  • Loading branch information
dei79 committed Nov 10, 2023
1 parent 97109fb commit 1138e79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
@@ -1,4 +1,4 @@
using System.Text;
using System.Text;
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts;
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions;
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models;
Expand Down Expand Up @@ -34,7 +34,7 @@ public async Task VerifyImportFromJson()
storageContext.AddAttributeMapper(typeof(DemoModel2), tableName1);

// define the import data
var staticExportData = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]";
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\"}]}]";
var staticExportDataStream = new MemoryStream(Encoding.UTF8.GetBytes(staticExportData ?? ""));

// check if we have an empty tabel before import
Expand All @@ -53,7 +53,13 @@ public async Task VerifyImportFromJson()
// get the data
var data = await storageContext.Query<DemoModel2>().Now();
Assert.Equal("1", data.First().P);
Assert.Equal("2", data.First().R);
Assert.Equal("2", data.First().R);

var createdAtDate = DateTime.Parse("2023-01-30T22:58:40.5859427+00:00");
var createdAtDateFromDataLoad = data.First().CreatedAt;

Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad);
Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad.ToUniversalTime());

// drop table
await storageContext.DropTableAsync<DemoModel2>();
Expand Down
Expand Up @@ -12,6 +12,8 @@ public class DemoModel2

[RowKey]
public string R { get; set; } = "R1";

public DateTime CreatedAt { get; set; } = DateTime.MinValue;
}
}

Expand Up @@ -123,6 +123,8 @@ public async Task ImportFromJsonAsync(string tableName, StreamReader reader, Act
if ((ExportEdmType)property.PropertyType == ExportEdmType.String && property.PropertyValue is DateTime)
{
property.PropertyValue = ((DateTime)property.PropertyValue).ToString("o");
} else if ((ExportEdmType)property.PropertyType == ExportEdmType.DateTime) {
property.PropertyValue = ((DateTime)property.PropertyValue).ToUniversalTime();
}
}

Expand Down

0 comments on commit 1138e79

Please sign in to comment.