Context:
In a Cosmos DB triggered function, Azure function receives an IReadOnlyList<Poco>,
Poco is defined as:
public record Poco
{
public string Id { get; set; }
public string DateAsString { get; set; }
}
Although property DateAsString is of type string and, as I understand, should not be converted by DateTimeConverter since the target property is not DateTime or DateTimeOffset, it still gets parsed and consequently its timezone info is converted to the local timezone.
Steps to reproduce
Create a new Cosmos DB triggered Azure function, e.g.:
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace AzureFunctionTest;
public class MyCosmosDbTrigger
{
private readonly ILogger _logger;
public MyCosmosDbTrigger(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<MyCosmosDbTrigger>();
}
[Function("MyCosmosDbTrigger")]
public void Run([CosmosDBTrigger(
databaseName: "MyDatabase",
containerName: "MyContainer",
Connection = "CosmosDbConnectionString",
LeaseContainerName = "leases",
CreateLeaseContainerIfNotExists = true)]
IReadOnlyList<Poco> input,
FunctionContext context)
{
foreach (var document in input)
{
this._logger.LogInformation(document.ToString());
}
}
}
Define Poco as:
public record Poco
{
public string Id { get; set; }
public string DateAsString { get; set; }
}
Create a document in container MyDatabase.MyContainer:
Description
Context: In a Cosmos DB triggered function, Azure function receives an
IReadOnlyList<Poco>
, Poco is defined as:Although property
DateAsString
is of typestring
and, as I understand, should not be converted byDateTimeConverter
since the target property is notDateTime
orDateTimeOffset
, it still gets parsed and consequently its timezone info is converted to the local timezone.Steps to reproduce
Poco
as:Poco { Id = 1, DateAsString = 2024-04-29T06:46:00+03:00 }
and notice that the timezone has been converted.