report_public_funs_utils.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 get_month():
  43. now = datetime.datetime.now()
  44. return str(now.month)
  45. @staticmethod
  46. def get_pre_day():
  47. now = datetime.datetime.now()
  48. return str(now.day - 1)
  49. @staticmethod
  50. def add(a=None, b=None):
  51. """
  52. 求和
  53. :param a:
  54. :param b:
  55. :return:
  56. """
  57. if a and b:
  58. return a + b
  59. elif a and not b:
  60. return a
  61. elif b and not a:
  62. return b
  63. return 0
  64. if __name__ == '__main__':
  65. print(ReportPublicFunsUtils.get_month())