forked from getpelican/pelican-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
39 lines (32 loc) · 848 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Utility functions
"""
from datetime import datetime
import logging
from pelican.utils import set_date_tzinfo
DEV_LOGGER = logging.getLogger(__name__)
STRING_BOOLS = {
'yes': True,
'no': False,
'true': True,
'false': False,
'0': False,
'1': True,
'on': True,
'off': False,
}
def string_to_bool(string):
'''
Convert a string to a bool based
'''
return STRING_BOOLS[string.strip().lower()]
def datetime_from_timestamp(timestamp, content):
"""
Helper function to add timezone information to datetime,
so that datetime is comparable to other datetime objects in recent versions
that now also have timezone information.
"""
return set_date_tzinfo(
datetime.fromtimestamp(timestamp),
tz_name=content.settings.get('TIMEZONE', None))