qreport_time_parser 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11d376f6c6d18b170a60de9866f7bcc2c69d1962
4
+ data.tar.gz: 2205c1ec0a2151747cd6ed1e0945f4f1bec5de47
5
+ SHA512:
6
+ metadata.gz: 432466f0ada7f6aefc254aaa1e7c9b09a368f26cb229734f38c6e5dda2fd3ad57209b0ac9138b067b3db7e2f56ba910b0cfd8451f72e3153181817b5d0f36454
7
+ data.tar.gz: 6c7c23628914b28ed59eb2d80aeba0778d8a60b7c4e8f792565dbae1bea1e3ec9563f1be333b772e07f813a04bc75ee586f75ab3cbe7656a28d352dfb9b5e4c1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qreport_time_parser.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+ guard 'rspec' do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch(%r{^lib/qreport/time_parser/(.+)\.rb$}) { "spec" }
6
+ watch('spec/spec_helper.rb') { "spec" }
7
+ end
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Kurt Stephens
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # QreportTimeParser
2
+
3
+ A Time/Date parser with implicit precision.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qreport_time_parser'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qreport_time_parser
18
+
19
+ ## Usage
20
+
21
+ Qreport::TimeParser will parse human-specified Time values into Time ranges with implicit precision.
22
+
23
+ ## Examples
24
+
25
+ require 'qreport/time_parser'
26
+
27
+ p = Qreport::TimeParser.new
28
+ p.now = Time.parse('2011-03-10T15:10:37-06:00')
29
+
30
+ puts p.parse("now").to_TimeRange
31
+ # => "nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00"
32
+
33
+ puts p.parse("2011-03-10 15:10:37 -0600").to_TimeRange
34
+ # => "nil 2011-03-10T15:10:37.000000-06:00 ... nil 2011-03-10T15:10:38.000000-06:00"
35
+
36
+ puts p.parse("2011-03-10 15:10:37.981304 -0600").to_TimeRange
37
+ # => "nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00"
38
+
39
+ puts p.parse("today").to_TimeRange
40
+ # => ":day 2011-03-10T00:00:00.000000-06:00 ... :day 2011-03-11T00:00:00.000000-06:00"
41
+
42
+ puts p.parse("tomorrow").to_TimeRange
43
+ # => ":day 2011-03-11T00:00:00.000000-06:00 ... :day 2011-03-12T00:00:00.000000-06:00"
44
+
45
+ puts p.parse("yesterday").to_TimeRange
46
+ # => ":day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00"
47
+
48
+ puts p.parse("9:15am yesterday").to_TimeRange
49
+ # => ":min 2011-03-09T09:15:00.000000-06:00 ... :min 2011-03-09T09:16:00.000000-06:00"
50
+
51
+ puts p.parse("yesterday 9:15am").to_TimeRange
52
+ # => ":day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00"
53
+
54
+ puts p.parse("10 days ago").to_TimeRange
55
+ # => ":day 2011-02-28T00:00:00.000000-06:00 ... :day 2011-03-01T00:00:00.000000-06:00"
56
+
57
+ puts p.parse("10 s ago").to_TimeRange
58
+ # => ":sec 2011-03-10T15:10:27.000000-06:00 ... :sec 2011-03-10T15:10:28.000000-06:00"
59
+
60
+ puts p.parse("day before yesterday").to_TimeRange
61
+ # => ":day 2011-03-08T00:00:00.000000-06:00 ... :day 2011-03-09T00:00:00.000000-06:00"
62
+
63
+ puts p.parse("hr before tomorrow").to_TimeRange
64
+ # => ":hour 2011-03-10T23:00:00.000000-06:00 ... :hour 2011-03-11T00:00:00.000000-06:00"
65
+
66
+ puts p.parse("3 days before today").to_TimeRange
67
+ # => ":day 2011-03-07T00:00:00.000000-06:00 ... :day 2011-03-08T00:00:00.000000-06:00"
68
+
69
+ puts p.parse("5 days after today").to_TimeRange
70
+ # => ":day 2011-03-15T00:00:00.000000-05:00 ... :day 2011-03-16T00:00:00.000000-05:00"
71
+
72
+ puts p.parse("5 days before now").to_TimeRange
73
+ # => "nil 2011-03-05T15:10:37.981304-06:00 ... nil 2011-03-05T15:10:38.981304-06:00"
74
+
75
+ puts p.parse("3 days before this minute").to_TimeRange
76
+ # => ":min 2011-03-07T15:10:00.000000-06:00 ... :min 2011-03-07T15:11:00.000000-06:00"
77
+
78
+ puts p.parse("5 days before yesterday").to_TimeRange
79
+ # => ":day 2011-03-04T00:00:00.000000-06:00 ... :day 2011-03-05T00:00:00.000000-06:00"
80
+
81
+ puts p.parse("2 days before 50 hours after tomorrow").to_TimeRange
82
+ # => ":hour 2011-03-11T02:00:00.000000-06:00 ... :hour 2011-03-11T03:00:00.000000-06:00"
83
+
84
+ puts p.parse("2 centuries after today").to_TimeRange
85
+ # => ":day 2211-01-21T00:00:00.000000-06:00 ... :day 2211-01-22T00:00:00.000000-06:00"
86
+
87
+ puts p.parse("1pm").to_TimeRange
88
+ # => ":hour 2011-03-10T13:00:00.000000-06:00 ... :hour 2011-03-10T14:00:00.000000-06:00"
89
+
90
+ puts p.parse("12:30pm").to_TimeRange
91
+ # => ":min 2011-03-10T12:30:00.000000-06:00 ... :min 2011-03-10T12:31:00.000000-06:00"
92
+
93
+ puts p.parse("9:20am tomorrow").to_TimeRange
94
+ # => ":min 2011-03-11T09:20:00.000000-06:00 ... :min 2011-03-11T09:21:00.000000-06:00"
95
+
96
+ puts p.parse("6am 3 days from yesterday").to_TimeRange
97
+ # => ":hour 2011-03-12T06:00:00.000000-06:00 ... :hour 2011-03-12T07:00:00.000000-06:00"
98
+
99
+ puts p.parse("2001/01").to_TimeRange
100
+ # => ":mon 2001-01-01T00:00:00.000000-06:00 ... :mon 2001-02-01T00:00:00.000000-06:00"
101
+
102
+ puts p.parse("2001-01").to_TimeRange
103
+ # => ":mon 2001-01-01T00:00:00.000000-06:00 ... :mon 2001-02-01T00:00:00.000000-06:00"
104
+
105
+ puts p.parse("01/2001").to_TimeRange
106
+ # => #<Qreport::TimeParser::Error::Syntax: syntax error at position 2: "01 |^| /2001">
107
+
108
+ puts p.parse("2001/02/03 12:23pm").to_TimeRange
109
+ # => ":min 2001-02-03T12:23:00.000000-06:00 ... :min 2001-02-03T12:24:00.000000-06:00"
110
+
111
+ puts p.parse("12/31 12:59pm").to_TimeRange
112
+ # => ":min 2011-12-31T12:59:00.000000-06:00 ... :min 2011-12-31T13:00:00.000000-06:00"
113
+
114
+ puts p.parse("12/31 last year").to_TimeRange
115
+ # => ":day 2010-12-31T00:00:00.000000-06:00 ... :day 2011-01-01T00:00:00.000000-06:00"
116
+
117
+ puts p.parse("12:59:59pm 12/31 next year").to_TimeRange
118
+ # => ":sec 2012-12-31T12:59:59.000000-06:00 ... :sec 2012-12-31T13:00:00.000000-06:00"
119
+
120
+ puts p.parse("1:23:45pm 1/2 in 2 years").to_TimeRange
121
+ # => ":sec 2013-01-01T13:23:45.000000-06:00 ... :sec 2013-01-01T13:23:46.000000-06:00"
122
+
123
+ puts p.parse("2011-03-10T15:10:37-06:00").to_TimeRange
124
+ # => "nil 2011-03-10T15:10:37.000000-06:00 ... nil 2011-03-10T15:10:38.000000-06:00"
125
+
126
+ puts p.parse("2011-03-10T15:10:37.981304-06:00").to_TimeRange
127
+ # => "nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00"
128
+
129
+ puts p.parse("2011-03-10T15:10:37-06:00 plus 10 sec").to_TimeRange
130
+ # => ":sec 2011-03-10T15:10:47.000000-06:00 ... :sec 2011-03-10T15:10:48.000000-06:00"
131
+
132
+ puts p.parse("2011-03-10T15:10:37.981304-06:00 - 2 weeks").to_TimeRange
133
+ # => "nil 2011-02-24T15:10:37.981304-06:00 ... nil 2011-02-24T15:10:38.981304-06:00"
134
+
135
+ puts p.parse("now minus 2.5 weeks").to_TimeRange
136
+ # => "nil 2011-03-10T15:10:35.481304-06:00 ... nil 2011-03-10T15:10:36.481304-06:00"
137
+
138
+ puts p.parse("t - 10 sec").to_TimeRange
139
+ # => "nil 2011-03-10T15:10:27.981304-06:00 ... nil 2011-03-10T15:10:28.981304-06:00"
140
+
141
+ puts p.parse("123.45 sec ago").to_TimeRange
142
+ # => "nil 2011-03-10T15:08:34.531303-06:00 ... nil 2011-03-10T15:08:35.531303-06:00"
143
+
144
+ puts p.parse("year 2010").to_TimeRange
145
+ # => ":year 2010-01-01T00:00:00.000000-06:00 ... :year 2011-01-01T00:00:00.000000-06:00"
146
+
147
+ puts p.parse("between 12:45pm and 1:15pm").to_TimeRange
148
+ # => ":min 2011-03-10T12:45:00.000000-06:00 ... :min 2011-03-10T13:15:00.000000-06:00"
149
+
150
+ puts p.parse("before 1:23pm tomorrow").to_TimeRange
151
+ # => ":min 2011-03-11T13:22:00.000000-06:00 ... :min 2011-03-11T13:23:00.000000-06:00"
152
+
153
+ puts p.parse("this minute").to_TimeRange
154
+ # => ":min 2011-03-10T15:10:00.000000-06:00 ... :min 2011-03-10T15:11:00.000000-06:00"
155
+
156
+ puts p.parse("last hour").to_TimeRange
157
+ # => ":hour 2011-03-10T14:00:00.000000-06:00 ... :hour 2011-03-10T15:00:00.000000-06:00"
158
+
159
+ puts p.parse("previous hour").to_TimeRange
160
+ # => ":hour 2011-03-10T14:00:00.000000-06:00 ... :hour 2011-03-10T15:00:00.000000-06:00"
161
+
162
+ puts p.parse("last day").to_TimeRange
163
+ # => ":day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00"
164
+
165
+ puts p.parse("previous day").to_TimeRange
166
+ # => ":day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00"
167
+
168
+ puts p.parse(" 2001-01 + 1234 ajsdkfsd hours").to_TimeRange
169
+ # => #<Qreport::TimeParser::Error::Syntax: syntax error at position 17: " 2001-01 + 1234 |^| ajsdkfsd hours">
170
+
171
+
172
+ # UNIMPLEMENTED YET:
173
+
174
+ puts p.parse("15 sec").to_TimeRange
175
+ # => #<Qreport::TimeParser::Error: Qreport::TimeParser::Error>
176
+
177
+ puts p.parse("12 minutes").to_TimeRange
178
+ # => #<Qreport::TimeParser::Error: Qreport::TimeParser::Error>
179
+
180
+
181
+ ## Contributing
182
+
183
+ 1. Fork it
184
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
185
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
186
+ 4. Push to the branch (`git push origin my-new-feature`)
187
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ gem 'rspec'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Default => :test"
6
+ task :default => :test
7
+
8
+ desc "Run all tests"
9
+ task :test => [ :spec ]
10
+
11
+ desc "Run specs"
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'qreport/time_parser/examples'
4
+
5
+ fh = File.open("#{File.dirname(__FILE__)}/examples.rb", "w+")
6
+ def fh.p *args
7
+ write " "
8
+ puts *args
9
+ end
10
+
11
+ fh.p "require 'qreport/time_parser'"
12
+ fh.p ""
13
+ examples = Qreport::TimeParser.examples
14
+ now = examples[:now]
15
+ fh.p "p = Qreport::TimeParser.new"
16
+ fh.p "p.now = Time.parse('#{now.iso8601}')"
17
+ fh.p ""
18
+ examples.each do | expr, val |
19
+ next if Symbol === expr
20
+ val, time_range = val if Array === val
21
+ t = err = nil
22
+ begin
23
+ tp = Qreport::TimeParser.new
24
+ tp.now = now
25
+ # tp.debug = true if expr =~ /between/i
26
+ t = tp.parse(expr)
27
+ rescue Qreport::TimeParser::Error => exc
28
+ $stderr.puts "ERROR: #{exc.inspect}"
29
+ err = exc
30
+ end
31
+ fh.p "puts p.parse(#{expr.inspect}).to_TimeRange"
32
+ if t
33
+ fh.p " # => #{t.to_TimeRange}"
34
+ fh.p ""
35
+ end
36
+ if err
37
+ fh.p " # => #{err.inspect}"
38
+ fh.p ""
39
+ end
40
+ end
41
+
42
+ fh.close
43
+
@@ -0,0 +1,152 @@
1
+ require 'qreport/time_parser'
2
+
3
+ p = Qreport::TimeParser.new
4
+ p.now = Time.parse('2011-03-10T15:10:37-06:00')
5
+
6
+ puts p.parse("now").to_TimeRange
7
+ # => nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00
8
+
9
+ puts p.parse("2011-03-10 15:10:37 -0600").to_TimeRange
10
+ # => nil 2011-03-10T15:10:37.000000-06:00 ... nil 2011-03-10T15:10:38.000000-06:00
11
+
12
+ puts p.parse("2011-03-10 15:10:37.981304 -0600").to_TimeRange
13
+ # => nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00
14
+
15
+ puts p.parse("today").to_TimeRange
16
+ # => :day 2011-03-10T00:00:00.000000-06:00 ... :day 2011-03-11T00:00:00.000000-06:00
17
+
18
+ puts p.parse("tomorrow").to_TimeRange
19
+ # => :day 2011-03-11T00:00:00.000000-06:00 ... :day 2011-03-12T00:00:00.000000-06:00
20
+
21
+ puts p.parse("yesterday").to_TimeRange
22
+ # => :day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00
23
+
24
+ puts p.parse("9:15am yesterday").to_TimeRange
25
+ # => :min 2011-03-09T09:15:00.000000-06:00 ... :min 2011-03-09T09:16:00.000000-06:00
26
+
27
+ puts p.parse("yesterday 9:15am").to_TimeRange
28
+ # => :day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00
29
+
30
+ puts p.parse("10 days ago").to_TimeRange
31
+ # => :day 2011-02-28T00:00:00.000000-06:00 ... :day 2011-03-01T00:00:00.000000-06:00
32
+
33
+ puts p.parse("10 s ago").to_TimeRange
34
+ # => :sec 2011-03-10T15:10:27.000000-06:00 ... :sec 2011-03-10T15:10:28.000000-06:00
35
+
36
+ puts p.parse("day before yesterday").to_TimeRange
37
+ # => :day 2011-03-08T00:00:00.000000-06:00 ... :day 2011-03-09T00:00:00.000000-06:00
38
+
39
+ puts p.parse("hr before tomorrow").to_TimeRange
40
+ # => :hour 2011-03-10T23:00:00.000000-06:00 ... :hour 2011-03-11T00:00:00.000000-06:00
41
+
42
+ puts p.parse("3 days before today").to_TimeRange
43
+ # => :day 2011-03-07T00:00:00.000000-06:00 ... :day 2011-03-08T00:00:00.000000-06:00
44
+
45
+ puts p.parse("5 days after today").to_TimeRange
46
+ # => :day 2011-03-15T00:00:00.000000-05:00 ... :day 2011-03-16T00:00:00.000000-05:00
47
+
48
+ puts p.parse("5 days before now").to_TimeRange
49
+ # => nil 2011-03-05T15:10:37.981304-06:00 ... nil 2011-03-05T15:10:38.981304-06:00
50
+
51
+ puts p.parse("3 days before this minute").to_TimeRange
52
+ # => :min 2011-03-07T15:10:00.000000-06:00 ... :min 2011-03-07T15:11:00.000000-06:00
53
+
54
+ puts p.parse("5 days before yesterday").to_TimeRange
55
+ # => :day 2011-03-04T00:00:00.000000-06:00 ... :day 2011-03-05T00:00:00.000000-06:00
56
+
57
+ puts p.parse("2 days before 50 hours after tomorrow").to_TimeRange
58
+ # => :hour 2011-03-11T02:00:00.000000-06:00 ... :hour 2011-03-11T03:00:00.000000-06:00
59
+
60
+ puts p.parse("2 centuries after today").to_TimeRange
61
+ # => :day 2211-01-21T00:00:00.000000-06:00 ... :day 2211-01-22T00:00:00.000000-06:00
62
+
63
+ puts p.parse("1pm").to_TimeRange
64
+ # => :hour 2011-03-10T13:00:00.000000-06:00 ... :hour 2011-03-10T14:00:00.000000-06:00
65
+
66
+ puts p.parse("12:30pm").to_TimeRange
67
+ # => :min 2011-03-10T12:30:00.000000-06:00 ... :min 2011-03-10T12:31:00.000000-06:00
68
+
69
+ puts p.parse("9:20am tomorrow").to_TimeRange
70
+ # => :min 2011-03-11T09:20:00.000000-06:00 ... :min 2011-03-11T09:21:00.000000-06:00
71
+
72
+ puts p.parse("6am 3 days from yesterday").to_TimeRange
73
+ # => :hour 2011-03-12T06:00:00.000000-06:00 ... :hour 2011-03-12T07:00:00.000000-06:00
74
+
75
+ puts p.parse("2001/01").to_TimeRange
76
+ # => :mon 2001-01-01T00:00:00.000000-06:00 ... :mon 2001-02-01T00:00:00.000000-06:00
77
+
78
+ puts p.parse("2001-01").to_TimeRange
79
+ # => :mon 2001-01-01T00:00:00.000000-06:00 ... :mon 2001-02-01T00:00:00.000000-06:00
80
+
81
+ puts p.parse("01/2001").to_TimeRange
82
+ # => #<Qreport::TimeParser::Error::Syntax: syntax error at position 2: "01 |^| /2001">
83
+
84
+ puts p.parse("2001/02/03 12:23pm").to_TimeRange
85
+ # => :min 2001-02-03T12:23:00.000000-06:00 ... :min 2001-02-03T12:24:00.000000-06:00
86
+
87
+ puts p.parse("12/31 12:59pm").to_TimeRange
88
+ # => :min 2011-12-31T12:59:00.000000-06:00 ... :min 2011-12-31T13:00:00.000000-06:00
89
+
90
+ puts p.parse("12/31 last year").to_TimeRange
91
+ # => :day 2010-12-31T00:00:00.000000-06:00 ... :day 2011-01-01T00:00:00.000000-06:00
92
+
93
+ puts p.parse("12:59:59pm 12/31 next year").to_TimeRange
94
+ # => :sec 2012-12-31T12:59:59.000000-06:00 ... :sec 2012-12-31T13:00:00.000000-06:00
95
+
96
+ puts p.parse("1:23:45pm 1/2 in 2 years").to_TimeRange
97
+ # => :sec 2013-01-01T13:23:45.000000-06:00 ... :sec 2013-01-01T13:23:46.000000-06:00
98
+
99
+ puts p.parse("2011-03-10T15:10:37-06:00").to_TimeRange
100
+ # => nil 2011-03-10T15:10:37.000000-06:00 ... nil 2011-03-10T15:10:38.000000-06:00
101
+
102
+ puts p.parse("2011-03-10T15:10:37.981304-06:00").to_TimeRange
103
+ # => nil 2011-03-10T15:10:37.981304-06:00 ... nil 2011-03-10T15:10:38.981304-06:00
104
+
105
+ puts p.parse("2011-03-10T15:10:37-06:00 plus 10 sec").to_TimeRange
106
+ # => :sec 2011-03-10T15:10:47.000000-06:00 ... :sec 2011-03-10T15:10:48.000000-06:00
107
+
108
+ puts p.parse("2011-03-10T15:10:37.981304-06:00 - 2 weeks").to_TimeRange
109
+ # => nil 2011-02-24T15:10:37.981304-06:00 ... nil 2011-02-24T15:10:38.981304-06:00
110
+
111
+ puts p.parse("now minus 2.5 weeks").to_TimeRange
112
+ # => nil 2011-03-10T15:10:35.481304-06:00 ... nil 2011-03-10T15:10:36.481304-06:00
113
+
114
+ puts p.parse("t - 10 sec").to_TimeRange
115
+ # => nil 2011-03-10T15:10:27.981304-06:00 ... nil 2011-03-10T15:10:28.981304-06:00
116
+
117
+ puts p.parse("123.45 sec ago").to_TimeRange
118
+ # => nil 2011-03-10T15:08:34.531303-06:00 ... nil 2011-03-10T15:08:35.531303-06:00
119
+
120
+ puts p.parse("year 2010").to_TimeRange
121
+ # => :year 2010-01-01T00:00:00.000000-06:00 ... :year 2011-01-01T00:00:00.000000-06:00
122
+
123
+ puts p.parse("between 12:45pm and 1:15pm").to_TimeRange
124
+ # => :min 2011-03-10T12:45:00.000000-06:00 ... :min 2011-03-10T13:15:00.000000-06:00
125
+
126
+ puts p.parse("before 1:23pm tomorrow").to_TimeRange
127
+ # => :min 2011-03-11T13:22:00.000000-06:00 ... :min 2011-03-11T13:23:00.000000-06:00
128
+
129
+ puts p.parse("this minute").to_TimeRange
130
+ # => :min 2011-03-10T15:10:00.000000-06:00 ... :min 2011-03-10T15:11:00.000000-06:00
131
+
132
+ puts p.parse("last hour").to_TimeRange
133
+ # => :hour 2011-03-10T14:00:00.000000-06:00 ... :hour 2011-03-10T15:00:00.000000-06:00
134
+
135
+ puts p.parse("previous hour").to_TimeRange
136
+ # => :hour 2011-03-10T14:00:00.000000-06:00 ... :hour 2011-03-10T15:00:00.000000-06:00
137
+
138
+ puts p.parse("last day").to_TimeRange
139
+ # => :day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00
140
+
141
+ puts p.parse("previous day").to_TimeRange
142
+ # => :day 2011-03-09T00:00:00.000000-06:00 ... :day 2011-03-10T00:00:00.000000-06:00
143
+
144
+ puts p.parse(" 2001-01 + 1234 ajsdkfsd hours").to_TimeRange
145
+ # => #<Qreport::TimeParser::Error::Syntax: syntax error at position 17: " 2001-01 + 1234 |^| ajsdkfsd hours">
146
+
147
+ puts p.parse("15 sec").to_TimeRange
148
+ # => #<Qreport::TimeParser::Error: Qreport::TimeParser::Error>
149
+
150
+ puts p.parse("12 minutes").to_TimeRange
151
+ # => #<Qreport::TimeParser::Error: Qreport::TimeParser::Error>
152
+