-
Notifications
You must be signed in to change notification settings - Fork 386
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
Support for CONVERT_TZ() function with appropriate translation. #1579
Comments
Does |
An overload can probably do it, it'll just have to be clearly documented in the method XML docstring. I can't see an elegant way to specify |
I'm going to begin some work on this soon and try to get a prototype running, should I branch off |
Yes.
This will depend on the impact the PR has on the code base. While we usually do not add features to already released major versions, it is possible as long as there is very litte risk involved. Just adding another translation is potentially one of those features that could make it into the current release instead of the next. |
Another approach would be mapping |
@crozone I went ahead and provided the
@naitikmalaviya I will currently not implement this translation myself, because it might be cumbersome to ensure that the MySQL time zone information table is in sync with .NET. If you feel strongly about adding those translations as well, please open a separate issue and feel free to provide a PR to discuss the implementation. Thanks! |
Looks fantastic, thank you!! Also seems like a very clean example of how to add additional translations in the future. |
Preface
MySQL supports a function called
CONVERT_TZ(dt,from_tz,to_tz)
, which allows datetime values to be converted from a given source timezone into a given target timezone. The timezone values can either be specified as a fixed offset (eg+10:00
), or more interestingly, an IANA timezone identifier (eg.Australia/Melbourne
). This is particularly useful when writing database queries that performGROUP BY
over days/weeks/months, since theGROUP BY
query can be run over the appropriately shifted datetime value such that the edges of the day line up correctly with the target timezone. Since an actual timezone identifier can be specified, this also seamlessly accounts for changes in the daylight savings. This is very useful when writing queries for generating reports.A basic example of such a query:
If
r.timestamp
is aTIMESTAMP
column, it is implicitly converted into the connection timezone before being passed into theCONVERT_TZ
function, so@@session.time_zone
is used as thefrom_tz
parameter. For converting arbitraryDATETIME
values, thefrom_tz
would be set to the actual source timezone.Issue
Pomelo currently has no translation for the
CONVERT_TZ(dt,from_tz,to_tz)
method.Proposed API for consideration
Consider adding additional functions to
Microsoft.EntityFrameworkCore.MySqlDbFunctionsExtensions
to allow theCONVERT_TZ()
function to be expressed:This would allow the above SQL query to be rewritten as the following LINQ query:
The text was updated successfully, but these errors were encountered: