report_public_funs_utils.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. pre_day = ReportPublicFunsUtils.before_day()
  11. year = pre_day.year
  12. month = pre_day.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', pre_day.strftime('%Y-%m-%d %M:%I:%S')]
  17. else:
  18. return [first_day_of_month + '-01', pre_day.strftime('%Y-%m-%d')]
  19. @staticmethod
  20. def before_day():
  21. now_time = datetime.datetime.now()
  22. pre_time = now_time + datetime.timedelta(days=-1)
  23. return pre_time
  24. @staticmethod
  25. def get_prd_day(type=None):
  26. if type:
  27. return [ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S'), ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S')]
  28. else:
  29. return [ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d'), ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d')]
  30. @staticmethod
  31. def get_all_time_data_range(type=None):
  32. if type:
  33. return ['2020-02-18 00:00:00', ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d %M:%I:%S')]
  34. else:
  35. return ['2020-02-18', ReportPublicFunsUtils.before_day().strftime('%Y-%m-%d')]
  36. @staticmethod
  37. def get_month_day():
  38. pre_time = ReportPublicFunsUtils.before_day()
  39. month = pre_time.month
  40. day = pre_time.day
  41. return '{}月{}日'.format(month, day)
  42. @staticmethod
  43. def get_month():
  44. pre_time = ReportPublicFunsUtils.before_day()
  45. return str(pre_time.month)
  46. @staticmethod
  47. def get_pre_day():
  48. now = datetime.datetime.now()
  49. return str(now.day - 1)
  50. @staticmethod
  51. def add(a=None, b=None):
  52. """
  53. 求和
  54. :param a:
  55. :param b:
  56. :return:
  57. """
  58. if a and b:
  59. return a + b
  60. elif a and not b:
  61. return a
  62. elif b and not a:
  63. return b
  64. return 0
  65. if __name__ == '__main__':
  66. print(ReportPublicFunsUtils.get_time_range_month())