| 
5 | 5 | #  | 
6 | 6 | 
 
  | 
7 | 7 | import time  | 
8 |  | -from datetime import timedelta, datetime  | 
 | 8 | +from datetime import timedelta, datetime, date  | 
9 | 9 | from logging import getLogger  | 
10 | 10 | 
 
  | 
11 | 11 | import pytz  | 
12 | 12 | 
 
  | 
13 |  | -from .compat import TO_UNICODE  | 
 | 13 | +from .compat import TO_UNICODE, IS_WINDOWS  | 
14 | 14 | from .constants import (is_timestamp_type_name, is_date_type_name)  | 
15 | 15 | from .converter import (SnowflakeConverter, ZERO_EPOCH, _extract_timestamp)  | 
16 | 16 | from .sfbinaryformat import (binary_to_python, SnowflakeBinaryFormat)  | 
@@ -72,10 +72,11 @@ def to_python_method(self, type_name, column):  | 
72 | 72 |             ctx['zero_fill'] = '0' * (9 - ctx['scale'])  | 
73 | 73 |         fmt = None  | 
74 | 74 |         if is_date_type_name(type_name):  | 
 | 75 | +            datetime_class = time.struct_time if not IS_WINDOWS else date  | 
75 | 76 |             fmt = SnowflakeDateFormat(  | 
76 | 77 |                 self._get_format(type_name),  | 
77 | 78 |                 support_negative_year=self._support_negative_year,  | 
78 |  | -                datetime_class=time.struct_time)  | 
 | 79 | +                datetime_class=datetime_class)  | 
79 | 80 |         elif is_timestamp_type_name(type_name):  | 
80 | 81 |             fmt = SnowflakeDateTimeFormat(  | 
81 | 82 |                 self._get_format(type_name),  | 
@@ -121,14 +122,19 @@ def _BINARY_to_python(self, ctx):  | 
121 | 122 | 
 
  | 
122 | 123 |     def _DATE_to_python(self, ctx):  | 
123 | 124 |         """  | 
124 |  | -        DATE to datetime  | 
 | 125 | +        DATE to struct_time/date  | 
125 | 126 | 
  | 
126 | 127 |         No timezone is attached.  | 
127 | 128 |         """  | 
 | 129 | + | 
128 | 130 |         def conv(value):  | 
129 | 131 |             return ctx['fmt'].format(time.gmtime(int(value) * (24 * 60 * 60)))  | 
130 | 132 | 
 
  | 
131 |  | -        return conv  | 
 | 133 | +        def conv_windows(value):  | 
 | 134 | +            ts = ZERO_EPOCH + timedelta(seconds=int(value) * (24 * 60 * 60))  | 
 | 135 | +            return ctx['fmt'].format(date(ts.year, ts.month, ts.day))  | 
 | 136 | + | 
 | 137 | +        return conv if not IS_WINDOWS else conv_windows  | 
132 | 138 | 
 
  | 
133 | 139 |     def _TIMESTAMP_TZ_to_python(self, ctx):  | 
134 | 140 |         """  | 
 | 
0 commit comments