Package: cytimes
Easy management of python datetime & pandas time Series.Created to be used in a project, this package is published to github
for ease of management and installation across different modules.FeaturesProvides two classes for datetime and pandas time series management.pydt(Python Datetime)pddt(Pandas Time Series)Both provide similar functionalities:Parse time stringAccess in different data typesConversion toint/float(ordinal, total_seconds, timestamp, etc.)Calender properties (days_in_month, weekday, etc.)Day manipulation (next_week, to_week, etc.)Month manipulation (next_month, to_month, etc.)Quarter manipulation (next_quarter, to_quarter, etc.)Year manipulation (next_year, to_year, etc.)Timezone manipulation (tz_localize, tz_convert, etc.)Frequency manipulation (round, ceil, floor, etc.)Delta adjustment (Equivalent to addingrelativedeltaandpandas.DateOffset)Replace adjustment (Equivalent todatetime.replaceand custompandas.Series.replace)InstallationInstall fromPyPipipinstallcytimesInstall fromgithubpipinstallgit+https://github.com/AresJef/cyTimes.gitCompatibilityOnly support for python 3.10 and above.Usage (pydt)importdatetime,numpyasnp,pandasaspdfromcytimesimportpydt# Parse time stringpt=pydt('2021-01-01 00:00:00')# 2021-01-01T00:00:00pt=pydt("2021 Jan 1 11:11 AM")# 2021-01-01T11:11:00# dateimte/date/timept=pydt(datetime.datetime(2021,1,1,0,0,0))# 2021-01-01T00:00:00pt=pydt(datetime.date(2021,1,1))# 2021-01-01T00:00:00pt=pydt(datetime.time(12,0,0))# date defaults to today. Can change through default arugment.# 2023-09-01T12:00:00# pandas.Timestamppt=pydt(pd.Timestamp("2021-01-01 00:00:00"))# 2021-01-01T00:00:00# numpy.datetime64pt=pydt(np.datetime64("2021-01-01 00:00:00"))# 2021-01-01T00:00:00# Access in different data typespt.dt# -> datetime.datetimept.date# -> datetime.datept.time# -> datetime.timept.timetz# -> datetime.time with timezonept.ts# -> pandas.Timestamppt.dt64# -> numpy.datetime64...# Conversion to int/floatpt.ordinal# -> intpt.timestamp# -> float...# Calender propertiespt.is_leap_year# -> boolpt.days_bf_year# -> intpt.days_in_month# -> intpt.weekday# -> intpt.isocalendar# -> tuple# Day manipulationpt.monday# -> pydt (monday of the week)pt.tuesday# -> pydt (tuesday of the week)pt.next_week("monday")# -> pydt (next monday)pt.to_week(3,"Mon")# -> pydt (three weeks later monday )...# Month manipulationpt.month_lst# -> pydt (last day of the month)pt.next_month(3)# -> pydt (next month 3rd day)pt.to_month(3,31)# -> pydt (three months later last day)...# Quarter manipulationpt.quarter_1st# -> pydt (first day of the quarter)pt.next_quarter(2,10)# -> pydt (next quarter 2nd month 10th day)pt.to_quarter(2,10,15)# -> pydt (two quarters later 2nd month 15th day)...# Year manipulationpt.year_lst# -> pydt (last day of the year)pt.next_year("jan",1)# -> pydt (next year jan 1st)pt.to_year(2,"feb",29)# -> pydt (two years later feb last day)...# Timezone manipulationpt.tz_localize("UTC")# -> pydt (UTC time)pt.tz_switch(targ_tz="CET",base_tz="UTC")# -> pydt (Setting base timezone to UTC and convert to CET)...# Frequency manipulationpt.round("H")# -> pydt (round to hour)...# Delta adjustmentpt.delta(days=1)# -> pydt (add one day)# Replace adjustmentpt.replace(year=2022)# -> pydt (replace year to 2022)Usage (pddt)pddtacceptslistandpandas.Seriesas argument instead ofstr/datetimecomparing topydt. Properties and methods are similar topydt, exceptpddtis designed to work withpandas.Series[datetime64].AcknowledgementscyTimes is based on several open-source repositories.numpypandascyTimes makes modification of the following open-source repositories:dateutilThis package created a Cythonized version of dateutil.parser (cyparser) and
dateutil.relativedelta (cytimedelta). As a result, these two modules in
this package have sacrificed flexibility and readability in exchange for
enhancements in performance. All credits go to the original authors and
contributors of dateutil.