Format a timestamp value.
(val, unit)
| 294 | |
| 295 | |
| 296 | def format_timestamp(val, unit): |
| 297 | """ |
| 298 | Format a timestamp value. |
| 299 | """ |
| 300 | val = int(val) |
| 301 | unit = int(unit) |
| 302 | short_unit = short_time_unit(unit) |
| 303 | traits = time_unit_traits[unit] |
| 304 | seconds, subseconds = divmod(val, traits.multiplier) |
| 305 | try: |
| 306 | dt = datetime.datetime.utcfromtimestamp(seconds) |
| 307 | except (ValueError, OSError, OverflowError): |
| 308 | # value out of range for datetime.datetime |
| 309 | pretty = "too large to represent" |
| 310 | else: |
| 311 | pretty = dt.isoformat().replace('T', ' ') |
| 312 | if traits.fractional_digits > 0: |
| 313 | pretty += f".{subseconds:0{traits.fractional_digits}d}" |
| 314 | return f"{val}{short_unit} [{pretty}]" |
| 315 | |
| 316 | |
| 317 | def cast_to_concrete(val, ty): |
no test coverage detected