def datetime64_to_date(dt64: np.datetime64) -> datetime.date: """Convert a np.datetime64('D') to a datetime.date""" return dt64.astype(datetime.date)
def _represent_numpy_datetime(self, data: numpy.datetime64): return _represent_datetime(self, data.astype("M8[ms]").tolist())
def _get_datetime(time: np.datetime64) -> date: return datetime.strptime(time.astype(str)[:10], "%Y-%m-%d").date()
def offset_from_center(v: numpy.datetime64): return p.datetime + timedelta(microseconds=v.astype(float) * 1_000_000.0)
def _grid_date(self, date: np.datetime64, shift: int): """Calculates the grid date immediately before or after the date provided""" if date.astype("int64") % self.dt.astype("int64") != 0: return date + self.dt * shift return date
def date_to_str(d: np.datetime64) -> str: """Convert from np.datetime64 to str without hyphens""" return d.astype(str).replace("-", "")
def _iso_date(date: np.datetime64) -> str: """Return the time formatted according to ISO.""" return datetime.datetime.utcfromtimestamp( date.astype("datetime64[us]").astype("int64") * 1e-6).isoformat() + "Z"
def _iso_date(date: np.datetime64) -> str: """Return the time formatted according to ISO.""" epoch = date.astype("datetime64[us]").astype( "int64") * 1e-6 # type: ignore return datetime.datetime.utcfromtimestamp(epoch).strftime( "%Y-%m-%dT%H:%M:%S.%fZ")
def _floor_to_dt(value: np.datetime64) -> np.datetime64: """Floor a datetime64 to the nearest dt.""" integral = int(value.astype("<M8[h]").astype("int64") / 3) # type: ignore return np.datetime64(integral * 3, "h")