Skip to content

Prevent DynamoDB SDK converting the datetime in local timezone #1450

@vickyRathee

Description

@vickyRathee

The DynamoDB SDK is converting the datetime property in local timezone while fetching documents from database, which has stored the datetime in UTC correctly.

Expected Behavior

DateTime should not be converted to local time zone

Current Behavior

The SDK is converting the date time into local time zone

Correct In Dyanmo DB Table (UTC)

image

While fetching records through SDK

"2019-11-07T12:40:28.445+05:30",
"2019-11-07T12:35:25.071+05:30",

Code to Reproduce :

async Task Main()
{
	var dynamo = new DynamoDbService();
	var result = await dynamo.GetDocumentsAsync<Documents>("abc");
	result.Dump();

}

public class DynamoDbService
{
	private static readonly string awsAccessKey = "access key here";
	private static readonly string awsSecretKey = "secret here";

	private static BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
	private static AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCredentials, RegionEndpoint.USEast1);
	private static DynamoDBContext context = new DynamoDBContext(client);

	public async Task InsertDocumentAsync<T>(T document)
	{
		await context.SaveAsync<T>(document);
	}

	public async Task<List<T>> GetDocumentsAsync<T>(string id, int limit = 10)
	{
		QueryFilter filter = new QueryFilter();
		filter.AddCondition("doc_id", QueryOperator.Equal, id);
		QueryOperationConfig queryConfig = new QueryOperationConfig
		{
			Filter = filter,
			Limit = limit,
			BackwardSearch = true
		};
		var documents = await context.FromQueryAsync<T>(queryConfig, _operationConfig).GetNextSetAsync();
		return documents;
	}
}

[DynamoDBTable("Table1")]
public class Documents
{
	public string doc_id { get; set; }
	public string name { get; set; }
	public DateTime created { get; set; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.dynamodbp1This is a high priority issuequeued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions