1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import datetime
- class ReportPublicFunsUtils:
- @staticmethod
- def get_time_range_month(type=None):
- """
- 获取当月一号到当前时间的时间区间
- :param type 1 :y m d 2: y m d : s m m
- :return:
- """
- pre_day = ReportPublicFunsUtils.before_day()
- year = pre_day.year
- month = pre_day.month
- month = str(month) if month > 9 else '0' + str(month)
- first_day_of_month = str(year) + '-' + month
- if type:
- return [first_day_of_month + '-01 00:00:00', pre_day.strftime('%Y-%m-%d %M:%I:%S')]
- else:
- return [first_day_of_month + '-01', pre_day.strftime('%Y-%m-%d')]
- @staticmethod
- def before_day():
- now_time = datetime.datetime.now()
- pre_time = now_time + datetime.timedelta(days=-1)
- return pre_time
- @staticmethod
- def get_prd_day(type=None):
- if type:
- return [ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S'), ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S')]
- else:
- return [ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d'), ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d')]
- @staticmethod
- def get_all_time_data_range(type=None):
- if type:
- return ['2020-02-18 00:00:00', ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S')]
- else:
- return ['2020-02-18', ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d')]
- @staticmethod
- def get_month_day():
- pre_time = ReportPublicFunsUtils.before_day()
- month = pre_time.month
- day = pre_time.day
- return '{}月{}日'.format(month, day)
- @staticmethod
- def get_month():
- pre_time = ReportPublicFunsUtils.before_day()
- return str(pre_time.month)
- @staticmethod
- def get_pre_day():
- now = datetime.datetime.now()
- return str(now.day - 1)
- @staticmethod
- def add(a=None, b=None):
- """
- 求和
- :param a:
- :param b:
- :return:
- """
- if a and b:
- return a + b
- elif a and not b:
- return a
- elif b and not a:
- return b
- return 0
- if __name__ == '__main__':
- print(ReportPublicFunsUtils.get_time_range_month())
|