中国本土应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3KB

  1. # -*- coding: utf-8 -*-
  2. import time
  3. from odoo import api, models, tools, _
  4. from datetime import datetime, timedelta
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. class WecomApiToolsDatetime(models.AbstractModel):
  8. _name = "wecomapi.tools.datetime"
  9. _description = "Wecom API Tools - Datetime"
  10. def timestamp2datetime(self, time_stamp):
  11. """
  12. 时间戳转日期时间
  13. """
  14. if len(str(time_stamp)) > 10:
  15. # 一般爬取下来的时间戳长度都是13位的数字,而time.localtime的参数要的长度是10位,所以我们需要将其/1000并取整即可
  16. time_stamp = int(time_stamp / 1000)
  17. loc_time = time.localtime(time_stamp)
  18. return time.strftime("%Y-%m-%d %H:%M:%S", loc_time)
  19. def cheeck_days_overdue(self, datetime_start, maxday):
  20. """[summary]
  21. 检查天数是否超期
  22. Args:
  23. datetime_start_str ([type]): [description]
  24. datetime_end_str ([type]): [description]
  25. maxday ([type]): [description] 天数
  26. Returns:
  27. True: 超期
  28. False:未超期
  29. """
  30. now = datetime.now()
  31. # print(now - datetime_start)
  32. if datetime_start > (now - timedelta(days=maxday)):
  33. return False
  34. else:
  35. return True
  36. def cheeck_hours_overdue(self, datetime_start, maxhour):
  37. """[summary]
  38. 检查小时是否超期
  39. Args:
  40. datetime_start_str ([type]): [description]
  41. datetime_end_str ([type]): [description]
  42. maxhour ([type]): [description] 小时
  43. Returns:
  44. True: 超期
  45. False:未超期
  46. """
  47. now = datetime.now()
  48. if datetime_start > (now - timedelta(hours=maxhour)):
  49. return False
  50. else:
  51. return True
  52. def cheeck_minutes_overdue(self, datetime_start, maxminute):
  53. """[summary]
  54. 检查分钟是否超期
  55. Args:
  56. datetime_start_str ([type]): [description]
  57. datetime_end_str ([type]): [description]
  58. maxminute ([type]): [description] 分钟
  59. Returns:
  60. True: 超期
  61. False:未超期
  62. """
  63. now = datetime.now()
  64. if datetime_start > (now - timedelta(minutes=maxminute)):
  65. return False
  66. else:
  67. return True
上海开阖软件有限公司 沪ICP备12045867号-1