report_public_funs_utils.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import datetime
  2. class ReportPublicFunsUtils:
  3. @staticmethod
  4. def get_time_range_month(type=None):
  5. """
  6. 获取当月一号到当前时间的时间区间
  7. :param type 1:y m d 2: y m d : s m m
  8. :return:
  9. """
  10. now_time = datetime.datetime.now()
  11. year = now_time.year
  12. month = now_time.month
  13. month = str(month) if month > 9 else '0' + str(month)
  14. first_day_of_month = str(year) + '-' + month
  15. if type:
  16. return [first_day_of_month + '-01 00:00:00', now_time.strftime('%Y-%m-%d %M:%I:%S')]
  17. else:
  18. return [first_day_of_month + '-01', now_time.strftime('%Y-%m-%d')]
  19. @staticmethod
  20. def get_prd_day(type=None):
  21. now_time = datetime.datetime.now()
  22. pre_time = now_time + datetime.timedelta(days=-1)
  23. now_time = now_time + datetime.timedelta(days=-1)
  24. if type:
  25. return [pre_time.strftime('%Y-%m-%d %M:%I:%S'), now_time.strftime('%Y-%m-%d %M:%I:%S')]
  26. else:
  27. return [pre_time.strftime('%Y-%m-%d'), now_time.strftime('%Y-%m-%d')]
  28. @staticmethod
  29. def get_all_time_data_range(type=None):
  30. now_time = datetime.datetime.now()
  31. if not type:
  32. return ['2020-02-18 00:00:00', now_time.strftime('%Y-%m-%d %M:%I:%S')]
  33. else:
  34. return ['2020-02-18', now_time.strftime('%Y-%m-%d')]
  35. @staticmethod
  36. def get_montho_day():
  37. now = datetime.datetime.now()
  38. month = now.month
  39. day = now.day - 1
  40. return '{}月{}日'.format(month, day)
  41. @staticmethod
  42. def add(a=None, b=None):
  43. """
  44. 求和
  45. :param a:
  46. :param b:
  47. :return:
  48. """
  49. if a and b:
  50. return a + b
  51. elif a and not b:
  52. return a
  53. elif b and not a:
  54. return b
  55. return 0
  56. if __name__ == '__main__':
  57. print(ReportPublicFunsUtils.get_prd_day())