Advertisement
SharkyEXE

Untitled

Jan 2nd, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. from Converter import Converter
  2. from time import localtime, strftime, mktime, time
  3. from Components.Element import cached
  4. from datetime import date, datetime
  5.  
  6. MONTHS = (_('Январь'),
  7. _('February'),
  8. _('March'),
  9. _('April'),
  10. _('May'),
  11. _('June'),
  12. _('July'),
  13. _('August'),
  14. _('September'),
  15. _('October'),
  16. _('November'),
  17. _('December'))
  18.  
  19. shortMONTHS = (_('Jan'),
  20. _('Feb'),
  21. _('Mar'),
  22. _('Apr'),
  23. _('May'),
  24. _('Jun'),
  25. _('Jul'),
  26. _('Aug'),
  27. _('Sep'),
  28. _('Oct'),
  29. _('Nov'),
  30. _('Dec'))
  31.  
  32. DAYWEEK = (_('Понедельник'),
  33. _('Вторник'),
  34. _('Среда'),
  35. _('Четверг'),
  36. _('Пятница'),
  37. _('Суббота'),
  38. _('Воскресенье'))
  39.  
  40. shortDAYWEEK = (_('Mon'),
  41. _('Tue'),
  42. _('Wed'),
  43. _('Thu'),
  44. _('Fri'),
  45. _('Sat'),
  46. _('Sun'))
  47.  
  48. class ClockToText(Converter, object):
  49. DEFAULT = 0
  50. FORMAT = 4
  51.  
  52. def __init__(self, type):
  53. elif str(type).find('Format') != -1:
  54. self.type = self.FORMAT
  55. self.fmt_string = type[7:]
  56.  
  57. @cached
  58. def getText(self):
  59. time = self.source.time
  60. if time is None:
  61. return ''
  62.  
  63. elif self.type == self.FORMAT:
  64. spos = self.fmt_string.find('%')
  65. self.fmt_string = self.fmt_string.replace('%A',_(DAYWEEK[t.tm_wday]))
  66. self.fmt_string = self.fmt_string.replace('%B',_(MONTHS[t.tm_mon-1]))
  67. self.fmt_string = self.fmt_string.replace('%a',_(shortDAYWEEK[t.tm_wday]))
  68. self.fmt_string = self.fmt_string.replace('%b',_(shortMONTHS[t.tm_mon-1]))
  69. if spos > 0:
  70. s1 = self.fmt_string[:spos]
  71. s2 = strftime(self.fmt_string[spos:], t)
  72. return str(s1+s2)
  73. else:
  74. return strftime(self.fmt_string, t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement