Skip to content

Commit

Permalink
adjust docs on rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
ariebovenberg committed Feb 21, 2025
1 parent dc3ed42 commit 22dafbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ and many issues remaining unaddressed.
Instant(2024-07-04 10:36:56Z)

# Simple, explicit conversions
>>> now.to_tz("Europe/Paris").round("minute", increment=5)
ZonedDateTime(2024-07-04 12:35:00+02:00[Europe/Paris])
>>> now.to_tz("Europe/Paris")
ZonedDateTime(2024-07-04 12:36:56+02:00[Europe/Paris])

# A 'naive' local time can't accidentally mix with other types.
# You need to explicitly convert it and handle ambiguity.
Expand All @@ -154,12 +154,16 @@ ZonedDateTime(2023-10-28 22:00:00+02:00[Europe/Amsterdam])

# DST-safe arithmetic
>>> party_starts.add(hours=6)
ZonedDateTime(2022-10-29 03:00:00+01:00[Europe/Amsterdam])
ZonedDateTime(2023-10-29 03:00:00+01:00[Europe/Amsterdam])

# Comparison and equality
>>> now > party_starts
True

# Rounding and truncation
>>> now.round("minute", increment=15)
Instant(2024-07-04 10:30:00Z)

# Formatting & parsing common formats (ISO8601, RFC3339, RFC2822)
>>> now.format_rfc2822()
"Thu, 04 Jul 2024 10:36:56 GMT"
Expand Down
11 changes: 7 additions & 4 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,14 @@ The :class:`~whenever._KnowsLocal.round` method allows you to do this:

.. code-block:: python
>>> d = LocalDateTime(2023, 12, 28, 11, 30)
>>> d.round(hours=1)
>>> d = LocalDateTime(2023, 12, 28, 11, 32, 8)
LocalDateTime(2023-12-28 11:32:08)
>>> d.round("hour")
LocalDateTime(2023-12-28 12:00:00)
>>> d.round(minutes=15)
LocalDateTime(2023-12-28 11:30:00)
>>> d.round("minute", increment=15, mode="ceil")
LocalDateTime(2023-12-28 11:45:00)
See the method documentation for more details on the available options.

Formatting and parsing
----------------------
Expand Down

0 comments on commit 22dafbd

Please sign in to comment.