@@ -83,25 +83,34 @@ def test_bool_to_connection_string_arg(key: str, value: bool, expected: str) ->
83
83
"value, expected_datetime, expected_str" , [
84
84
(
85
85
bytes ([
86
- 0xE5 , 0x07 , # year: 2022
87
- 0x0C , 0x00 , # month: 12
88
- 0x11 , 0x00 , # day: 17
89
- 0x16 , 0x00 , # hour: 22
90
- 0x16 , 0x00 , # minute: 22
91
- 0x12 , 0x00 , # second: 18
92
- 0x15 , 0xCD , 0x5B , 0x07 , # microsecond: 123456789
93
- 0x02 , 0x00 , 0x1E , 0x00 # tzinfo: +02:30
86
+ 0xE5 , 0x07 , # 2022 year unsigned short
87
+ 0x0C , 0x00 , # 12 month unsigned short
88
+ 0x11 , 0x00 , # 17 day unsigned short
89
+ 0x16 , 0x00 , # 17 hour unsigned short
90
+ 0x16 , 0x00 , # 52 minute unsigned short
91
+ 0x12 , 0x00 , # 18 second unsigned short
92
+ 0xBC , 0xCC , 0x5B , 0x07 , # 123456700 10⁻⁷ second unsigned long
93
+ 0xFE , 0xFF , # -2 offset hour signed short
94
+ 0xE2 , 0xFF # -30 offset minute signed short
94
95
]),
95
- dt .datetime (2022 , 12 , 17 , 22 , 22 , 18 , 123456 , dt .timezone (dt .timedelta (hours = 2 , minutes = 30 ))),
96
- "2021-12-17 22:22:18.123456+02:30"
96
+ dt .datetime (
97
+ year = 2022 ,
98
+ month = 12 ,
99
+ day = 17 ,
100
+ hour = 17 ,
101
+ minute = 52 ,
102
+ second = 18 ,
103
+ microsecond = 123456700 // 1000 , # 10⁻⁶ second
104
+ tzinfo = dt .timezone (dt .timedelta (hours = - 2 , minutes = - 30 ))
105
+ ),
106
+ "2021-12-17 17:52:18.123456-02:30"
97
107
)
98
108
]
99
109
)
100
110
def test_byte_array_to_datetime (value : bytes , expected_datetime : dt .datetime , expected_str : str ) -> None :
101
111
"""
102
- Assert SQL_SS_TIMESTAMPOFFSET_STRUCT bytes convert to string in an expected isoformat
103
- https://docs.python.org/3/library/datetime.html#datetime.datetime.__str__
112
+ Assert SQL_SS_TIMESTAMPOFFSET_STRUCT bytes are converted to datetime and str
104
113
https://learn.microsoft.com/sql/relational-databases/native-client-odbc-date-time/data-type-support-for-odbc-date-and-time-improvements#sql_ss_timestampoffset_struct
105
114
"""
106
115
assert byte_array_to_datetime (value ) == expected_datetime
107
- assert str (byte_array_to_datetime (value )) == expected_str
116
+ assert str (byte_array_to_datetime (value )) == expected_str
0 commit comments