Skip to content

Commit

Permalink
Fix create_period_filter test not working on dev machine (#1927)
Browse files Browse the repository at this point in the history
Force use of UTC in create_period_filter to make sure calculation is not dependent on server local time.

---------

Co-authored-by: Sébastien Favre <[email protected]>
  • Loading branch information
Panikabor and Panikabor authored Jan 28, 2025
1 parent 3c94f78 commit ba2f3df
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 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 @@ -35,8 +35,8 @@ def build_query(url_params, meta_params, doc_type):
if filter:
search = search.filter(filter)

search = search.\
fields([]).\
search = search. \
fields([]). \
extra(from_=offset, size=limit)

if url_params.get('bbox'):
Expand Down Expand Up @@ -283,7 +283,11 @@ 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

0 comments on commit ba2f3df

Please sign in to comment.