We’re converting our Cosmos DB triggered Azure function from in-process model to isolated.
Since we want to retain ability to use fluent JSON schema, we’re not using a POCO class for trigger inputs and use JObject
instead.
Here’s our trigger:
[CosmosDBTrigger(
databaseName: "%SourceCosmosDatabaseName%",
containerName: OurContainerName,
Connection = "CosmosConnectionString",
LeaseDatabaseName = "%CosmosDatabaseName%",
LeaseContainerName = LeaseContainerName,
LeaseContainerPrefix = LeaseContainerNewStatusPrefix,
CreateLeaseContainerIfNotExists = true,
StartFromBeginning = true)]
IReadOnlyList<JObject> inputs,
FunctionContext functionContext)
The problem is that strings containing date times are automatically parsed and converted to DateTime
by Azure functions, which converts them to the server’s time zone, i.e. string "2023-05-15T20:05:00-05:00"
becomes “2023-05-16T04:05:00+03:00”
I tried giving the DateParseHandling.None option in JSON serialization settings as it is described in documentation, but they don’t seem to be respected:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder.Services.Configure<WorkerOptions>(options =>
{
var settings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings();
settings.DateParseHandling = DateParseHandling.None;
options.Serializer = new NewtonsoftJsonObjectSerializer(settings);
});
})