Skip to content

Timezones improperly handled when retrieving clips #1144

@roger-

Description

@roger-

I had some motion on one of my cameras ~30 mins ago but look at the following:

>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=1)), stop=2)
[]
>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=2)), stop=2)
[]
>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=3)), stop=2)
[]
>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=4)), stop=2)
[]
>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=5)), stop=2)
[]
>>> await blink.get_videos_metadata(since=str(datetime.now(timezone.utc) - timedelta(hours=6)), stop=2)
[{'id': 15873035115, 'created_at': '2025-11-22T14:12:13+00:00', ...

I expect timedelta of 1 hour to catch it, but it doesn't until a delta of 6 hours. My timezone is UTC - 5.

I looked at the get_videos_metadata function implementation and noticed this behavior:

>>> datetime.now(timezone.utc)
datetime.datetime(2025, 11, 22, 14, 47, 36, 693905, tzinfo=datetime.timezone.utc)
>>> util.get_time(datetime.now(timezone.utc).timestamp())
'2025-11-22T14:47:46-0500'

Those two dates should be the same but they seem different due to the UTC offset. I believe there's a TZ handling bug.

This seems to give the correct result:

dt = datetime.now(timezone.utc) - timedelta(hours=1) + datetime.now().astimezone().utcoffset()
await blink.get_videos_metadata(since=str(dt), stop=2)

As an aside, the stop parameter is confusing since the code uses for page in range(1, stop). This means stop=2 is needed for the first page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThere is an issue causing unexpected resultshelp-wantedAssistance required due to lack of resources for testing or complexity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions