report_public_funs_utils.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import datetime
  2. class ReportPublicFunsUtils:
  3. @staticmethod
  4. def get_time_range_month(type):
  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. first_day_of_month = datetime.datetime.now().strftime('%Y-%M')
  12. if type == 1:
  13. return [first_day_of_month + '-01 00:00:00', now_time.strftime('%Y-%m-%d %M:%I:%S')]
  14. else:
  15. return [first_day_of_month + '-01', now_time.strftime('%Y-%m-%d')]
  16. @staticmethod
  17. def get_prd_day(type):
  18. now_time = datetime.datetime.now()
  19. pre_time = now_time + datetime.timedelta(days=-1)
  20. now_time = now_time + datetime.timedelta(days=-1)
  21. if type == 1:
  22. return [pre_time.strftime('%Y-%m-%d %M:%I:%S'), now_time.strftime('%Y-%m-%d %M:%I:%S')]
  23. else:
  24. repr([pre_time.strftime('%Y-%m-%d'), now_time.strftime('%Y-%m-%d')])
  25. @staticmethod
  26. def get_all_time_data_range(type):
  27. now_time = datetime.datetime.now()
  28. pre_time = now_time + datetime.timedelta(days=-9999)
  29. if type == 1:
  30. return [pre_time.strftime('%Y-%m-%d %M:%I:%S'), now_time.strftime('%Y-%m-%d %M:%I:%S')]
  31. else:
  32. return [pre_time.strftime('%Y-%m-%d'), now_time.strftime('%Y-%m-%d')]
  33. @staticmethod
  34. def get_montho_day():
  35. now = datetime.datetime.now()
  36. month = now.month
  37. day = now.day
  38. return '{}月{}日'.format(month, day)
  39. @staticmethod
  40. def add(a=None, b=None):
  41. """
  42. 求和
  43. :param a:
  44. :param b:
  45. :return:
  46. """
  47. if a and b:
  48. return a + b
  49. elif a and not b:
  50. return a
  51. elif b and not a:
  52. return b
  53. return 0
  54. if __name__ == '__main__':
  55. print(ReportPublicFunsUtils.get_montho_day())