Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create_period_filter test not working on dev machine #1927

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions c2corg_api/search/search_filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import math
import re
from datetime import datetime
from datetime import datetime, timezone
from functools import partial

from c2corg_api.models.outing import OUTING_TYPE
Expand Down Expand Up @@ -283,7 +283,9 @@ def create_period_filter(field, query_term):
range_values = [t for t in range_values if t is not None]

def milliseconds_since_first_day_of_year(date):
seconds_since_epoch = datetime.strptime(date, '%Y-%m-%d').timestamp()
processed_date = datetime.strptime(date, '%Y-%m-%d')
# Force UTC, to avoid problems when running on a machine that is not set to UTC
seconds_since_epoch = processed_date.replace(tzinfo=timezone.utc).timestamp()

return int(1000 * seconds_since_epoch) % milliseconds_in_one_year

Expand Down