summaryrefslogtreecommitdiff
path: root/lib/optparse/date.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/optparse/date.rb')
-rw-r--r--lib/optparse/date.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/optparse/date.rb b/lib/optparse/date.rb
new file mode 100644
index 0000000..c9f072f
--- /dev/null
+++ b/lib/optparse/date.rb
@@ -0,0 +1,17 @@
+require 'optparse'
+require 'date'
+
+OptionParser.accept(DateTime) do |s,|
+ begin
+ DateTime.parse(s) if s
+ rescue ArgumentError
+ raise OptionParser::InvalidArgument, s
+ end
+end
+OptionParser.accept(Date) do |s,|
+ begin
+ DateTime.parse(s) if s
+ rescue ArgumentError
+ raise OptionParser::InvalidArgument, s
+ end
+end