File size: 882 Bytes
e96d69f
884dad1
 
 
 
 
 
 
e96d69f
884dad1
 
 
e96d69f
884dad1
e96d69f
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import datetime, timedelta
from utils.config import DATE_FORMAT


class Utility:
    def __init__(self) -> None: pass

    @staticmethod
    def ts_to_date(ts: int, format=DATE_FORMAT) -> str:
        return datetime.fromtimestamp(ts).strftime(format)

    @staticmethod
    def date_to_ts(date: str, format=DATE_FORMAT) -> int:
        return int(datetime.timestamp(datetime.strptime(date, format)))

    @staticmethod
    def generate_dates(start_date: datetime.date,
                       num_days: int,
                       format=DATE_FORMAT):
        lst_date = []
        current_date = start_date
        for i in range(num_days):
            current_date += timedelta(days=1)
            while current_date.weekday() >= 5:
                current_date += timedelta(days=1)
            lst_date.append(current_date.strftime(format))
        return lst_date