Issues 350 - Formatting date and time

pull/420/head
Jonathan D'Orleans 2016-11-24 21:57:53 -05:00
parent 416191e598
commit d80e83d575
3 changed files with 21 additions and 10 deletions

View File

@ -2,8 +2,8 @@
"lang": "en-us",
"location": "Lawrence, Kansas",
"system_unit": "metric",
"time_format": "%H:%M",
"date_format": "%A, %B %d, %Y",
"time_format": "half",
"date_format": "MDY",
"skills": {
"directory": "~/.mycroft/skills",
"stop_threshold": 2.0

View File

@ -17,7 +17,7 @@
import datetime
from os.path import dirname, join
from os.path import dirname
import tzlocal
from adapt.intent import IntentBuilder
@ -34,12 +34,13 @@ class TimeSkill(MycroftSkill):
def __init__(self):
super(TimeSkill, self).__init__("TimeSkill")
self.astral = Astral()
self.format = self.init_format()
self.init_format()
def init_format(self):
if self.config_core.get('time_format', 'half') == 'half':
return "%I:%M, %p"
return "%H:%M"
if self.config_core.get('time_format') == 'full':
self.format = "%H:%M"
else:
self.format = "%I:%M, %p"
def initialize(self):
self.load_data_files(dirname(__file__))

View File

@ -52,6 +52,18 @@ class ScheduledSkill(MycroftSkill):
self.timer = None
self.calendar = pdt.Calendar()
self.time_rules = time_rules.create(self.lang)
self.init_format()
def init_format(self):
if self.config_core.get('date_format') == 'DMY':
self.format = "%d %B, %Y at "
else:
self.format = "%B %d, %Y at "
if self.config_core.get('time_format') == 'full':
self.format += "%H:%M"
else:
self.format += "%I:%M, %p"
def schedule(self):
times = sorted(self.get_times())
@ -91,9 +103,7 @@ class ScheduledSkill(MycroftSkill):
else:
return "%s minutes and %s seconds from now" % \
(int(minutes), int(seconds))
dt_format = self.config_core.get('date_format')
dt_format += " at " + self.config_core.get('time_format')
return date.strftime(dt_format)
return date.strftime(self.format)
@abc.abstractmethod
def get_times(self):