Cast given object to a Timestamp and return a nicely formatted string
(t)
| 147 | |
| 148 | |
| 149 | def format_timestamp(t): |
| 150 | """Cast given object to a Timestamp and return a nicely formatted string""" |
| 151 | try: |
| 152 | timestamp = pd.Timestamp(t) |
| 153 | datetime_str = timestamp.isoformat(sep=" ") |
| 154 | except OutOfBoundsDatetime: |
| 155 | datetime_str = str(t) |
| 156 | |
| 157 | try: |
| 158 | date_str, time_str = datetime_str.split() |
| 159 | except ValueError: |
| 160 | # catch NaT and others that don't split nicely |
| 161 | return datetime_str |
| 162 | else: |
| 163 | if time_str == "00:00:00": |
| 164 | return date_str |
| 165 | else: |
| 166 | return f"{date_str}T{time_str}" |
| 167 | |
| 168 | |
| 169 | def format_timedelta(t, timedelta_format=None): |
no test coverage detected
searching dependent graphs…