jiff 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daee8f43df0fc3c4d69cca0a2e2dfbb2e7021fe0
4
- data.tar.gz: 5b9a63c3a463851d5465870a9f5be7a0824f7c48
3
+ metadata.gz: cc744df326da70beb9508995643106b57dffd77d
4
+ data.tar.gz: b37a887f065fbcacacc21d7001090c4e6fbc14c3
5
5
  SHA512:
6
- metadata.gz: 8e94cef432291f0c14dd3157e32afb9b5f4eb189f1df4c2dace6da56087d707d85a59d4bcdf990fca2ace4b0980d98e1449aeb1b618244086660f634774f29d8
7
- data.tar.gz: 244d48d43198c2c6e79f940b278615ffcb6cac2ee783c74aae5926100ceb733cacb69006eace31cdd9bc2fe8ea99844d323bf97f9adc8406aa87ab815232e75d
6
+ metadata.gz: 2dbf5eddac079fa928dd777eb6e78ee34ce3fd490076ebe8d4ab8e02be2c944d49196588822b49231ad207e3facae84cd3f85757d461f88ccaabcb80766d9546
7
+ data.tar.gz: f982446814eb017b3b792ac90b8e34a13fb84c1a13acc3b701a6d6c46ec786e5ada3cb45f13348e99edecac224bce7737074192f6c6fa0c9d2ba96c450d29ea9
data/README.md CHANGED
@@ -34,6 +34,12 @@ or create one using an unix timestamp:
34
34
  Jiff.new 1414612800
35
35
  ```
36
36
 
37
+ or create one using a query string (see [Chronic](https://github.com/mojombo/chronic) for more examples):
38
+
39
+ ```ruby
40
+ Jiff.new 'tomorrow'
41
+ ```
42
+
37
43
  Access the date/time object at any point:
38
44
 
39
45
  ```ruby
@@ -242,4 +248,5 @@ Please create an [issue](https://github.com/revett/jiff/issues/new) if you find
242
248
 
243
249
  ## Credits
244
250
 
245
- Heavily influenced by [Moment.js](http://momentjs.com/)
251
+ * Heavily influenced by [Moment.js](http://momentjs.com/).
252
+ * [Chronic](https://github.com/mojombo/chronic) is used to parse query Strings.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "jiff"
7
- spec.version = '0.0.4'
7
+ spec.version = '0.1.0'
8
8
  spec.authors = ["Charlie Revett"]
9
9
  spec.email = ["charlierevett@gmail.com"]
10
10
  spec.summary = %q{Parse, validate, manipulate, and display dates in Ruby.}
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "pry"
26
26
 
27
27
  spec.add_runtime_dependency "activesupport"
28
+ spec.add_runtime_dependency "chronic"
28
29
  end
@@ -1,4 +1,5 @@
1
1
  require 'time'
2
+ require 'chronic'
2
3
  require_relative 'jiff/manipulate'
3
4
  require_relative 'jiff/nearest'
4
5
  require_relative 'jiff/timezone'
@@ -61,8 +62,7 @@ class Jiff
61
62
  private
62
63
 
63
64
  def parse(query)
64
- raise ArgumentError, 'Query must be Integer' unless query.is_a? Integer
65
- Time.at query
65
+ query.is_a?(Integer) ? Time.at(query) : Chronic.parse(query)
66
66
  end
67
67
 
68
68
  def pattern(format, to_int = true)
@@ -9,7 +9,7 @@ describe Jiff do
9
9
  after { Timecop.return }
10
10
 
11
11
  describe '.new' do
12
- context 'with no query string' do
12
+ context 'with no query' do
13
13
  specify { expect(subject.date).to eq time }
14
14
  end
15
15
 
@@ -19,9 +19,15 @@ describe Jiff do
19
19
  specify { expect(described_class.new(timestamp).date).to eq expected}
20
20
  end
21
21
 
22
- context 'with a String' do
22
+ context 'with an invalid query String' do
23
23
  let(:query) { 'batman' }
24
- specify { expect{ described_class.new query }.to raise_error ArgumentError }
24
+ specify { expect(described_class.new(query).date).to be nil }
25
+ end
26
+
27
+ context 'with a valid query String' do
28
+ let(:expected) { Time.new(1992, 6, 9, 12, 0, 0) }
29
+ let(:query) { 'tomorrow' }
30
+ specify { expect(described_class.new(query).date).to eq expected }
25
31
  end
26
32
  end
27
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Revett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: chronic
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description:
126
140
  email:
127
141
  - charlierevett@gmail.com