osx_defaults: fix datetime

Fix #1742
pull/18777/head
Chulki Lee 9 years ago committed by Matt Clay
parent c8bd27f1e8
commit 432a9a31ca

@ -83,7 +83,7 @@ EXAMPLES = '''
- osx_defaults: domain=com.geekchimp.macable key=ExampleKeyToRemove state=absent - osx_defaults: domain=com.geekchimp.macable key=ExampleKeyToRemove state=absent
''' '''
from datetime import datetime import datetime
# exceptions --------------------------------------------------------------- {{{ # exceptions --------------------------------------------------------------- {{{
class OSXDefaultsException(Exception): class OSXDefaultsException(Exception):
@ -141,7 +141,7 @@ class OSXDefaults(object):
raise OSXDefaultsException("Invalid boolean value: {0}".format(repr(value))) raise OSXDefaultsException("Invalid boolean value: {0}".format(repr(value)))
elif type == "date": elif type == "date":
try: try:
return datetime.strptime(value.split("+")[0].strip(), "%Y-%m-%d %H:%M:%S") return datetime.datetime.strptime(value.split("+")[0].strip(), "%Y-%m-%d %H:%M:%S")
except ValueError: except ValueError:
raise OSXDefaultsException( raise OSXDefaultsException(
"Invalid date value: {0}. Required format yyy-mm-dd hh:mm:ss.".format(repr(value)) "Invalid date value: {0}. Required format yyy-mm-dd hh:mm:ss.".format(repr(value))
@ -240,7 +240,7 @@ class OSXDefaults(object):
value = str(self.value) value = str(self.value)
elif self.array_add and self.current_value is not None: elif self.array_add and self.current_value is not None:
value = list(set(self.value) - set(self.current_value)) value = list(set(self.value) - set(self.current_value))
elif isinstance(self.value, datetime): elif isinstance(self.value, datetime.datetime):
value = self.value.strftime('%Y-%m-%d %H:%M:%S') value = self.value.strftime('%Y-%m-%d %H:%M:%S')
else: else:
value = self.value value = self.value

Loading…
Cancel
Save