thombashi / DateTimeRange

DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.
https://datetimerange.rtfd.io/
MIT License
106 stars 16 forks source link

Make DateTimeRange Json serializable #51

Closed peterkronenberg closed 2 months ago

peterkronenberg commented 2 months ago

I would like to be able to do something like json.dumps(date_time_range) and get something like this

{
  "start": <starttime>,
   "end": <endtime>
}

Is this possible?

thombashi commented 2 months ago

How about creating a dict object?

json.dumps({
    "start": str(dtr.start_datetime),
    "end": str(dtr.end_datetime),
})