-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dates: Add basic format_interval implementation
Refs #276
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
|
||
from babel import dates | ||
from babel.dates import get_timezone | ||
from babel.util import UTC | ||
|
||
TEST_DT = datetime.datetime(2016, 1, 8, 11, 46, 15) | ||
TEST_TIME = TEST_DT.time() | ||
TEST_DATE = TEST_DT.date() | ||
|
||
|
||
def test_format_interval_same_instant_1(): | ||
assert dates.format_interval(TEST_DT, TEST_DT, "yMMMd", locale="fi") == "8. tammikuuta 2016" | ||
|
||
|
||
def test_format_interval_same_instant_2(): | ||
assert dates.format_interval(TEST_DT, TEST_DT, "xxx", locale="fi") == "8.1.2016 klo 11.46.15" | ||
|
||
|
||
def test_format_interval_same_instant_3(): | ||
assert dates.format_interval(TEST_TIME, TEST_TIME, "xxx", locale="fi") == "11.46.15" | ||
|
||
|
||
def test_format_interval_same_instant_4(): | ||
assert dates.format_interval(TEST_DATE, TEST_DATE, "xxx", locale="fi") == "8.1.2016" | ||
|
||
|
||
def test_format_interval_no_difference(): | ||
t1 = TEST_DT | ||
t2 = t1 + datetime.timedelta(minutes=8) | ||
assert dates.format_interval(t1, t2, "yMd", locale="fi") == "8.1.2016" | ||
|
||
|
||
def test_format_interval_in_tz(): | ||
t1 = TEST_DT.replace(tzinfo=UTC) | ||
t2 = t1 + datetime.timedelta(minutes=18) | ||
hki_tz = get_timezone("Europe/Helsinki") | ||
assert dates.format_interval(t1, t2, "Hmv", tzinfo=hki_tz, locale="fi") == "13.46\u201314.04 aikavyöhyke: Suomi" | ||
|
||
|
||
def test_format_interval_12_hour(): | ||
t2 = TEST_DT | ||
t1 = t2 - datetime.timedelta(hours=1) | ||
assert dates.format_interval(t1, t2, "hm", locale="en") == "10:46 \u2013 11:46 AM" |