timetwister 0.3.1 → 0.4.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
  SHA256:
3
- metadata.gz: 93fa574a2f0c2978b64b08db23b61cc6805f35ea2f9e94036e90ad010425d425
4
- data.tar.gz: 10aee7dcc195da3eb77108113ed67d9eea87641782ae00216c3509adabf94a2e
3
+ metadata.gz: fc36713ba664a945f35f2174a7047646118b90e40ba78edede43e8a4efe891f8
4
+ data.tar.gz: b6861861782dae33194e0e4d601d316f6246b14baacb73e0b4ebe31f7007c007
5
5
  SHA512:
6
- metadata.gz: 519d4485a0472394c83a3473d1d5720f2a6d7e6427d4411abb3643d971bc19e199b0ca9f38a0d9bb53aaaaa4b24430eb131e0455fd7a61edf87c67e43b7f41b4
7
- data.tar.gz: 383890f74d7b161718b5b8e7e8c445e6847740bda00e46439c40ac2ae5e89b8dca75128816d963be23747dfe4a19613cac8da9031c13c854fa91916fa030d3d4
6
+ metadata.gz: 7880c0927a7a48d0cba0ac9dc52058fa3def90b986201d553fc0df9f288c7bd72c0fb2e71731892733db6ff138f1630a8edc6264fa4819106dabc7ef6fe181b7
7
+ data.tar.gz: b8d5517e5e2ae6c0457a1335f192e87d5b3b04623b6c04f499d7f98ec880bebb7bef0724fcbafb2ea3d4bd9745410bca5e216973bff95ba5ee8d8fa16daa14e4
@@ -19,15 +19,15 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
22
+ ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
23
23
 
24
24
  steps:
25
- - uses: actions/checkout@v2
25
+ - uses: actions/checkout@v3
26
26
  - name: Set up Ruby
27
27
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
28
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
29
  # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
30
+ uses: ruby/setup-ruby@v1
31
31
  with:
32
32
  ruby-version: ${{ matrix.ruby-version }}
33
33
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
@@ -56,7 +56,17 @@ class Parser
56
56
  if c[:proc]
57
57
  # clone string to avoid changing it via in-place methods used in Procs
58
58
  work_string = @string.clone
59
- c[:proc].call(work_string, c[:arg])
59
+
60
+ # using a begin/rescue to catch dates that Date.parse errors on
61
+ begin
62
+ c[:proc].call(work_string, c[:arg])
63
+
64
+ # ArgumentError for pre-2.7.0 DateTime errors,
65
+ # Date::Error for 2.7.0 and later
66
+ rescue ArgumentError || Date::Error
67
+ @dates = { :original_string => @string, :index_dates => [], :keydate => nil, :keydate_z => nil, :date_start => nil, :date_end => nil,
68
+ :date_start_full => nil, :date_end_full => nil, :inclusive_range => nil, :certainty => nil }
69
+ end
60
70
  end
61
71
  break
62
72
  end
@@ -1,3 +1,3 @@
1
1
  module Timetwister
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/spec/dates_spec.rb CHANGED
@@ -46,7 +46,6 @@ describe Timetwister do
46
46
  end
47
47
 
48
48
  it "parses ranges of full dates" do
49
-
50
49
  forms = ["July 4 1776 - March 1 1789", "4 July 1776 - 1 March 1789", "1776 July 4 - 1789 March 1", "1776 4 July - 1789 1 March", "1776 4 July to 1789 1 March"]
51
50
  forms.each do |f|
52
51
  date = Timetwister.parse(f)
@@ -572,6 +571,62 @@ describe Timetwister do
572
571
  end
573
572
  end
574
573
 
574
+ it "DOES NOT parse nonexistent dates" do
575
+ date = Timetwister.parse('1776 September 31')
576
+ expect(date[0][:date_start]).to eq(nil)
577
+ expect(date[0][:date_start_full]).to eq(nil)
578
+ expect(date[0][:date_end]).to eq(nil)
579
+ expect(date[0][:date_end_full]).to eq(nil)
580
+ expect(date[0][:inclusive_range]).to eq(nil)
581
+ expect(date[0][:index_dates]).to eq([])
582
+ expect(date[0][:test_data]).to eq(nil)
583
+
584
+ date = Timetwister.parse('1776-11-31')
585
+ expect(date[0][:date_start]).to eq(nil)
586
+ expect(date[0][:date_start_full]).to eq(nil)
587
+ expect(date[0][:date_end]).to eq(nil)
588
+ expect(date[0][:date_end_full]).to eq(nil)
589
+ expect(date[0][:inclusive_range]).to eq(nil)
590
+ expect(date[0][:index_dates]).to eq([])
591
+ expect(date[0][:test_data]).to eq(nil)
592
+
593
+ date = Timetwister.parse('1776-11-00')
594
+ expect(date[0][:date_start]).to eq(nil)
595
+ expect(date[0][:date_start_full]).to eq(nil)
596
+ expect(date[0][:date_end]).to eq(nil)
597
+ expect(date[0][:date_end_full]).to eq(nil)
598
+ expect(date[0][:inclusive_range]).to eq(nil)
599
+ expect(date[0][:index_dates]).to eq([])
600
+ expect(date[0][:test_data]).to eq(nil)
601
+
602
+ date = Timetwister.parse('1776 whatever 31')
603
+ expect(date[0][:date_start]).to eq(nil)
604
+ expect(date[0][:date_start_full]).to eq(nil)
605
+ expect(date[0][:date_end]).to eq(nil)
606
+ expect(date[0][:date_end_full]).to eq(nil)
607
+ expect(date[0][:inclusive_range]).to eq(nil)
608
+ expect(date[0][:index_dates]).to eq([])
609
+ expect(date[0][:test_data]).to eq(nil)
610
+
611
+ date = Timetwister.parse('1776 sometime 72 - december 42 1999')
612
+ expect(date[0][:date_start]).to eq(nil)
613
+ expect(date[0][:date_start_full]).to eq(nil)
614
+ expect(date[0][:date_end]).to eq(nil)
615
+ expect(date[0][:date_end_full]).to eq(nil)
616
+ expect(date[0][:inclusive_range]).to eq(nil)
617
+ expect(date[0][:index_dates]).to eq([])
618
+ expect(date[0][:test_data]).to eq(nil)
619
+
620
+ date = Timetwister.parse('just absolute garbage')
621
+ expect(date[0][:date_start]).to eq(nil)
622
+ expect(date[0][:date_start_full]).to eq(nil)
623
+ expect(date[0][:date_end]).to eq(nil)
624
+ expect(date[0][:date_end_full]).to eq(nil)
625
+ expect(date[0][:inclusive_range]).to eq(nil)
626
+ expect(date[0][:index_dates]).to eq([])
627
+ expect(date[0][:test_data]).to eq(nil)
628
+ end
629
+
575
630
  it "parses lists of years" do
576
631
  date = Timetwister.parse("1776, 1789, 1812")
577
632
  expect(date[0][:date_start]).to eq("1776")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetwister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Duryee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler