Skip to content

ViewResult slicing with datetime object #297

Open
@rdbisme

Description

@rdbisme

Hello,

Here I am back. Still working with DateTime fields. At the moment to "slice" (equivalent to startkey/endkey) a ViewResult you need to serialize the a datetime object into a iso format:

from datetime import datetime

start_time = datetime(
    year=2016,
    month=7,
    day=29,
    hour=0,
    minute=0,
    second=0,
    microsecond=0)

end_time = datetime(
    year=2016,
    month=7,
    day=30,
    hour=11,
    minute=0,
    second=0,
    microsecond=0)

results = results[datetime.isoformat(start_time)]:[datetime.isoformat(end_time)]]

If instead of that you use the plain start_time and end_time (that are Python datetime objects) you get a:

TypeError: datetime.datetime(2016, 7, 29, 0, 0) is not a JSON serializable.

What about implementing a native support for that in order to avoid to cast a datetime.isoformat explicitly? Do you see any problems in that? I could try to see if I can implement that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions