date_period_parser 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90516f6773fd43e04a5134ea3c2d067d885ea5f8
4
- data.tar.gz: 4038d871c3a4339bb709ef6e7010a4947ad5b2a5
3
+ metadata.gz: 9c07ac23b3837999e42abd603e613c83033866e4
4
+ data.tar.gz: f0474b0706edd9799c033924a2341a0ba73cb8ed
5
5
  SHA512:
6
- metadata.gz: a4e833f6ad144dcf5c2883feb4f4f5d0fc31a245b1dce0b39fc22ff4310cb4f9d2f9405043a0bf0c404d50437a051bb00e974bdceb6b3c1e4d5ec79015e79c3a
7
- data.tar.gz: c28fefc56507da2baa84c8dd79dece8e8cb0a5e3b09e6558724894d4d59946c5e07f0116d095b71dcdf5e9138242febbe116d048e9e2218ff5bc74120da77ec0
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 reports to filterin records for a given time period.
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
- class PostsController
13
- # GET /posts?period=2015-08
14
- def index
15
- date_range = DatePeriodParser.range(params["period"], default: "this-month")
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
- 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).
22
-
23
- Examples:
21
+ Examples periods:
24
22
 
25
23
  * years `YYYY`
26
24
  * months `YYYY-MM`
@@ -95,7 +95,7 @@ module DatePeriodParser
95
95
  #
96
96
  def range!(period, options = {})
97
97
  period = options[:default] if period.nil? || period.empty?
98
- first,last = Base.new(period, offset).parse
98
+ first,last = Base.new(period, options).parse
99
99
  first..last
100
100
  end
101
101
 
@@ -1,3 +1,3 @@
1
1
  module DatePeriodParser
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -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.3
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-09-16 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler