-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy patharguments.py
More file actions
41 lines (33 loc) · 1.46 KB
/
arguments.py
File metadata and controls
41 lines (33 loc) · 1.46 KB
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
40
41
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import logging
def should_detect(detect):
if detect is None:
return True
return detect
def convert_date_string_to_iso8601(value, argument=None):
import dateutil.parser
try:
d = dateutil.parser.parse(value)
except BaseException as ex: # pylint: disable=broad-except
logging.info(msg=ex)
if argument is None:
raise ValueError('The string "%s" must be a valid date or datetime string.' % value)
raise ValueError('The --%s argument must be a valid ISO 8601 string.' % argument)
if d.tzinfo is None:
from dateutil.tz import tzlocal
d = d.replace(tzinfo=tzlocal())
return d.isoformat()
def convert_date_only_string_to_iso8601(value, argument=None):
import dateutil.parser
try:
d = dateutil.parser.parse(value)
except BaseException as ex: # pylint: disable=broad-except
logging.info(msg=ex)
if argument is None:
raise ValueError('The string "%s" must be a valid date.' % value)
raise ValueError('The --%s argument must be a valid ISO 8601 string.' % argument)
d = d.isoformat()
return d