rdblue commented on code in PR #4908:
URL: https://github.com/apache/iceberg/pull/4908#discussion_r885103817
##########
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)
Review Comment:
Time shouldn't use epoch. There's no need to mix dates into this.
Getting a time is actually straightforward:
```python
def time_from_micros(micros: int) -> time:
seconds = micros // 1_000_000
minutes = seconds // 60
hours = minutes // 60
time(hour=hours, minute=minutes % 60, second=seconds % 60,
microsecond=micros % 1_000_000)
```
--
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]