liferoad commented on code in PR #26962:
URL: https://github.com/apache/beam/pull/26962#discussion_r1213823853
##########
sdks/python/apache_beam/utils/timestamp.py:
##########
@@ -156,12 +156,24 @@ def __repr__(self):
return 'Timestamp(%s%d.%06d)' % (sign, int_part, frac_part)
return 'Timestamp(%s%d)' % (sign, int_part)
- def to_utc_datetime(self):
- # type: () -> datetime.datetime
+ def to_utc_datetime(self, has_tz=False):
+ # type: (bool) -> datetime.datetime
+
+ """Returns a ``datetime.datetime`` object of UTC for this Timestamp.
+
+ Args:
+ has_tz: whether the timezone info is attached, default to False.
+
+ Returns:
+ a ``datetime.datetime`` object of UTC for this Timestamp.
+ """
+
# We can't easily construct a datetime object from microseconds, so we
# create one at the epoch and add an appropriate timedelta interval.
- return self._epoch_datetime_utc().replace(tzinfo=None) +
datetime.timedelta(
- microseconds=self.micros)
+ epoch = self._epoch_datetime_utc()
+ if not has_tz:
+ epoch = epoch.replace(tzinfo=None)
+ return epoch + datetime.timedelta(microseconds=self.micros)
Review Comment:
How could we inform users when using
`temp_file_format=bigquery_tools.FileFormat.AVRO`, you should set has_tz=True?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]