Epoch functions#135
Open
dmcghan wants to merge 2 commits intoOraOpenSource:masterfrom
dmcghan:epoch-functions
Open
Epoch functions#135dmcghan wants to merge 2 commits intoOraOpenSource:masterfrom dmcghan:epoch-functions
dmcghan wants to merge 2 commits intoOraOpenSource:masterfrom
dmcghan:epoch-functions
Conversation
Alternative implementation. Removed timestamp2epoch in favor of implicit data conversion. Here, date2epoch uses the timestamp data type so if a date is passed it doesn't lose precision but any timestamp data type can be passed without losing milliseconds. Also, both functions now have an additional tzr parameter which allows for additional flexibility when needed. In the case of date2epoch, the parameter can be used to specify which timezone the date or timestamp being passed in is from. For epoch2date, the tzr parameter allows the user to get a date back in a specific timezone. The tzr parameter defaults to the sessiontimezone for convenience.
Updated implementation of epoch functions.
janihur
reviewed
Jan 5, 2017
| $end | ||
|
|
||
| l_tswtz timestamp with time zone; | ||
| l_start timestamp with time zone := to_timestamp_tz('19700101 utc', 'yyyymmdd tzr'); |
Contributor
There was a problem hiding this comment.
Use a package level constant:
epoch constant timestamp with time zone := timestamp '1970-01-01 00:00:00 +00:00';
instead of l_start.
janihur
reviewed
Jan 5, 2017
| return | ||
| to_date ('19700101', 'yyyymmdd') | ||
| + ((p_epoch + ((to_number(substr(tz_offset(sessiontimezone), 1, 3))+0) * 3600)) / 86400); -- Note: Was +1 but was causing 1 hour ahead (#123) | ||
| l_tswtz := to_timestamp_tz('19700101 utc', 'yyyymmdd tzr') + numtodsinterval(p_epoch/86400000, 'day'); |
Contributor
There was a problem hiding this comment.
Use the constant:
l_tswtz := epoch + numtodsinterval(p_epoch/86400000, 'day');
And define a constant for magic number 86400000.
janihur
reviewed
Jan 5, 2017
| - (to_number(substr (tz_offset (sessiontimezone), 1, 3))+0) * 3600); -- Note: Was +1 but was causing 1 hour behind (#123) | ||
| l_tswtz := from_tz(p_date, p_date_in_tzr) at time zone 'utc'; | ||
|
|
||
| return round((extract (day from l_tswtz - l_start) * 86400000) |
Contributor
There was a problem hiding this comment.
Define constants for the magic numbers.
janihur
reviewed
Jan 5, 2017
| create or replace package oos_util_date | ||
| as | ||
|
|
||
| function date2epoch( |
Contributor
There was a problem hiding this comment.
Make this a deterministic function.
janihur
reviewed
Jan 5, 2017
| p_date_in_tzr in varchar2 default sessiontimezone) | ||
| return number; | ||
|
|
||
| function epoch2date( |
Contributor
There was a problem hiding this comment.
Make this a deterministic function.
janihur
reviewed
Jan 5, 2017
| create or replace package oos_util_date | ||
| as | ||
|
|
||
| function date2epoch( |
Contributor
There was a problem hiding this comment.
Can we also have a p_date in timestamp with time zone version ?
janihur
reviewed
Jan 5, 2017
|
|
||
| function date2epoch( | ||
| p_date in date) | ||
| p_date timestamp, |
Contributor
|
Thank you ! This contribution is welcome, but unfortunately @martindsouza has not have time for the project recently. Please be patient ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative implementation. Removed timestamp2epoch in favor of implicit data conversion. Here, date2epoch uses the timestamp data type so if a date is passed it doesn't lose precision but any timestamp data type can be passed without losing milliseconds.
Also, both functions now have an additional tzr parameter which allows for additional flexibility when needed. In the case of date2epoch, the parameter can be used to specify which timezone the date or timestamp being passed in is from. For epoch2date, the tzr parameter allows the user to get a date back in a specific timezone.
The tzr parameter defaults to the sessiontimezone for convenience.