-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timezone support when rendering datetimes.
Fixes #42.
- Loading branch information
Showing
5 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from django.conf import settings | ||
|
||
|
||
@pytest.fixture | ||
def use_seconds_format(): | ||
settings.APSCHEDULER_DATETIME_FORMAT = "N j, Y, f:s" | ||
return settings.APSCHEDULER_DATETIME_FORMAT | ||
|
||
|
||
@pytest.fixture | ||
def use_tz(): | ||
settings.APSCHEDULER_DATETIME_FORMAT = "H" # Only interested in hour | ||
settings.USE_TZ = True | ||
|
||
return settings.APSCHEDULER_DATETIME_FORMAT | ||
|
||
|
||
@pytest.fixture | ||
def use_hour_format(): | ||
settings.APSCHEDULER_DATETIME_FORMAT = "H" # Only interested in hour | ||
|
||
return settings.APSCHEDULER_DATETIME_FORMAT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from datetime import datetime | ||
|
||
from django.utils import timezone | ||
|
||
from django_apscheduler import util | ||
|
||
|
||
def test_get_format_default(): | ||
assert util.get_format() == "N j, Y, f:s a" | ||
|
||
|
||
def test_get_format_from_settings(use_seconds_format): | ||
assert util.get_format() == use_seconds_format | ||
|
||
|
||
def test_localize_naive(use_hour_format): | ||
|
||
dt = datetime.utcnow() | ||
dt_hour = dt.strftime("%H") | ||
|
||
localized_dt_hour = util.localize(dt) | ||
|
||
assert localized_dt_hour == dt_hour | ||
|
||
|
||
def test_localize_aware(use_tz): | ||
utc_dt = timezone.now() | ||
|
||
local_dt = timezone.localtime(utc_dt) | ||
local_dt_hour = local_dt.strftime("%H") | ||
|
||
localized_dt_hour = util.localize(utc_dt) | ||
|
||
assert localized_dt_hour == local_dt_hour |