Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
use UTC for data
Browse files Browse the repository at this point in the history
  • Loading branch information
camsom committed Jan 13, 2016
1 parent 71e6c26 commit 968dd12
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bulbs/__init__.py
@@ -1 +1 @@
__version__ = "0.6.52"
__version__ = "0.6.53"
7 changes: 4 additions & 3 deletions bulbs/special_coverage/filters.py
@@ -1,6 +1,7 @@
from bulbs.utils.filters import CaseInsensitiveBooleanFilter
from django.utils import timezone

from bulbs.utils.methods import get_query_params, today_as_datetime
from bulbs.utils.filters import CaseInsensitiveBooleanFilter
from bulbs.utils.methods import get_query_params


class SpecialCoverageFilter(CaseInsensitiveBooleanFilter):
Expand All @@ -12,7 +13,7 @@ def filter_queryset(self, request, queryset, view):
queryset = super(SpecialCoverageFilter, self).filter_queryset(request, queryset, view)
query_params = get_query_params(request)
if "active" in query_params:
today_filter = today_as_datetime()
today_filter = timezone.now()
value = query_params.get("active").lower()
if value == "true":
queryset = queryset.filter(
Expand Down
@@ -1,7 +1,6 @@
from django.core.management.base import BaseCommand
from django.utils import timezone

from bulbs.utils.methods import get_central_now
from ...models import SpecialCoverage


Expand All @@ -10,14 +9,14 @@ class Command(BaseCommand):

def get_month_start_date(self):
"""Returns the first day of the current month"""
now = get_central_now()
now = timezone.now()
return timezone.datetime(day=1, month=now.month, year=now.year, tzinfo=now.tzinfo)

def get_absurd_end_date(self):
"""
To give ourselves a buffer, we are setting the initial end_date to 5 years in the future.
"""
now = get_central_now()
now = timezone.now()
return timezone.datetime(day=1, month=now.month, year=now.year + 5, tzinfo=now.tzinfo)

def get_active_special_coverages(self):
Expand Down
4 changes: 2 additions & 2 deletions bulbs/special_coverage/models.py
Expand Up @@ -11,7 +11,7 @@
from bulbs.content.custom_search import custom_search_model
from bulbs.content.models import Content
from bulbs.content.mixins import DetailImageMixin
from bulbs.utils.methods import today_as_datetime, is_valid_digit
from bulbs.utils.methods import today_as_utc_datetime, is_valid_digit


es = Elasticsearch(settings.ES_URLS)
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_content(self, published=True):

@property
def is_active(self):
now = today_as_datetime()
now = today_as_utc_datetime()
if self.start_date and self.end_date:
if self.start_date < now and self.end_date > now:
return True
Expand Down
4 changes: 2 additions & 2 deletions bulbs/utils/methods.py
Expand Up @@ -19,12 +19,12 @@ def today():
return getattr(settings, "TODAY", get_central_now())


def today_as_datetime():
def today_as_utc_datetime():
"""Datetime/Date comparisons aren't great, and someone might configure TODAY, to be a date."""
now = today()
if not isinstance(now, datetime) and isinstance(now, date):
now = datetime.combine(now, datetime.min.time())
now = now.replace(tzinfo=tz.gettz('America/Chicago'))
now = now.replace(tzinfo=tz.gettz('UTC'))
return now


Expand Down
4 changes: 2 additions & 2 deletions tests/special_coverage/test_spec_cov_commands.py
Expand Up @@ -2,7 +2,7 @@
from django.test.utils import override_settings

from bulbs.special_coverage.models import SpecialCoverage
from bulbs.utils.methods import today_as_datetime
from bulbs.utils.methods import today_as_utc_datetime
from bulbs.utils.test import BaseIndexableTestCase


Expand Down Expand Up @@ -35,7 +35,7 @@ def test_active_migration_success(self):
self.assertNotIn(sc, start_qs)
self.assertNotIn(sc, end_qs)

@override_settings(TODAY=today_as_datetime().date())
@override_settings(TODAY=today_as_utc_datetime().date())
def test_active_migration_date_config_success(self):
call_command("migrate_active_to_published")
start_qs = SpecialCoverage.objects.filter(start_date__isnull=False)
Expand Down

0 comments on commit 968dd12

Please sign in to comment.