|
1 | 1 | import datetime as pdt
|
2 |
| -import sys |
3 | 2 | import platform
|
| 3 | +import struct |
| 4 | +import sys |
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 | import rustapi_module.datetime as rdt
|
@@ -40,16 +41,27 @@ def tzname(self, dt):
|
40 | 41 | MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6)
|
41 | 42 | MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6)
|
42 | 43 |
|
43 |
| -IS_X86 = platform.architecture()[0] == "32bit" |
| 44 | +# The reason we don't use platform.architecture() here is that it's not |
| 45 | +# reliable on macOS. See https://stackoverflow.com/a/1405971/823869. Similarly, |
| 46 | +# sys.maxsize is not reliable on Windows. See |
| 47 | +# https://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode-on-os/1405971#comment6209952_1405971 |
| 48 | +# and https://stackoverflow.com/a/3411134/823869. |
| 49 | +_pointer_size = struct.calcsize("P") |
| 50 | +if _pointer_size == 8: |
| 51 | + IS_32_BIT = False |
| 52 | +elif _pointer_size == 4: |
| 53 | + IS_32_BIT = True |
| 54 | +else: |
| 55 | + raise RuntimeError("unexpected pointer size: " + repr(_pointer_size)) |
44 | 56 | IS_WINDOWS = sys.platform == "win32"
|
45 | 57 | if IS_WINDOWS:
|
46 | 58 | MIN_DATETIME = pdt.datetime(1970, 1, 2, 0, 0)
|
47 |
| - if IS_X86: |
| 59 | + if IS_32_BIT: |
48 | 60 | MAX_DATETIME = pdt.datetime(3001, 1, 19, 4, 59, 59)
|
49 | 61 | else:
|
50 | 62 | MAX_DATETIME = pdt.datetime(3001, 1, 19, 7, 59, 59)
|
51 | 63 | else:
|
52 |
| - if IS_X86: |
| 64 | + if IS_32_BIT: |
53 | 65 | # TS ±2147483648 (2**31)
|
54 | 66 | MIN_DATETIME = pdt.datetime(1901, 12, 13, 20, 45, 52)
|
55 | 67 | MAX_DATETIME = pdt.datetime(2038, 1, 19, 3, 14, 8)
|
|
0 commit comments