0003-misc-add-helper-method-to-parse-xsd-datetime-value-i.patch
tests/test_misc.py | ||
---|---|---|
8 | 8 |
import wcs.api # workaround against circular dependencies :/ |
9 | 9 |
from wcs.qommon.form import FileSizeWidget |
10 | 10 |
from wcs.qommon.humantime import humanduration2seconds, seconds2humanduration |
11 |
from wcs.qommon.misc import simplify, json_loads |
|
11 |
from wcs.qommon.misc import simplify, json_loads, parse_isotime
|
|
12 | 12 |
from wcs.admin.settings import FileTypesDirectory |
13 | 13 | |
14 | 14 |
def setup_module(module): |
... | ... | |
95 | 95 |
assert type(json_loads(json_str)['lst'][0]['a']) is str |
96 | 96 |
assert type(json_loads(json_str)['bla']) is str |
97 | 97 |
assert json_loads(json_str)['bla'] == u'éléphant'.encode('utf-8') |
98 | ||
99 |
def test_parse_isotime(): |
|
100 |
assert 1420107019 == parse_isotime('2015-01-01T10:10:19Z') |
|
101 |
with pytest.raises(ValueError): |
|
102 |
parse_isotime('2015-01-01T10:10:19') |
|
103 |
with pytest.raises(ValueError): |
|
104 |
parse_isotime('2015-01-0110:10:19Z') |
wcs/qommon/misc.py | ||
---|---|---|
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import datetime |
18 |
import calendar |
|
18 | 19 |
import re |
19 | 20 |
import os |
20 | 21 |
import time |
... | ... | |
455 | 456 |
json_str = '%s(%s);' % (get_request().form[variable], json_str) |
456 | 457 |
break |
457 | 458 |
return json_str |
459 | ||
460 |
def parse_isotime(s): |
|
461 |
t = time.strptime(s, '%Y-%m-%dT%H:%M:%SZ') |
|
462 |
return calendar.timegm(t) |
|
458 |
- |