2022-12-13 11:26:36 +00:00
|
|
|
from fontTools.misc.timeTools import (
|
|
|
|
asctime,
|
|
|
|
timestampNow,
|
|
|
|
timestampToString,
|
|
|
|
timestampFromString,
|
|
|
|
epoch_diff,
|
|
|
|
)
|
2017-10-02 10:27:31 +02:00
|
|
|
import os
|
2017-01-16 16:34:18 +00:00
|
|
|
import time
|
2020-02-25 20:36:02 +01:00
|
|
|
import locale
|
2017-10-02 14:19:01 +01:00
|
|
|
import pytest
|
2017-01-16 16:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_asctime():
|
2021-03-27 10:23:29 -04:00
|
|
|
assert isinstance(asctime(), str)
|
2022-12-13 11:26:36 +00:00
|
|
|
assert asctime(time.gmtime(0)) == "Thu Jan 1 00:00:00 1970"
|
2017-10-02 10:27:31 +02:00
|
|
|
|
2017-10-02 14:19:01 +01:00
|
|
|
|
2017-10-02 10:27:31 +02:00
|
|
|
def test_source_date_epoch():
|
|
|
|
os.environ["SOURCE_DATE_EPOCH"] = "150687315"
|
|
|
|
assert timestampNow() + epoch_diff == 150687315
|
|
|
|
|
|
|
|
# Check that malformed value fail, any better way?
|
|
|
|
os.environ["SOURCE_DATE_EPOCH"] = "ABCDEFGHI"
|
2017-10-02 14:19:01 +01:00
|
|
|
with pytest.raises(ValueError):
|
2017-10-02 10:27:31 +02:00
|
|
|
timestampNow()
|
|
|
|
|
|
|
|
del os.environ["SOURCE_DATE_EPOCH"]
|
|
|
|
assert timestampNow() + epoch_diff != 150687315
|
2020-02-25 20:36:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
# test for issue #1838
|
|
|
|
def test_date_parsing_with_locale():
|
|
|
|
l = locale.getlocale(locale.LC_TIME)
|
|
|
|
try:
|
2022-12-13 11:26:36 +00:00
|
|
|
locale.setlocale(locale.LC_TIME, "de_DE.utf8")
|
2020-02-25 20:36:02 +01:00
|
|
|
except locale.Error:
|
|
|
|
pytest.skip("Locale de_DE not available")
|
|
|
|
|
|
|
|
try:
|
|
|
|
assert timestampFromString(timestampToString(timestampNow()))
|
|
|
|
finally:
|
|
|
|
locale.setlocale(locale.LC_TIME, l)
|