Aw: Re: Standard class for time *period*?

Karsten Hilbert Karsten.Hilbert at gmx.net
Tue Mar 28 11:42:23 EDT 2023


> No, it doesn't.  I already know about timedelta.  I must have explained
> the issue badly, because everyone seems to be fixating on the
> formatting, which is not a problem and is incidental to what I am really
> interested in, namely:
>
> 1. Is there a standard class for a 'period', i.e. length of time
>    specified by a start point and an end point?  The start and end
>    points could obviously be datetimes and the difference a timedelta,
>    but the period '2022-03-01 00:00 to 2022-03-02 00:00' would be
>    different to '2023-03-01 00:00 to 2023-03-02 00:00' even if the
>    *duration* of both periods is the same.

Not that I know, within the constraints of the standard library.

However:

class CalendarPeriod:
   def __init__(self, start, end):
      self.start = start
      self.end = end

?

For this to be *useful* more needs need to be explained. Until then - YAGNI.

Karsten



More information about the Python-list mailing list