date_period_parser 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -12
- data/lib/date_period_parser.rb +1 -1
- data/lib/date_period_parser/version.rb +1 -1
- data/spec/date_period_parser_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c07ac23b3837999e42abd603e613c83033866e4
|
4
|
+
data.tar.gz: f0474b0706edd9799c033924a2341a0ba73cb8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9294cf45307a6ce57997bd9806b74d17104a87fbdeab9f816c4b706b7ffaf27eb54d8e2dc98ec72ae8f19ae54f574b20b3f803080111aa3355d31147b587990
|
7
|
+
data.tar.gz: 94211e5781292b746aecc88f69ef7936f55065b44238ab4866ef451f8c9c0101ed1e2614300da001cb3c06cef51f9e3b62880919b1dbce77b72605c69f0f77c2
|
data/README.md
CHANGED
@@ -4,23 +4,21 @@
|
|
4
4
|
|
5
5
|
Parse a date-period string like 2015-Q1 and returns the start and end DateTime.
|
6
6
|
|
7
|
-
Useful for
|
7
|
+
Useful for reporting/pagination/search to filter records for a given time period.
|
8
|
+
|
9
|
+
It is **not** a natural language date parser like the [chronic gem](https://github.com/mojombo/chronic). But intends to parse common formats like [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601).
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
# Example useage in a rails controller
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@posts = Posts.where(created_at: date_range)
|
17
|
-
end
|
12
|
+
# Example useage in a rails controller action
|
13
|
+
|
14
|
+
# GET /posts?period=2015-08
|
15
|
+
def index
|
16
|
+
date_range = DatePeriodParser.range(params["period"], default: "today")
|
17
|
+
@posts = Posts.where(created_at: date_range)
|
18
18
|
end
|
19
19
|
```
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
Examples:
|
21
|
+
Examples periods:
|
24
22
|
|
25
23
|
* years `YYYY`
|
26
24
|
* months `YYYY-MM`
|
data/lib/date_period_parser.rb
CHANGED
@@ -7,6 +7,14 @@ describe DatePeriodParser do
|
|
7
7
|
DatePeriodParser.parse(str, opts)
|
8
8
|
end
|
9
9
|
|
10
|
+
def range(str, opts = {})
|
11
|
+
DatePeriodParser.range(str, opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "range" do
|
15
|
+
range("today")
|
16
|
+
end
|
17
|
+
|
10
18
|
it 'parse' do
|
11
19
|
assert parse(:today) != nil
|
12
20
|
assert_equal DateTime.new(2014, 1, 1, 0, 0, 0.000, "+0000"), parse("2014").first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_period_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hasclass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|