MCPcopy Index your code
hub / github.com/pydata/xarray / format_timestamp

Function format_timestamp

xarray/core/formatting.py:149–166  ·  view source on GitHub ↗

Cast given object to a Timestamp and return a nicely formatted string

(t)

Source from the content-addressed store, hash-verified

147
148
149def 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
169def format_timedelta(t, timedelta_format=None):

Callers 3

format_itemFunction · 0.85

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…