date.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import constants
  2. from packet import Packet
  3. class Date(object):
  4. def call_date(self, format=0):
  5. """Call date for insertion into a TEXT file.
  6. Args:
  7. format: integer from 0 to 9
  8. 0 - MM/DD/YY
  9. 1 - DD/MM/YY
  10. 2 - MM-DD-YY
  11. 3 - DD-MM-YY
  12. 4 - MM.DD.YY
  13. 5 - DD.MM.YY
  14. 6 - MM DD YY
  15. 7 - DD MM YY
  16. 8 - MMM.DD, YYYY
  17. 9 - Day of week
  18. Returns:
  19. formatted string to use in a TEXT
  20. """
  21. if format < 0 or format > 9:
  22. format = 0
  23. return "\x0B%s" % format
  24. def set(self, year=None, month=None, day=None):
  25. """Sets the date in the memory of the sign. This must be done each day to
  26. keep the clock 'up to date', because the sign will not automatically advance
  27. the day.
  28. If the date is not specified in the arguments, today's date will be used.
  29. Args:
  30. year (optional): two-digit year (98, 99, 00, ...)
  31. month (optional): integer month (1, 2, ..., 12)
  32. day (optional): integer day (1, ..., 31)
  33. """
  34. today = datetime.datetime.today()
  35. if year is None:
  36. year = str(today.year)[2:4]
  37. if month is None:
  38. month = today.month
  39. if day is None:
  40. day = today.day
  41. packet = self._packet("%s%s%02d%02d%02d" % (constants.WRITE_SPECIAL, ";",
  42. year, month, day))
  43. return packet
  44. def set_day(self, day=None):
  45. """Set the day of the week on the sign.
  46. If the argument is omitted, today's day will be used.
  47. Args:
  48. day (optional): integer between 1 (Sunday) and 7 (Saturday)
  49. """
  50. if day is None or day < 1 or day > 7:
  51. day = datetime.datetime.today().weekday() + 1
  52. packet = self._packet("%s%s%s" % (constants.WRITE_SPECIAL, "&", day))
  53. return packet