Timestamp ========= .. currentmodule:: pandasCore .. class:: Timestamp Pandas-compatible Timestamp representing a single moment in time. Example ------- .. code-block:: python import pandasCore as pd # Create Timestamp obj = pd.Timestamp(...) Attributes ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Attribute - Description - Example * - :attr:`~Timestamp.day` - Return the day of the month (1-31) - :ref:`View ` * - :attr:`~Timestamp.day_of_week` - Return the day of the week (0=Monday, 6=Sunday) - * - :attr:`~Timestamp.day_of_year` - Return the day of the year (1-366) - * - :attr:`~Timestamp.dayofweek` - Return the day of the week (0=Monday, 6=Sunday) - :ref:`View ` * - :attr:`~Timestamp.dayofyear` - Return the day of the year (1-366) - :ref:`View ` * - :attr:`~Timestamp.days_in_month` - Return the number of days in the month - * - :attr:`~Timestamp.fold` - Return the fold value for DST disambiguation - * - :attr:`~Timestamp.hour` - Return the hour (0-23) - :ref:`View ` * - :attr:`~Timestamp.is_leap_year` - Return True if the year is a leap year - * - :attr:`~Timestamp.is_month_end` - Return True if the date is the last day of the month - * - :attr:`~Timestamp.is_month_start` - Return True if the date is the first day of the month - * - :attr:`~Timestamp.is_quarter_end` - Return True if the date is the last day of the quarter - * - :attr:`~Timestamp.is_quarter_start` - Return True if the date is the first day of the quarter - * - :attr:`~Timestamp.is_year_end` - Return True if the date is the last day of the year - * - :attr:`~Timestamp.is_year_start` - Return True if the date is the first day of the year - * - :attr:`~Timestamp.isnat` - Return True if the Timestamp is NaT (Not a Timestamp) - * - :attr:`~Timestamp.microsecond` - Return the microsecond (0-999999) - :ref:`View ` * - :attr:`~Timestamp.minute` - Return the minute (0-59) - :ref:`View ` * - :attr:`~Timestamp.month` - Return the month (1-12) - :ref:`View ` * - :attr:`~Timestamp.nanosecond` - Return the nanosecond (0-999) - :ref:`View ` * - :attr:`~Timestamp.quarter` - Return the quarter (1-4) - :ref:`View ` * - :attr:`~Timestamp.second` - Return the second (0-59) - :ref:`View ` * - :attr:`~Timestamp.tz` - Return the timezone name - * - :attr:`~Timestamp.tzinfo` - Return the timezone name - * - :attr:`~Timestamp.value` - Return the value as nanoseconds since epoch - :ref:`View ` * - :attr:`~Timestamp.week` - Return the ISO week number (1-53) - * - :attr:`~Timestamp.weekofyear` - Return the ISO week number (1-53) - * - :attr:`~Timestamp.year` - Return the year - :ref:`View ` Construction ------------ .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.__init__` ``(ts_input: object = None, year: object = None, month: object = None, day: object = None, hour: object = None, minute: object = None, second: object = None, microsecond: object = None, tzinfo: object = None, *, nanosecond: object = None, tz: object = None, unit: object = None, fold: object = None)`` - Create a Timestamp from various inputs (pandas-compatible). - :ref:`View ` Data Manipulation ----------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.replace` ``(year: object = None, month: object = None, day: object = None, hour: object = None, minute: object = None, second: object = None, microsecond: object = None, nanosecond: object = None, tzinfo: object = None, fold: object = None)`` - Return Timestamp with fields replaced. - :ref:`View ` Arithmetic ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.__add__` ``(*args, **kwargs) | (arg0: numpy::timedelta64) | (arg0: object)`` - - * - :meth:`~Timestamp.__sub__` ``(*args, **kwargs) | (arg0: numpy::timedelta64) | (arg0: pandasCore.Timestamp) | (arg0: object)`` - - Comparison ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.__eq__` ``(arg0: pandasCore.Timestamp)`` - - * - :meth:`~Timestamp.__ge__` ``(arg0: pandasCore.Timestamp)`` - - * - :meth:`~Timestamp.__gt__` ``(arg0: pandasCore.Timestamp)`` - - * - :meth:`~Timestamp.__le__` ``(arg0: pandasCore.Timestamp)`` - - * - :meth:`~Timestamp.__lt__` ``(arg0: pandasCore.Timestamp)`` - - * - :meth:`~Timestamp.__ne__` ``(arg0: pandasCore.Timestamp)`` - - Time Series ----------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.to_period` ``(freq: object = None)`` - Convert Timestamp to a Period. - * - :meth:`~Timestamp.tz_convert` ``(tz: str)`` - Convert tz-aware Timestamp to another timezone. - * - :meth:`~Timestamp.tz_localize` ``(tz: object, ambiguous: str = 'raise', nonexistent: str = 'raise')`` - Localize tz-naive Timestamp to a timezone. - I/O --- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.to_datetime64` ``()`` - Return as numpy datetime64 value - * - :meth:`~Timestamp.to_julian_date` ``()`` - Return the Julian Date - * - :meth:`~Timestamp.to_numpy` ``(dtype: object = None, copy: bool = False)`` - Return as numpy datetime64 value - * - :meth:`~Timestamp.to_pydatetime` ``(warn: bool = True)`` - Convert Timestamp to a Python datetime.datetime object. - Datetime Methods ---------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.ceil` ``(freq: str, ambiguous: str = 'raise', nonexistent: str = 'raise')`` - Round up the Timestamp to the specified resolution. - :ref:`View ` * - :meth:`~Timestamp.floor` ``(freq: str, ambiguous: str = 'raise', nonexistent: str = 'raise')`` - Round down the Timestamp to the specified resolution. - :ref:`View ` * - :meth:`~Timestamp.normalize` ``()`` - Normalize Timestamp to midnight, preserving tz information. - :ref:`View ` * - :meth:`~Timestamp.round` ``(freq: str, ambiguous: str = 'raise', nonexistent: str = 'raise')`` - Round the Timestamp to the specified resolution. - :ref:`View ` * - :meth:`~Timestamp.strftime` ``(format: str)`` - Return a string representing the Timestamp, controlled by a format ... - :ref:`View ` * - :meth:`~Timestamp.weekday` ``()`` - Return the day of the week (0=Monday, 6=Sunday) - Other Methods ------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Timestamp.__hash__` ``()`` - - * - :meth:`~Timestamp.__repr__` ``()`` - - * - :meth:`~Timestamp.__str__` ``()`` - - * - :meth:`~Timestamp.as_unit` ``(unit: str, round_ok: bool = True)`` - Convert Timestamp to target unit resolution. - * - :meth:`~Timestamp.astimezone` ``(tz: str)`` - Convert tz-aware Timestamp to another timezone - * - :meth:`~Timestamp.ctime` ``()`` - Return ctime() style string - * - :meth:`~Timestamp.date` ``()`` - Return a datetime.date object - * - :meth:`~Timestamp.day_name` ``(locale: object = None)`` - Return the name of the day of the week - :ref:`View ` * - :meth:`~Timestamp.dst` ``()`` - Return the daylight saving time (DST) offset. - * - :meth:`~Timestamp.isocalendar` ``()`` - Return a tuple containing ISO year, week number, and weekday. - :ref:`View ` * - :meth:`~Timestamp.isoformat` ``(sep: str = 'T', timespec: str = 'auto')`` - Return the time formatted according to ISO 8601. - :ref:`View ` * - :meth:`~Timestamp.isoweekday` ``()`` - Return the ISO weekday (1=Monday, 7=Sunday) - * - :meth:`~Timestamp.month_name` ``(locale: object = None)`` - Return the name of the month - :ref:`View ` * - :meth:`~Timestamp.time` ``()`` - Return a datetime.time object - * - :meth:`~Timestamp.timestamp` ``()`` - Return POSIX timestamp as float (seconds since epoch). - :ref:`View ` * - :meth:`~Timestamp.timetuple` ``()`` - Return time tuple, compatible with time.localtime(). - * - :meth:`~Timestamp.timetz` ``()`` - Return a datetime.time object with timezone info - * - :meth:`~Timestamp.toordinal` ``()`` - Return the proleptic Gregorian ordinal - * - :meth:`~Timestamp.tzname` ``()`` - Return the timezone abbreviation - * - :meth:`~Timestamp.utcoffset` ``()`` - Return the UTC offset. - * - :meth:`~Timestamp.utctimetuple` ``()`` - Return UTC time tuple - Code Examples ------------- The following examples are extracted from the test suite. .. _example-timestamp-day-0: .. dropdown:: day (test_timestamp.py:51) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 41 :emphasize-lines: 11 return False # Check month if ts.month == 1: f_print_success(f"month is correct: {ts.month}") else: f_print_error(f"month is wrong: {ts.month}, expected 1") return False # Check day if ts.day == 15: f_print_success(f"day is correct: {ts.day}") else: f_print_error(f"day is wrong: {ts.day}, expected 15") return False # Check hour if ts.hour == 12: f_print_success(f"hour is correct: {ts.hour}") else: f_print_error(f"hour is wrong: {ts.hour}, expected 12") .. _example-timestamp-dayofweek-1: .. dropdown:: dayofweek (test_timestamp.py:192) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 182 :emphasize-lines: 11 def test_derived_properties(): """Test Timestamp derived properties""" f_print_header("Test: Timestamp Derived Properties") try: # Create a Timestamp for 2021-01-15 (Friday) ts = pandasCore.Timestamp(2021, 1, 15, 12, 0, 0) # dayofweek (0=Monday, 6=Sunday) - Friday is 4 if ts.dayofweek == 4: f_print_success(f"dayofweek is correct: {ts.dayofweek} (Friday)") else: f_print_error(f"dayofweek is wrong: {ts.dayofweek}, expected 4 (Friday)") return False # dayofyear - Jan 15 is day 15 if ts.dayofyear == 15: f_print_success(f"dayofyear is correct: {ts.dayofyear}") else: f_print_error(f"dayofyear is wrong: {ts.dayofyear}, expected 15") .. _example-timestamp-dayofyear-2: .. dropdown:: dayofyear (test_timestamp.py:199) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 189 :emphasize-lines: 11 ts = pandasCore.Timestamp(2021, 1, 15, 12, 0, 0) # dayofweek (0=Monday, 6=Sunday) - Friday is 4 if ts.dayofweek == 4: f_print_success(f"dayofweek is correct: {ts.dayofweek} (Friday)") else: f_print_error(f"dayofweek is wrong: {ts.dayofweek}, expected 4 (Friday)") return False # dayofyear - Jan 15 is day 15 if ts.dayofyear == 15: f_print_success(f"dayofyear is correct: {ts.dayofyear}") else: f_print_error(f"dayofyear is wrong: {ts.dayofyear}, expected 15") return False # quarter if ts.quarter == 1: f_print_success(f"quarter is correct: {ts.quarter}") else: f_print_error(f"quarter is wrong: {ts.quarter}, expected 1") .. _example-timestamp-hour-3: .. dropdown:: hour (test_timestamp.py:58) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 48 :emphasize-lines: 11 return False # Check day if ts.day == 15: f_print_success(f"day is correct: {ts.day}") else: f_print_error(f"day is wrong: {ts.day}, expected 15") return False # Check hour if ts.hour == 12: f_print_success(f"hour is correct: {ts.hour}") else: f_print_error(f"hour is wrong: {ts.hour}, expected 12") return False # Check minute if ts.minute == 30: f_print_success(f"minute is correct: {ts.minute}") else: f_print_error(f"minute is wrong: {ts.minute}, expected 30") .. _example-timestamp-microsecond-4: .. dropdown:: microsecond (test_timestamp.py:79) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 69 :emphasize-lines: 11 return False # Check second if ts.second == 45: f_print_success(f"second is correct: {ts.second}") else: f_print_error(f"second is wrong: {ts.second}, expected 45") return False # Check microsecond if ts.microsecond == 123456: f_print_success(f"microsecond is correct: {ts.microsecond}") else: f_print_error(f"microsecond is wrong: {ts.microsecond}, expected 123456") return False # Check nanosecond if ts.nanosecond == 789: f_print_success(f"nanosecond is correct: {ts.nanosecond}") else: f_print_error(f"nanosecond is wrong: {ts.nanosecond}, expected 789") .. _example-timestamp-minute-5: .. dropdown:: minute (test_timestamp.py:65) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 55 :emphasize-lines: 11 return False # Check hour if ts.hour == 12: f_print_success(f"hour is correct: {ts.hour}") else: f_print_error(f"hour is wrong: {ts.hour}, expected 12") return False # Check minute if ts.minute == 30: f_print_success(f"minute is correct: {ts.minute}") else: f_print_error(f"minute is wrong: {ts.minute}, expected 30") return False # Check second if ts.second == 45: f_print_success(f"second is correct: {ts.second}") else: f_print_error(f"second is wrong: {ts.second}, expected 45") .. _example-timestamp-month-6: .. dropdown:: month (test_timestamp.py:44) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 34 :emphasize-lines: 11 f_print_success("Created Timestamp from components") # Check year if ts.year == 2021: f_print_success(f"year is correct: {ts.year}") else: f_print_error(f"year is wrong: {ts.year}, expected 2021") return False # Check month if ts.month == 1: f_print_success(f"month is correct: {ts.month}") else: f_print_error(f"month is wrong: {ts.month}, expected 1") return False # Check day if ts.day == 15: f_print_success(f"day is correct: {ts.day}") else: f_print_error(f"day is wrong: {ts.day}, expected 15") .. _example-timestamp-nanosecond-7: .. dropdown:: nanosecond (test_timestamp.py:86) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 76 :emphasize-lines: 11 return False # Check microsecond if ts.microsecond == 123456: f_print_success(f"microsecond is correct: {ts.microsecond}") else: f_print_error(f"microsecond is wrong: {ts.microsecond}, expected 123456") return False # Check nanosecond if ts.nanosecond == 789: f_print_success(f"nanosecond is correct: {ts.nanosecond}") else: f_print_error(f"nanosecond is wrong: {ts.nanosecond}, expected 789") return False # Check repr repr_str = repr(ts) f_print_info(f"repr: {repr_str}") return True .. _example-timestamp-quarter-8: .. dropdown:: quarter (test_timestamp.py:206) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 196 :emphasize-lines: 11 return False # dayofyear - Jan 15 is day 15 if ts.dayofyear == 15: f_print_success(f"dayofyear is correct: {ts.dayofyear}") else: f_print_error(f"dayofyear is wrong: {ts.dayofyear}, expected 15") return False # quarter if ts.quarter == 1: f_print_success(f"quarter is correct: {ts.quarter}") else: f_print_error(f"quarter is wrong: {ts.quarter}, expected 1") return False # Create a Timestamp for leap year check (2020) ts_leap = pandasCore.Timestamp(2020, 2, 29, 0, 0, 0) if ts_leap.is_leap_year: f_print_success("is_leap_year is correct: True for 2020") else: .. _example-timestamp-second-9: .. dropdown:: second (test_timestamp.py:72) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 62 :emphasize-lines: 11 return False # Check minute if ts.minute == 30: f_print_success(f"minute is correct: {ts.minute}") else: f_print_error(f"minute is wrong: {ts.minute}, expected 30") return False # Check second if ts.second == 45: f_print_success(f"second is correct: {ts.second}") else: f_print_error(f"second is wrong: {ts.second}, expected 45") return False # Check microsecond if ts.microsecond == 123456: f_print_success(f"microsecond is correct: {ts.microsecond}") else: f_print_error(f"microsecond is wrong: {ts.microsecond}, expected 123456") .. _example-timestamp-value-10: .. dropdown:: value (test_date_range_comp.py:42) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 32 :emphasize-lines: 11 # Helpers # ============================================================================= def _compare_lengths(pd_idx, pc_idx, label): """Compare index lengths between pandas and pandasCore.""" ctx.assert_equal(len(pd_idx), len(pc_idx), f"{label} length") def _pd_to_ns(ts): """Convert pandas Timestamp to nanoseconds since epoch.""" return int(ts.value) def _compare_first_last(pd_idx, pc_idx, label): """Compare first/last values by nanosecond epoch.""" pd_first = _pd_to_ns(pd_idx[0]) pd_last = _pd_to_ns(pd_idx[len(pd_idx) - 1]) pc_first = int(pc_idx[0]) pc_last = int(pc_idx[len(pc_idx) - 1]) ctx.assert_equal(pd_first, pc_first, f"{label} first value") ctx.assert_equal(pd_last, pc_last, f"{label} last value") .. _example-timestamp-year-11: .. dropdown:: year (test_timestamp.py:37) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 27 :emphasize-lines: 11 def test_construction_from_components(): """Test Timestamp construction from date/time components""" f_print_header("Test: Timestamp Construction from Components") try: # Create Timestamp from components ts = pandasCore.Timestamp(2021, 1, 15, 12, 30, 45, 123456, 789) f_print_success("Created Timestamp from components") # Check year if ts.year == 2021: f_print_success(f"year is correct: {ts.year}") else: f_print_error(f"year is wrong: {ts.year}, expected 2021") return False # Check month if ts.month == 1: f_print_success(f"month is correct: {ts.month}") else: f_print_error(f"month is wrong: {ts.month}, expected 1") .. _example-timestamp-dunder-initdunder--12: .. dropdown:: __init__ (test_dateoffset_comp.py:42) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 32 :emphasize-lines: 11 # ==================== apply() Tests ==================== # Note: pandas 2.x removed public .apply() on offsets. # We compare pandasCore apply() results against ts + offset in pandas. def test_day_apply(): """Test Day.apply() matches pandas ts + offset""" f_print_header("Test: Day.apply()") pc_day = pandasCore.Day(n=1) pc_ts = pandasCore.Timestamp('2023-01-15') pc_result = pc_day.apply(pc_ts) pd_ts = pd.Timestamp('2023-01-15') pd_result = pd_ts + pd.offsets.Day(n=1) ctx.assert_equal(str(pd_result)[:10], str(pc_result)[:10], "Day(1).apply(Jan 15)") # Multi-day pc_day5 = pandasCore.Day(n=5) pc_r5 = pc_day5.apply(pc_ts) .. _example-timestamp-replace-13: .. dropdown:: replace (test_timestamp.py:412) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 402 :emphasize-lines: 11 def test_replace_method(): """Test Timestamp replace method""" f_print_header("Test: Timestamp replace Method") try: ts = pandasCore.Timestamp(2021, 1, 15, 12, 30, 45) # Replace year ts_new_year = ts.replace(year=2022) if ts_new_year.year == 2022 and ts_new_year.month == 1 and ts_new_year.day == 15: f_print_success(f"replace(year=2022) correct: {ts_new_year.year}-{ts_new_year.month}-{ts_new_year.day}") else: f_print_error(f"replace(year=2022) wrong") return False # Replace month and day ts_new_date = ts.replace(month=6, day=20) if ts_new_date.year == 2021 and ts_new_date.month == 6 and ts_new_date.day == 20: f_print_success(f"replace(month=6, day=20) correct: {ts_new_date.year}-{ts_new_date.month}-{ts_new_date.day}") .. _example-timestamp-ceil-14: .. dropdown:: ceil (test_timestamp.py:312) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 302 :emphasize-lines: 11 # Floor to hour ts_floor = ts.floor("H") if ts_floor.hour == 14 and ts_floor.minute == 0 and ts_floor.second == 0: f_print_success(f"floor('H') correct: {ts_floor.hour}:{ts_floor.minute}:{ts_floor.second}") else: f_print_error(f"floor('H') wrong: {ts_floor.hour}:{ts_floor.minute}:{ts_floor.second}") return False # Ceil to hour ts_ceil = ts.ceil("H") if ts_ceil.hour == 15 and ts_ceil.minute == 0: f_print_success(f"ceil('H') correct: {ts_ceil.hour}:{ts_ceil.minute}:{ts_ceil.second}") else: f_print_error(f"ceil('H') wrong: {ts_ceil.hour}:{ts_ceil.minute}:{ts_ceil.second}") return False # Round to hour (37 minutes rounds down) ts_round = ts.round("H") if ts_round.hour == 15: f_print_success(f"round('H') correct: {ts_round.hour}:{ts_round.minute}") .. _example-timestamp-floor-15: .. dropdown:: floor (test_timestamp.py:304) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 294 :emphasize-lines: 11 def test_rounding_methods(): """Test Timestamp rounding methods""" f_print_header("Test: Timestamp Rounding Methods") try: # Create a Timestamp with all components ts = pandasCore.Timestamp(2021, 1, 15, 14, 37, 45, 123456, 789) # Floor to hour ts_floor = ts.floor("H") if ts_floor.hour == 14 and ts_floor.minute == 0 and ts_floor.second == 0: f_print_success(f"floor('H') correct: {ts_floor.hour}:{ts_floor.minute}:{ts_floor.second}") else: f_print_error(f"floor('H') wrong: {ts_floor.hour}:{ts_floor.minute}:{ts_floor.second}") return False # Ceil to hour ts_ceil = ts.ceil("H") if ts_ceil.hour == 15 and ts_ceil.minute == 0: f_print_success(f"ceil('H') correct: {ts_ceil.hour}:{ts_ceil.minute}:{ts_ceil.second}") .. _example-timestamp-normalize-16: .. dropdown:: normalize (test_timestamp.py:328) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 318 :emphasize-lines: 11 # Round to hour (37 minutes rounds down) ts_round = ts.round("H") if ts_round.hour == 15: f_print_success(f"round('H') correct: {ts_round.hour}:{ts_round.minute}") else: f_print_error(f"round('H') wrong: {ts_round.hour}") return False # Normalize (floor to day) ts_norm = ts.normalize() if ts_norm.hour == 0 and ts_norm.minute == 0 and ts_norm.second == 0: f_print_success("normalize() correct: midnight") else: f_print_error(f"normalize() wrong: {ts_norm.hour}:{ts_norm.minute}:{ts_norm.second}") return False return True except Exception as e: f_print_error(f"Exception: {e}") .. _example-timestamp-round-17: .. dropdown:: round (test_timestamp.py:320) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 310 :emphasize-lines: 11 # Ceil to hour ts_ceil = ts.ceil("H") if ts_ceil.hour == 15 and ts_ceil.minute == 0: f_print_success(f"ceil('H') correct: {ts_ceil.hour}:{ts_ceil.minute}:{ts_ceil.second}") else: f_print_error(f"ceil('H') wrong: {ts_ceil.hour}:{ts_ceil.minute}:{ts_ceil.second}") return False # Round to hour (37 minutes rounds down) ts_round = ts.round("H") if ts_round.hour == 15: f_print_success(f"round('H') correct: {ts_round.hour}:{ts_round.minute}") else: f_print_error(f"round('H') wrong: {ts_round.hour}") return False # Normalize (floor to day) ts_norm = ts.normalize() if ts_norm.hour == 0 and ts_norm.minute == 0 and ts_norm.second == 0: f_print_success("normalize() correct: midnight") .. _example-timestamp-strftime-18: .. dropdown:: strftime (test_timestamp.py:358) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 348 :emphasize-lines: 11 # isoformat iso_str = ts.isoformat() if "2021-01-15" in iso_str and "12:30:45" in iso_str: f_print_success(f"isoformat() correct: {iso_str}") else: f_print_error(f"isoformat() wrong: {iso_str}") return False # strftime str_time = ts.strftime("%Y/%m/%d") if str_time == "2021/01/15": f_print_success(f"strftime() correct: {str_time}") else: f_print_error(f"strftime() wrong: {str_time}, expected '2021/01/15'") return False # isocalendar iso_cal = ts.isocalendar() if len(iso_cal) == 3: f_print_success(f"isocalendar() correct: {iso_cal}") .. _example-timestamp-day_name-19: .. dropdown:: day_name (test_timestamp.py:382) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 372 :emphasize-lines: 11 # timestamp (POSIX) posix_ts = ts.timestamp() if posix_ts > 0: f_print_success(f"timestamp() correct: {posix_ts}") else: f_print_error(f"timestamp() wrong: {posix_ts}") return False # day_name day_name = ts.day_name() if day_name == "Friday": f_print_success(f"day_name() correct: {day_name}") else: f_print_error(f"day_name() wrong: {day_name}, expected 'Friday'") return False # month_name month_name = ts.month_name() if month_name == "January": f_print_success(f"month_name() correct: {month_name}") .. _example-timestamp-isocalendar-20: .. dropdown:: isocalendar (test_timestamp.py:366) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 356 :emphasize-lines: 11 # strftime str_time = ts.strftime("%Y/%m/%d") if str_time == "2021/01/15": f_print_success(f"strftime() correct: {str_time}") else: f_print_error(f"strftime() wrong: {str_time}, expected '2021/01/15'") return False # isocalendar iso_cal = ts.isocalendar() if len(iso_cal) == 3: f_print_success(f"isocalendar() correct: {iso_cal}") else: f_print_error(f"isocalendar() wrong format") return False # timestamp (POSIX) posix_ts = ts.timestamp() if posix_ts > 0: f_print_success(f"timestamp() correct: {posix_ts}") .. _example-timestamp-isoformat-21: .. dropdown:: isoformat (test_timestamp.py:350) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 340 :emphasize-lines: 11 def test_conversion_methods(): """Test Timestamp conversion methods""" f_print_header("Test: Timestamp Conversion Methods") try: ts = pandasCore.Timestamp(2021, 1, 15, 12, 30, 45) # isoformat iso_str = ts.isoformat() if "2021-01-15" in iso_str and "12:30:45" in iso_str: f_print_success(f"isoformat() correct: {iso_str}") else: f_print_error(f"isoformat() wrong: {iso_str}") return False # strftime str_time = ts.strftime("%Y/%m/%d") if str_time == "2021/01/15": f_print_success(f"strftime() correct: {str_time}") .. _example-timestamp-month_name-22: .. dropdown:: month_name (test_timestamp.py:390) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 380 :emphasize-lines: 11 # day_name day_name = ts.day_name() if day_name == "Friday": f_print_success(f"day_name() correct: {day_name}") else: f_print_error(f"day_name() wrong: {day_name}, expected 'Friday'") return False # month_name month_name = ts.month_name() if month_name == "January": f_print_success(f"month_name() correct: {month_name}") else: f_print_error(f"month_name() wrong: {month_name}, expected 'January'") return False return True except Exception as e: f_print_error(f"Exception: {e}") .. _example-timestamp-timestamp-23: .. dropdown:: timestamp (test_timestamp.py:374) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 364 :emphasize-lines: 11 # isocalendar iso_cal = ts.isocalendar() if len(iso_cal) == 3: f_print_success(f"isocalendar() correct: {iso_cal}") else: f_print_error(f"isocalendar() wrong format") return False # timestamp (POSIX) posix_ts = ts.timestamp() if posix_ts > 0: f_print_success(f"timestamp() correct: {posix_ts}") else: f_print_error(f"timestamp() wrong: {posix_ts}") return False # day_name day_name = ts.day_name() if day_name == "Friday": f_print_success(f"day_name() correct: {day_name}")