diff options
author | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-14 08:36:47 +0000 |
---|---|---|
committer | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-14 08:36:47 +0000 |
commit | 3e8e5bbe2489138460cd65c021107ccf6c607e25 (patch) | |
tree | 58fb22ccf9ef1886b746054d2fd5c0d582646d74 | |
parent | fa3a163cacd0516f5282424478a0f30f54fe13a4 (diff) | |
download | pyparsing-3e8e5bbe2489138460cd65c021107ccf6c607e25.tar.gz |
Add examples from pyparsing_common
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@418 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r-- | src/examples/datetimeParseActions.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/examples/datetimeParseActions.py b/src/examples/datetimeParseActions.py index 4d726c5..34b9d2b 100644 --- a/src/examples/datetimeParseActions.py +++ b/src/examples/datetimeParseActions.py @@ -30,7 +30,7 @@ def convertToDatetime(s,loc,tokens): # on the integer expression above
return datetime(tokens.year, tokens.month, tokens.day).date()
except Exception as ve:
- errmsg = "'%d/%d/%d' is not a valid date, %s" % \
+ errmsg = "'%s/%s/%s' is not a valid date, %s" % \
(tokens.year, tokens.month, tokens.day, ve)
raise ParseException(s, loc, errmsg)
date_expr.setParseAction(convertToDatetime)
@@ -41,4 +41,16 @@ date_expr.runTests("""\ 2000/13/1 # invalid month
1900/2/29 # 1900 was not a leap year
2000/2/29 # but 2000 was
+ """)
+
+
+# if dates conform to ISO8601, use definitions in pyparsing_common
+date_expr = pyparsing_common.iso8601_date.setParseAction(pyparsing_common.convertToDate())
+date_expr.ignore(pythonStyleComment)
+
+date_expr.runTests("""\
+ 2000-01-01
+ 2000-13-01 # invalid month
+ 1900-02-29 # 1900 was not a leap year
+ 2000-02-29 # but 2000 was
""")
\ No newline at end of file |