# -*- coding: utf-8 -*-
"""
@File: date_utils.py
@Date: 2020-09-14
@author: A2TEC
@section MODIFYINFO 수정정보
- 수정자/수정일   : 수정내역
- 2022-01-14/hsj100@a2tec.co.kr : refactoring
@brief: date-utility functions
"""

from datetime import datetime, date, timedelta

_TIMEDELTA = 9


class D:
    def __init__(self, *args):
        self.utc_now = datetime.utcnow()
        # NOTE(hsj100): utc->kst
        self.timedelta = _TIMEDELTA

    @classmethod
    def datetime(cls, diff: int=_TIMEDELTA) -> datetime:
        return datetime.utcnow() + timedelta(hours=diff) if diff > 0 else datetime.now()

    @classmethod
    def date(cls, diff: int=_TIMEDELTA) -> date:
        return cls.datetime(diff=diff).date()

    @classmethod
    def date_num(cls, diff: int=_TIMEDELTA) -> int:
        return int(cls.date(diff=diff).strftime('%Y%m%d'))

    @classmethod
    def validate(cls, date_text):
        try:
            datetime.strptime(date_text, '%Y-%m-%d')
        except ValueError:
            raise ValueError('Incorrect data format, should be YYYY-MM-DD')

    @classmethod
    def date_str(cls, diff: int = _TIMEDELTA) -> str:
        return cls.datetime(diff=diff).strftime('%Y-%m-%dT%H:%M:%S')

    @classmethod
    def check_expire_date(cls, expire_date: datetime):
        td = expire_date - datetime.now()
        timestamp = td.total_seconds()
        return timestamp
    
    @classmethod
    def date_file_name(cls):
        date = datetime.now()
        return date.strftime('%y%m%d_%H%M%S.%s')
    
if __name__ == "__main__":
    _date = D()
