jun-he commented on code in PR #4908:
URL: https://github.com/apache/iceberg/pull/4908#discussion_r889757285
##########
python/src/iceberg/utils/datetime.py:
##########
@@ -63,3 +65,27 @@ def timestamptz_to_micros(timestamptz_str: str) -> int:
if ISO_TIMESTAMPTZ.fullmatch(timestamptz_str):
return datetime_to_micros(datetime.fromisoformat(timestamptz_str))
raise ValueError(f"Invalid timestamp with zone: {timestamptz_str} (must be
ISO-8601)")
+
+
+def to_human_day(day_ordinal: int) -> str:
+ """Converts a DateType value to human string"""
+ to_time = EPOCH_TIMESTAMP + timedelta(days=day_ordinal)
+ return "{0:0=4d}-{1:0=2d}-{2:0=2d}".format(to_time.year, to_time.month,
to_time.day)
+
+
+def to_human_time(micros_from_midnight: int) -> str:
+ """Converts a TimeType value to human string"""
+ to_day = EPOCH_TIMESTAMP + timedelta(microseconds=micros_from_midnight)
+ return f"{to_day.time()}"
+
+
+def to_human_timestamptz(timestamp_micros: int) -> str:
+ """Converts a TimestamptzType value to human string"""
+ to_timestamptz = EPOCH_TIMESTAMP + timedelta(microseconds=timestamp_micros)
+ return
pytz.timezone("UTC").localize(to_timestamptz).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
+
+
+def to_human_timestamp(timestamp_micros: int) -> str:
+ """Converts a TimestampType value to human string"""
+ to_timestamp = EPOCH_TIMESTAMP + timedelta(microseconds=timestamp_micros)
+ return to_timestamp.isoformat()
Review Comment:
👌
##########
python/src/iceberg/utils/datetime.py:
##########
@@ -63,3 +65,27 @@ def timestamptz_to_micros(timestamptz_str: str) -> int:
if ISO_TIMESTAMPTZ.fullmatch(timestamptz_str):
return datetime_to_micros(datetime.fromisoformat(timestamptz_str))
raise ValueError(f"Invalid timestamp with zone: {timestamptz_str} (must be
ISO-8601)")
+
+
+def to_human_day(day_ordinal: int) -> str:
+ """Converts a DateType value to human string"""
+ to_time = EPOCH_TIMESTAMP + timedelta(days=day_ordinal)
+ return "{0:0=4d}-{1:0=2d}-{2:0=2d}".format(to_time.year, to_time.month,
to_time.day)
Review Comment:
Fixed.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]