mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
Move shorten_date to datetime helpers
This commit is contained in:
@@ -3,7 +3,6 @@ Various tool function for Freqtrade and scripts
|
||||
"""
|
||||
import gzip
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Iterator, List, Mapping, Optional, TextIO, Union
|
||||
@@ -48,18 +47,6 @@ def round_coin_value(
|
||||
return val
|
||||
|
||||
|
||||
def shorten_date(_date: str) -> str:
|
||||
"""
|
||||
Trim the date so it fits on small screens
|
||||
"""
|
||||
new_date = re.sub('seconds?', 'sec', _date)
|
||||
new_date = re.sub('minutes?', 'min', new_date)
|
||||
new_date = re.sub('hours?', 'h', new_date)
|
||||
new_date = re.sub('days?', 'd', new_date)
|
||||
new_date = re.sub('^an?', '1', new_date)
|
||||
return new_date
|
||||
|
||||
|
||||
def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool = True) -> None:
|
||||
"""
|
||||
Dump JSON data into a file
|
||||
|
||||
@@ -26,13 +26,13 @@ from freqtrade.exceptions import ExchangeError, PricingError
|
||||
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs
|
||||
from freqtrade.exchange.types import Tickers
|
||||
from freqtrade.loggers import bufferHandler
|
||||
from freqtrade.misc import decimals_per_coin, shorten_date
|
||||
from freqtrade.misc import decimals_per_coin
|
||||
from freqtrade.persistence import KeyStoreKeys, KeyValueStore, Order, PairLocks, Trade
|
||||
from freqtrade.persistence.models import PairLock
|
||||
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
||||
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
||||
from freqtrade.rpc.rpc_types import RPCSendMsg
|
||||
from freqtrade.util.datetime_helpers import dt_now
|
||||
from freqtrade.util import dt_now, shorten_date
|
||||
from freqtrade.wallets import PositionWallet, Wallet
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from freqtrade.util.datetime_helpers import dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc
|
||||
from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc,
|
||||
shorten_date)
|
||||
from freqtrade.util.ft_precise import FtPrecise
|
||||
from freqtrade.util.periodic_cache import PeriodicCache
|
||||
|
||||
@@ -9,6 +10,7 @@ __all__ = [
|
||||
'dt_now',
|
||||
'dt_ts',
|
||||
'dt_utc',
|
||||
'shorten_date',
|
||||
'FtPrecise',
|
||||
'PeriodicCache',
|
||||
]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
@@ -37,3 +38,15 @@ def dt_from_ts(timestamp: float) -> datetime:
|
||||
# Timezone in ms - convert to seconds
|
||||
timestamp /= 1000
|
||||
return datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
||||
|
||||
|
||||
def shorten_date(_date: str) -> str:
|
||||
"""
|
||||
Trim the date so it fits on small screens
|
||||
"""
|
||||
new_date = re.sub('seconds?', 'sec', _date)
|
||||
new_date = re.sub('minutes?', 'min', new_date)
|
||||
new_date = re.sub('hours?', 'h', new_date)
|
||||
new_date = re.sub('days?', 'd', new_date)
|
||||
new_date = re.sub('^an?', '1', new_date)
|
||||
return new_date
|
||||
|
||||
@@ -12,7 +12,7 @@ from freqtrade.misc import (dataframe_to_json, decimals_per_coin, deep_merge_dic
|
||||
file_load_json, format_ms_time, json_to_dataframe, pair_to_filename,
|
||||
parse_db_uri_for_logging, plural, render_template,
|
||||
render_template_with_fallback, round_coin_value, safe_value_fallback,
|
||||
safe_value_fallback2, shorten_date)
|
||||
safe_value_fallback2)
|
||||
|
||||
|
||||
def test_decimals_per_coin():
|
||||
@@ -39,12 +39,6 @@ def test_round_coin_value():
|
||||
assert round_coin_value(222.2, 'USDT', False, True) == '222.200'
|
||||
|
||||
|
||||
def test_shorten_date() -> None:
|
||||
str_data = '1 day, 2 hours, 3 minutes, 4 seconds ago'
|
||||
str_shorten_data = '1 d, 2 h, 3 min, 4 sec ago'
|
||||
assert shorten_date(str_data) == str_shorten_data
|
||||
|
||||
|
||||
def test_file_dump_json(mocker) -> None:
|
||||
file_open = mocker.patch('freqtrade.misc.Path.open', MagicMock())
|
||||
json_dump = mocker.patch('rapidjson.dump', MagicMock())
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta, timezone
|
||||
import pytest
|
||||
import time_machine
|
||||
|
||||
from freqtrade.util import dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc
|
||||
from freqtrade.util import dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_utc, shorten_date
|
||||
|
||||
|
||||
def test_dt_now():
|
||||
@@ -45,3 +45,9 @@ def test_dt_floor_day():
|
||||
now = datetime(2023, 9, 1, 5, 2, 3, 455555, tzinfo=timezone.utc)
|
||||
|
||||
assert dt_floor_day(now) == datetime(2023, 9, 1, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def test_shorten_date() -> None:
|
||||
str_data = '1 day, 2 hours, 3 minutes, 4 seconds ago'
|
||||
str_shorten_data = '1 d, 2 h, 3 min, 4 sec ago'
|
||||
assert shorten_date(str_data) == str_shorten_data
|
||||
|
||||
Reference in New Issue
Block a user