mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
add dt_utc helper
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
from freqtrade.util.datetime_helpers import dt_floor_day, dt_from_ts, dt_now, dt_ts
|
from freqtrade.util.datetime_helpers import dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc
|
||||||
from freqtrade.util.ft_precise import FtPrecise
|
from freqtrade.util.ft_precise import FtPrecise
|
||||||
from freqtrade.util.periodic_cache import PeriodicCache
|
from freqtrade.util.periodic_cache import PeriodicCache
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
'dt_floor_day',
|
||||||
'dt_from_ts',
|
'dt_from_ts',
|
||||||
'dt_now',
|
'dt_now',
|
||||||
'dt_ts',
|
'dt_ts',
|
||||||
'dt_floor_day',
|
'dt_utc',
|
||||||
'FtPrecise',
|
'FtPrecise',
|
||||||
'PeriodicCache',
|
'PeriodicCache',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ def dt_now() -> datetime:
|
|||||||
return datetime.now(timezone.utc)
|
return datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def dt_utc(year: int, month: int, day: int, hour: int = 0, minute: int = 0, second: int = 0,
|
||||||
|
microsecond: int = 0) -> datetime:
|
||||||
|
"""Return a datetime in UTC."""
|
||||||
|
return datetime(year, month, day, hour, minute, second, microsecond, tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
def dt_ts(dt: Optional[datetime] = None) -> int:
|
def dt_ts(dt: Optional[datetime] = None) -> int:
|
||||||
"""
|
"""
|
||||||
Return dt in ms as a timestamp in UTC.
|
Return dt in ms as a timestamp in UTC.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta, timezone
|
|||||||
import pytest
|
import pytest
|
||||||
import time_machine
|
import time_machine
|
||||||
|
|
||||||
from freqtrade.util import dt_floor_day, dt_from_ts, dt_now, dt_ts
|
from freqtrade.util import dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc
|
||||||
|
|
||||||
|
|
||||||
def test_dt_now():
|
def test_dt_now():
|
||||||
@@ -21,6 +21,13 @@ def test_dt_now():
|
|||||||
assert dt_ts(now) == int(now.timestamp() * 1000)
|
assert dt_ts(now) == int(now.timestamp() * 1000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dt_utc():
|
||||||
|
assert dt_utc(2023, 5, 5) == datetime(2023, 5, 5, tzinfo=timezone.utc)
|
||||||
|
assert dt_utc(2023, 5, 5, 0, 0, 0, 555500) == datetime(2023, 5, 5, 0, 0, 0, 555500,
|
||||||
|
tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('as_ms', [True, False])
|
@pytest.mark.parametrize('as_ms', [True, False])
|
||||||
def test_dt_from_ts(as_ms):
|
def test_dt_from_ts(as_ms):
|
||||||
multi = 1000 if as_ms else 1
|
multi = 1000 if as_ms else 1
|
||||||
|
|||||||
Reference in New Issue
Block a user