Events and States are no longer dicts but objects.
This commit is contained in:
1 parent
ae2058de70
commit
3c3e7e5825
9 files changed
+212
-129
No files matched your search
@@ -1,10 +1,13 @@
|
||||
""" Helper methods for various modules. """
|
||||
|
||||
import datetime
|
||||
import re
|
||||
|
||||
RE_SANITIZE_FILENAME = re.compile(r"(~|(\.\.)|/|\+)")
|
||||
RE_SLUGIFY = re.compile(r'[^A-Za-z0-9_]+')
|
||||
|
||||
DATE_STR_FORMAT = "%H:%M:%S %d-%m-%Y"
|
||||
|
||||
|
||||
def sanitize_filename(filename):
|
||||
""" Sanitizes a filename by removing .. / and \\. """
|
||||
@@ -16,3 +19,22 @@ def slugify(text):
|
||||
text = text.strip().replace(" ", "_")
|
||||
|
||||
return RE_SLUGIFY.sub("", text)
|
||||
|
||||
|
||||
def datetime_to_str(dattim):
|
||||
""" Converts datetime to a string format.
|
||||
|
||||
@rtype : str
|
||||
"""
|
||||
return dattim.strftime(DATE_STR_FORMAT)
|
||||
|
||||
|
||||
def str_to_datetime(dt_str):
|
||||
""" Converts a string to a datetime object.
|
||||
|
||||
@rtype: datetime
|
||||
"""
|
||||
try:
|
||||
return datetime.datetime.strptime(dt_str, DATE_STR_FORMAT)
|
||||
except ValueError: # If dt_str did not match our format
|
||||
return None
|
||||
Reference in new issue
Block a user