CoolFace
Apppublic

IntelliStock/data-api

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
utils.py28 linesDownload Raw Back to services
1from datetime import datetime, timedelta2from utils.config import DATE_FORMAT3 4 5class Utility:6    def __init__(self) -> None: pass7 8    @staticmethod9    def ts_to_date(ts: int, format=DATE_FORMAT) -> str:10        return datetime.fromtimestamp(ts).strftime(format)11 12    @staticmethod13    def date_to_ts(date: str, format=DATE_FORMAT) -> int:14        return int(datetime.timestamp(datetime.strptime(date, format)))15 16    @staticmethod17    def generate_dates(start_date: datetime.date,18                       num_days: int,19                       format=DATE_FORMAT):20        lst_date = []21        current_date = start_date22        for i in range(num_days):23            current_date += timedelta(days=1)24            while current_date.weekday() >= 5:25                current_date += timedelta(days=1)26            lst_date.append(current_date.strftime(format))27        return lst_date28