Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80609480
functions.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 1, 15:55
Size
892 B
Mime Type
text/x-python
Expires
Tue, Sep 3, 15:55 (2 d)
Engine
blob
Format
Raw Data
Handle
20406477
Attached To
R11599 sausage-binary
functions.py
View Options
'''
Various functions
'''
from
datetime
import
datetime
from
argparse
import
ArgumentTypeError
from
dateutil.relativedelta
import
relativedelta
def
valid_date
(
date
):
try
:
validate
=
datetime
.
strptime
(
date
,
"%Y-%m-
%d
"
)
return
validate
except
ValueError
as
error
:
msg
=
"Not a valid date: '{0}', YYYY-MM-DD expected."
.
format
(
date
)
raise
ArgumentTypeError
(
msg
)
from
error
def
valid_period
(
date
):
try
:
validate
=
datetime
.
strptime
(
date
,
"%Y-%m"
)
return
(
validate
,
validate
+
relativedelta
(
months
=
1
))
except
ValueError
:
pass
try
:
validate
=
datetime
.
strptime
(
date
,
"%Y"
)
return
(
validate
,
validate
+
relativedelta
(
months
=
12
))
except
ValueError
as
error
:
msg
=
"Not a valid period: '{0}', YYYY-MM or YYYY expected."
.
format
(
date
)
raise
ArgumentTypeError
(
msg
)
from
error
Event Timeline
Log In to Comment