friends 0.32 → 0.33

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: 6442d6d8566016d767f79473e03abed09746b0b8
4
- data.tar.gz: 63b53260698a0d144bce84e399fcf5947e6f9b13
3
+ metadata.gz: beaf0948ba10e832a1997429d3d4f3eea13874a0
4
+ data.tar.gz: 635351a704703797fbc817a0acbe43fa90b2ffbf
5
5
  SHA512:
6
- metadata.gz: a526deeed0f736bb3dc7d5b9f67be7c7e9debaa1d85e7effc65b74c126db5e0acd4eef8a5e6fdb09808d7081a61de3afb9631feca4fcab16ae4865d48d68c93a
7
- data.tar.gz: 9c2a52e89e4aaea1ddfb4e1f3f674d8031fff252374868403a9191104a8d6677fb4e65f541984b8caa1ba87ff850c926958f8f0d3515585546569b70ebab0daa
6
+ metadata.gz: f80bd7d3b7ac0603d52cb518cdaa2bf41c6711d3f0c5c82c50811a4e2ed417d68551b8303a0d9d077004590024809719d2c396c2b017e4932efb2b26d50cd46c
7
+ data.tar.gz: a7e060faa531c39ddaf1975292d6c2ad9722cc3145bbc8d9db5afa28da4e9b4d6aaeabdcc9cf9469cc855dceb522ac348690faee8b2e2169300bc820d0bdbad8
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.33](https://github.com/JacobEvelyn/friends/tree/v0.33) (2017-08-22)
4
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.32...v0.33)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Prevent dates without years from being in the future [\#181](https://github.com/JacobEvelyn/friends/pull/181) ([JacobEvelyn](https://github.com/JacobEvelyn))
9
+
3
10
  ## [v0.32](https://github.com/JacobEvelyn/friends/tree/v0.32) (2017-07-25)
4
11
  [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.31...v0.32)
5
12
 
@@ -34,9 +34,28 @@ module Friends
34
34
  # Partition lets us parse "Today" and "Today: I awoke." identically.
35
35
  date_s, _, description = str.partition(DATE_PARTITION)
36
36
 
37
- # rubocop:disable Lint/AssignmentInCondition
38
- if time = (date_s =~ /^\d{4}-\d{2}-\d{2}$/ ? Time : Chronic).parse(date_s)
39
- # rubocop:enable Lint/AssignmentInCondition
37
+ time = if date_s =~ /^\d{4}-\d{2}-\d{2}$/
38
+ Time.parse(date_s)
39
+ else
40
+ # If the user inputed a non YYYY-MM-DD format, asssume
41
+ # it is in the past.
42
+ past_time = Chronic.parse(date_s, context: :past)
43
+
44
+ # If there's no year, Chronic will sometimes parse the date
45
+ # as being the next occurrence of that date in the future.
46
+ # Instead, we want to subtract one year to make it the last
47
+ # occurrence of the date in the past.
48
+ # NOTE: This is a hacky workaround for the fact that
49
+ # Chronic's `context: :past` doesn't actually work. We should
50
+ # remove this when that behavior is fixed.
51
+ if past_time && past_time > Time.now
52
+ Time.local(past_time.year - 1, past_time.month, past_time.day)
53
+ else
54
+ past_time
55
+ end
56
+ end
57
+
58
+ if time
40
59
  @date = time.to_date
41
60
  @description = description
42
61
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Friends
4
- VERSION = "0.32"
4
+ VERSION = "0.33"
5
5
  end
@@ -29,12 +29,25 @@ def date_parsing_specs(test_stdout: true)
29
29
  it { stdout_only "Activity added: \"2017-03-02: #{description}\"" } if test_stdout
30
30
  end
31
31
 
32
- describe "when date is natural language" do
32
+ describe "when date is natural language and in full" do
33
33
  let(:date) { "February 23rd, 2017" }
34
34
 
35
35
  it { line_added "- 2017-02-23: #{description}" }
36
36
  it { stdout_only "Activity added: \"2017-02-23: #{description}\"" } if test_stdout
37
37
  end
38
+
39
+ describe "when date is natural language and only month and day" do
40
+ # We use two days rather than just one to avoid strange behavior around
41
+ # edge cases when the test is being run right around midnight.
42
+ let(:two_days_in_seconds) { 2 * 24 * 60 * 60 }
43
+ let(:raw_date) { Time.now + two_days_in_seconds }
44
+ let(:date) { raw_date.strftime("%B %d") }
45
+ let(:expected_year) { raw_date.strftime("%Y").to_i - 1 }
46
+ let(:expected_date_str) { "#{expected_year}-#{raw_date.strftime('%m-%d')}" }
47
+
48
+ it { line_added "- #{expected_date_str}: #{description}" }
49
+ it { stdout_only "Activity added: \"#{expected_date_str}: #{description}\"" } if test_stdout
50
+ end
38
51
  end
39
52
  end
40
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friends
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.32'
4
+ version: '0.33'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evelyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic