Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion python/pyspark/sql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def fromInternal(self, v):
return datetime.date.fromordinal(v + self.EPOCH_ORDINAL)


_is_utc = time.tzname[time.daylight] == "UTC"


class TimestampType(AtomicType):
"""Timestamp (datetime.datetime) data type.
"""
Expand All @@ -196,7 +199,10 @@ def toInternal(self, dt):
def fromInternal(self, ts):
if ts is not None:
# using int to avoid precision loss in float
return datetime.datetime.fromtimestamp(ts // 1000000).replace(microsecond=ts % 1000000)
y, m, d, hh, mm, ss, _, _, _ = (time.gmtime(ts // 1000000) if _is_utc
else time.localtime(ts // 1000000))
ss = min(ss, 59) # leap seconds support
return datetime.datetime(y, m, d, hh, mm, ss, ts % 1000000)


class DecimalType(FractionalType):
Expand Down