-
Notifications
You must be signed in to change notification settings - Fork 46
Support datetime extended type #228
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
Merged
DifferentialOrange
merged 3 commits into
master
from
DifferentialOrange/gh-204-datetime
Sep 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
msgpack: support tzindex in datetime
Support non-zero tzindex in datetime extended type. If both tzoffset and
tzindex are specified, tzindex is prior (same as in Tarantool [1]).
Use `tz` parameter to set up timezone name:
```
dt = tarantool.Datetime(year=2022, month=8, day=31,
hour=18, minute=7, sec=54,
nsec=308543321, tz='Europe/Moscow')
```
You may use `tz` property to get timezone name of a datetime object.
pytz is used to build timezone info. Tarantool index to Olson name
map and inverted one are built with gen_timezones.sh script based on
tarantool/go-tarantool script [2]. All Tarantool unique and alias
timezones present in pytz.all_timezones list. Only the following
abbreviated timezones from Tarantool presents in pytz.all_timezones
(version 2022.2.1):
- CET
- EET
- EST
- GMT
- HST
- MST
- UTC
- WET
pytz does not natively support work with abbreviated timezones due to
its possibly ambiguous nature [3-5]. Tarantool itself do not support
work with ambiguous abbreviated timezones:
```
Tarantool 2.10.1-0-g482d91c66
tarantool> datetime.new({tz = 'BST'})
---
- error: 'builtin/datetime.lua:477: could not parse ''BST'' - ambiguous timezone'
...
```
If ambiguous timezone is specified, the exception is raised.
Tarantool header timezones.h [6] provides a map for all abbreviated
timezones with category info (all ambiguous timezones are marked with
TZ_AMBIGUOUS flag) and offset info. We parse this info to build
pytz.FixedOffset() timezone for each Tarantool abbreviated timezone not
supported natively by pytz.
1. https://www.tarantool.io/en/doc/latest/reference/reference_lua/datetime/new/
2. https://github.com/tarantool/go-tarantool/blob/5801dc6f5ce69db7c8bc0c0d0fe4fb6042d5ecbc/datetime/gen-timezones.sh
3. https://stackoverflow.com/questions/37109945/how-to-use-abbreviated-timezone-namepst-ist-in-pytz
4. https://stackoverflow.com/questions/27531718/datetime-timezone-conversion-using-pytz
5. https://stackoverflow.com/questions/30315485/pytz-return-olson-timezone-name-from-only-a-gmt-offset
6. https://github.com/tarantool/tarantool/9ee45289e01232b8df1413efea11db170ae3b3b4/src/lib/tzcode/timezones.h
Closes #204- Loading branch information
commit aa7302a39c31b1fd69052c36af82eadf25aaa0f6
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from tarantool.msgpack_ext.types.timezones.timezones import ( | ||
| TZ_AMBIGUOUS, | ||
| indexToTimezone, | ||
| timezoneToIndex, | ||
| timezoneAbbrevInfo, | ||
| ) | ||
|
|
||
| __all__ = ['TZ_AMBIGUOUS', 'indexToTimezone', 'timezoneToIndex', | ||
| 'timezoneAbbrevInfo'] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env bash | ||
| set -xeuo pipefail | ||
|
|
||
| SRC_COMMIT="9ee45289e01232b8df1413efea11db170ae3b3b4" | ||
| SRC_FILE=timezones.h | ||
| DST_FILE=timezones.py | ||
|
|
||
| [ -e ${SRC_FILE} ] && rm ${SRC_FILE} | ||
| wget -O ${SRC_FILE} \ | ||
| https://raw.githubusercontent.com/tarantool/tarantool/${SRC_COMMIT}/src/lib/tzcode/timezones.h | ||
|
|
||
| # We don't need aliases in indexToTimezone because Tarantool always replace it: | ||
| # | ||
| # tarantool> T = date.parse '2022-01-01T00:00 Pacific/Enderbury' | ||
| # --- | ||
| # ... | ||
| # tarantool> T | ||
| # --- | ||
| # - 2022-01-01T00:00:00 Pacific/Kanton | ||
| # ... | ||
| # | ||
| # So we can do the same and don't worry, be happy. | ||
|
|
||
| cat <<EOF > ${DST_FILE} | ||
| # Automatically generated by gen-timezones.sh | ||
|
|
||
| TZ_UTC = 0x01 | ||
| TZ_RFC = 0x02 | ||
| TZ_MILITARY = 0x04 | ||
| TZ_AMBIGUOUS = 0x08 | ||
| TZ_NYI = 0x10 | ||
| TZ_OLSON = 0x20 | ||
| TZ_ALIAS = 0x40 | ||
| TZ_DST = 0x80 | ||
|
|
||
| indexToTimezone = { | ||
| EOF | ||
|
|
||
| grep ZONE_ABBREV ${SRC_FILE} | sed "s/ZONE_ABBREV( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : %s,\n", $1, $3)}' >> ${DST_FILE} | ||
| grep ZONE_UNIQUE ${SRC_FILE} | sed "s/ZONE_UNIQUE( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : %s,\n", $1, $2)}' >> ${DST_FILE} | ||
|
|
||
| cat <<EOF >> ${DST_FILE} | ||
| } | ||
|
|
||
| timezoneToIndex = { | ||
| EOF | ||
|
|
||
| grep ZONE_ABBREV ${SRC_FILE} | sed "s/ZONE_ABBREV( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : %s,\n", $3, $1)}' >> ${DST_FILE} | ||
| grep ZONE_UNIQUE ${SRC_FILE} | sed "s/ZONE_UNIQUE( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : %s,\n", $2, $1)}' >> ${DST_FILE} | ||
| grep ZONE_ALIAS ${SRC_FILE} | sed "s/ZONE_ALIAS( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : %s,\n", $2, $1)}' >> ${DST_FILE} | ||
|
|
||
| cat <<EOF >> ${DST_FILE} | ||
| } | ||
|
|
||
| timezoneAbbrevInfo = { | ||
| EOF | ||
|
|
||
| grep ZONE_ABBREV ${SRC_FILE} | sed "s/ZONE_ABBREV( *//g" | sed "s/[),]//g" \ | ||
| | awk '{printf("\t%s : {\"offset\" : %d, \"category\" : %s},\n", $3, $2, $4)}' >> ${DST_FILE} | ||
| echo "}" >> ${DST_FILE} | ||
|
|
||
| rm timezones.h | ||
|
|
||
| python validate_timezones.py |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.