Commit 4ed8aba
Fix timezone handling for datetime to unixtime conversions (#2213)
* Fix timezone handling for datetime to unixtime conversions
datetime objects are supported to set expire, these can have timezones.
mktime was used to convert these to unixtime. mktime in Python however is not timezone aware, it expects the input to be UTC and redis-py did not convert the datetime timestamps to UTC before calling mktime.
This can lead to:
1) Setting incorrect expire times because the input datetime object has a timezone but is passed to mktime without converting to UTC first.
2) When the datetime timestamp is within DST, mktime fails with "OverflowError: mktime argument out of range" because UTC doesn't have DST. This depends on libc versions.
* linters
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>1 parent fd9fea6 commit 4ed8aba
File tree
4 files changed
+13
-19
lines changed- redis/commands
- tests
- test_asyncio
4 files changed
+13
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
1674 | 1673 | | |
1675 | 1674 | | |
1676 | 1675 | | |
1677 | | - | |
| 1676 | + | |
1678 | 1677 | | |
1679 | 1678 | | |
1680 | 1679 | | |
| |||
1769 | 1768 | | |
1770 | 1769 | | |
1771 | 1770 | | |
1772 | | - | |
1773 | | - | |
| 1771 | + | |
1774 | 1772 | | |
1775 | 1773 | | |
1776 | 1774 | | |
1777 | 1775 | | |
1778 | | - | |
1779 | | - | |
| 1776 | + | |
1780 | 1777 | | |
1781 | 1778 | | |
1782 | 1779 | | |
| |||
1995 | 1992 | | |
1996 | 1993 | | |
1997 | 1994 | | |
1998 | | - | |
1999 | | - | |
| 1995 | + | |
2000 | 1996 | | |
2001 | 1997 | | |
2002 | 1998 | | |
| |||
2197 | 2193 | | |
2198 | 2194 | | |
2199 | 2195 | | |
2200 | | - | |
2201 | | - | |
| 2196 | + | |
2202 | 2197 | | |
2203 | 2198 | | |
2204 | 2199 | | |
2205 | 2200 | | |
2206 | | - | |
2207 | | - | |
| 2201 | + | |
2208 | 2202 | | |
2209 | 2203 | | |
2210 | 2204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
750 | 749 | | |
751 | 750 | | |
752 | 751 | | |
753 | | - | |
| 752 | + | |
754 | 753 | | |
755 | 754 | | |
756 | 755 | | |
| |||
875 | 874 | | |
876 | 875 | | |
877 | 876 | | |
878 | | - | |
879 | | - | |
| 877 | + | |
| 878 | + | |
880 | 879 | | |
881 | 880 | | |
882 | 881 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1185 | 1185 | | |
1186 | 1186 | | |
1187 | 1187 | | |
1188 | | - | |
| 1188 | + | |
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
| |||
1428 | 1428 | | |
1429 | 1429 | | |
1430 | 1430 | | |
1431 | | - | |
1432 | | - | |
| 1431 | + | |
| 1432 | + | |
1433 | 1433 | | |
1434 | 1434 | | |
1435 | 1435 | | |
| |||
0 commit comments