Skip to content

Commit c87af1c

Browse files
committed
Updating validation
1 parent 8da519e commit c87af1c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/azure-cli/azure/cli/command_modules/appconfig/_validators.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
# pylint: disable=line-too-long
77

88
import json
9-
import re
109
import azure.cli.core.azclierror as CLIErrors
11-
from dateutil.parser import isoparse
1210

11+
from datetime import datetime
1312
from knack.log import get_logger
1413
from knack.util import CLIError
1514
from azure.cli.core.azclierror import (InvalidArgumentValueError,
@@ -32,11 +31,21 @@
3231

3332
def validate_datetime(namespace):
3433
''' valid datetime format: YYYY-MM-DDThh:mm:ss["Z"/±hh:mm]'''
34+
supported_formats = ["%Y-%m-%dT%H:%M:%S", "%Y-%m-%dT%H:%M:%Sz", "%Y-%m-%dT%H:%M:%S%z"]
3535
if namespace.datetime is not None:
36-
try:
37-
isoparse(namespace.datetime)
38-
except ValueError:
39-
raise CLIError('The input datetime is invalid. Value should be in ISO-8601 format: YYYY-MM-DDThh:mm:ss["Z"/±hh:mm].')
36+
for supported_format in supported_formats:
37+
if __tryparse_datetime(namespace.datetime, supported_format):
38+
return
39+
40+
raise CLIError('The input datetime is invalid. Correct format should be YYYY-MM-DDThh:mm:ss["Z"/±hh:mm].')
41+
42+
43+
def __tryparse_datetime(datetime_string, format):
44+
try:
45+
datetime.strptime(datetime_string, format)
46+
return True
47+
except ValueError:
48+
return False
4049

4150

4251
def validate_connection_string(cmd, namespace):

0 commit comments

Comments
 (0)