config_base.py 682 B

123456789101112131415161718192021222324252627282930
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from datetime import timedelta
  5. from pydantic import BaseModel, datetime_parse
  6. def format_timedelta(tdelta: timedelta):
  7. days = tdelta.days
  8. hours, rem = divmod(tdelta.seconds, 3600)
  9. minutes, seconds = divmod(rem, 60)
  10. return f"{days:02d} {hours:02d}:{minutes:02d}:{seconds:02d}"
  11. class TimeDelta(timedelta):
  12. def __str__(self):
  13. return format_timedelta(self)
  14. def __repr__(self):
  15. return format_timedelta(self)
  16. class ConfigBase(BaseModel):
  17. class Config:
  18. json_encoders = {
  19. TimeDelta: format_timedelta
  20. }