Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions timescale/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
UPDATE HISTORY:
Updated 07/2026: add HTML representations of Timescale and Calendar
added attributes for tai_utc and loran_utc
added timezone option to to_string to allow local time outputs
added strftime function to output customized datetime strings
Updated 05/2026: added functions to update delta time files from project
updated CDDIS ftp login options for encrypted connections
Updated 04/2026: added endpoint option (defaults to True) to date_range
Expand Down Expand Up @@ -1001,7 +1003,7 @@ def to_deltatime(
# return the date in time (default days) since epoch
return scale * np.array(self.MJD - delta_time_epochs, dtype=np.float64)

def to_datetime(self, unit="ns"):
def to_datetime(self, unit="ns", **kwargs):
"""
Convert a ``Timescale`` object to a ``datetime`` array

Expand All @@ -1020,20 +1022,37 @@ def to_datetime(self, unit="ns"):
# return the datetime array
return np.array(epoch + delta_time.astype(f"timedelta64[{unit}]"))

def to_string(self, unit: str = "s", **kwargs):
def to_string(self, unit: str = "s", timezone="naive", **kwargs):
"""
Convert a ``Timescale`` object to a formatted string array

Parameters
----------
unit: str, default 's'
datetime unit for output string array
timezone: str, default 'naive'
timezone for output string array
**kwargs: dict
keyword arguments for datetime formatting
"""
return np.datetime_as_string(
self.to_datetime(unit=unit), unit=unit, **kwargs
)
# convert to datetime objects
dtime = self.to_datetime(unit=unit, **kwargs)
return np.datetime_as_string(dtime, unit=unit, timezone=timezone)

def strftime(self, format: str, **kwargs):
"""
Convert a ``Timescale`` object to a custom formatted string array

Parameters
----------
format: str
formatting string for output string array
**kwargs: dict
keyword arguments for datetime formatting
"""
# convert to datetime objects
dtime = self.to_datetime(**kwargs).astype(datetime.datetime)
return np.array([d.strftime(format) for d in dtime])
Comment on lines +1032 to +1064

# PURPOSE: calculate the sum of a polynomial function of time
def polynomial_sum(self, coefficients: list | np.ndarray, t: np.ndarray):
Expand Down
Loading