report_public_funs_utils.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. pre_time = now_time + datetime.timedelta(days=-9999)
  32. if not type:
  33. return [pre_time.strftime('%Y-%m-%d %M:%I:%S'), now_time.strftime('%Y-%m-%d %M:%I:%S')]
  34. else:
  35. return [pre_time.strftime('%Y-%m-%d'), now_time.strftime('%Y-%m-%d')]
  36. @staticmethod
  37. def get_montho_day():
  38. now = datetime.datetime.now()
  39. month = now.month
  40. day = now.day - 1
  41. return '{}月{}日'.format(month, day)
  42. @staticmethod
  43. def add(a=None, b=None):
  44. """
  45. 求和
  46. :param a:
  47. :param b:
  48. :return:
  49. """
  50. if a and b:
  51. return a + b
  52. elif a and not b:
  53. return a
  54. elif b and not a:
  55. return b
  56. return 0
  57. if __name__ == '__main__':
  58. print(ReportPublicFunsUtils.get_prd_day())