summaryrefslogtreecommitdiff
path: root/natlangdate.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-06-15 15:58:59 -0500
committerluxagraf <sng@luxagraf.net>2023-06-15 15:58:59 -0500
commitab987e10f154f5536bb8fd936ae0966e909fa969 (patch)
tree9de5076f38b71ececb1bc94f8d9d19170898d603 /natlangdate.py
added all my scriptssynced/master
Diffstat (limited to 'natlangdate.py')
-rwxr-xr-xnatlangdate.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/natlangdate.py b/natlangdate.py
new file mode 100755
index 0000000..4fe7528
--- /dev/null
+++ b/natlangdate.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+import os
+import sys
+import re
+import parsedatetime.parsedatetime as pdt
+#import parsedatetime.parsedatetime_consts as pdc
+import datetime
+
+# Define Globals
+pyDate = os.getenv('KMVAR_myDate')
+
+# Function for parsing a string and returning a datetime value
+def datetimeFromString( s ):
+ #c = pdc.Constants()
+ p = pdt.Calendar()
+ result, what = p.parse( s )
+ dt = 0
+ # See: http://stackoverflow.com/questions/1810432/handling-the-different-results-from-parsedatetime
+ # what was returned (see http://code-bear.com/code/parsedatetime/docs/)
+ # 0 = failed to parse
+ # 1 = date (with current time, as a struct_time)
+ # 2 = time (with current date, as a struct_time)
+ # 3 = datetime
+ if what in (1,2,3):
+ # result is struct_time
+ dt = datetime.datetime( *result[:6] )
+ if what == 0:
+ # Failed to parse
+ raise ValueError, ("Don't understand date '"+s+"'")
+ dt = "Unrecognized Date"
+ return dt
+NLPDate = datetimeFromString(pyDate)
+print NLPDate