-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding DateTimeConverter which will handle binding of DateTime/DateTimeOffset type parameters #852
Conversation
public ValueTask<ConversionResult> ConvertAsync(ConverterContext context) | ||
{ | ||
if ( | ||
context.TargetType == typeof(DateTime) || context.TargetType == typeof(DateTime?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should DateTimeOffset
be handled as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Yes, we should support DateTimeOffset
as well. I pushed a new iteration with that support.
… format to avoid flaky behavior on CI/CD env.
return new ValueTask<ConversionResult>(ConversionResult.Unhandled()); | ||
} | ||
|
||
if ((context.TargetType == typeof(DateTimeOffset) || context.TargetType == typeof(DateTimeOffset?)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what scenario would we pass null
to a DateTimeOffset?
or DateTime?
? Is there any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say customer has a function definition like below.
public static HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req,
DateTime startDate,
DateTime? endDate)
where endDate param is nullable type / optional. The below 2 requests will work for this function definition.
api/Function4?startdate=2021/10/10&enddate=2021/12/12
api/Function4?startdate=2021/12/12
For the second request where endDate
is not part of the request's input data/ trigger metadata, so, we do not have a source data to use (ie: source
is null). So, the converter will return Unhandled result and the default value of the parameterValues array (of type object[]
) entry will be used, which is null
. We will end up passing null as that argument's value when invoking the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do similar thing for Guid converter where Guid?
is supported.
/check-enforcer evaluate |
Microsoft.Azure.Functions.Worker 1.8.0-preview3 includes this change. |
I have a question: how come this converter converts timestamps in strings, when the TargetType isn't even See issue: https://github.com/Azure/azure-functions-dotnet-worker/issues/2731 |
Fixes #851
Adding a new
IConverter
implementation to handle binding the below types.DateTime
DateTime?
DateTimeOffset
DateTimeOffset?