# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2022/11/12
# 描述:
import time
from datetime import datetime, timedelta


class TimeUnit(object):
    @staticmethod
    def get_date_str(time_diff=0):
        """
        param: time_diff - 时间差
        """
        now = datetime.now()
        dt = now + timedelta(days=time_diff)
        return dt.strftime('%Y-%m-%d')

    @staticmethod
    def get_time_str(time_diff=0):
        """
        param: time_diff - 时间差
        """
        now = datetime.now()
        dt = now + timedelta(hours=time_diff)
        return dt.strftime('%H-%M-%S')

    @staticmethod
    def get_timezone():
        return int(time.time() * 1000)

    @staticmethod
    def get_datetime(format_type='X'):
        now = datetime.now()
        dt = time.strftime('%Y-%m-%d %X') if format_type == 'X' else time.strftime(
            '%Y-%m-%d') if format_type == 'D' else '{}{:0>2}{:0>2}{:0>2}{:0>2}{:0>2}{:0>3}'.format(now.year, now.month,
                                                                                                   now.day, now.hour,
                                                                                                   now.minute,
                                                                                                   now.second,
                                                                                                   int(now.microsecond / 1000))
        return dt

    @staticmethod
    def str_to_datetime(date_str):
        return datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
