pennmarc 1.0.22 → 1.0.23

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: d9222d0bfd9ca8704ec91ef01d1e27ce90711506b648f2d0006fc2270dd6d82d
4
- data.tar.gz: c250833003d00f8d2b12a6c8e4043d9eadcdaaa33bba8ae70468e3210cdb1780
3
+ metadata.gz: 7c906223a9bcdb4ba4792ac50462b8c57e41e71fa1e83cd8e63018d360ebfe0a
4
+ data.tar.gz: 5d1a420e07734370c95ab1f83d3c519a1d75a7faaa807f1d3ee436808779c586
5
5
  SHA512:
6
- metadata.gz: b9a1c42746b7d1448df78aad4528c1bf20731feeadc073e4937d0722bcfbed6ec42c104ae2d1241cf31830e6c7e50b0b6ab125140cf9d232511530a7b82861ef
7
- data.tar.gz: c143ab4e9056f6a62a06a90d01938d70a6b7088704930e0dcf402c392954c08164a9821f39f35d03d07023393ca1d64844fa56d16522155ec55ca4a9a35fcf9b
6
+ metadata.gz: 32e47c254c1a2bb78e861003c864bdbc22833439cff22ebe00148df081c74fed85f60e2f743b5ea65065e5db576e3a304710b1a68b2cdc1e08a1a5f7808e5fc3
7
+ data.tar.gz: 6051840a95afdcb41640abf2c42ce699deddc93970c5d117cb445474d4f5998996ee05651ec1e59da3e45886e00f6c058b881b1bf9103de92deb5cf6d868ce80
@@ -8,14 +8,14 @@ module PennMARC
8
8
  # Publication date is a four-digit year found in position 7-10 and may contain 'u' characters to represent
9
9
  # partially known dates. We replace any occurrences of 'u' with '0' before converting to DateTime object.
10
10
  # @param [MARC::Record] record
11
- # @return [DateTime, nil] The publication date, or nil if date found in record is invalid
11
+ # @return [Time, nil] The publication date, or nil if date found in record is invalid
12
12
  def publication(record)
13
13
  record.fields('008').filter_map { |field|
14
14
  four_digit_year = sanitize_partially_known_date(field.value[7, 4], '0')
15
15
 
16
16
  next if four_digit_year.blank?
17
17
 
18
- DateTime.new(four_digit_year.to_i)
18
+ Time.new(four_digit_year.to_i)
19
19
  }.first
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ module PennMARC
23
23
  # {PennMARC::Enriched} maps enriched marc fields and subfields created during Alma publishing. The enriched
24
24
  # metadata provided by the Alma API does not include the date created value, so we can't work with that here.
25
25
  # @param [MARC::Record] record
26
- # @return [DateTime, nil] The date added, or nil if date found in record is invalid
26
+ # @return [Time, nil] The date added, or nil if date found in record is invalid
27
27
  def added(record)
28
28
  record.fields(Enriched::Pub::ITEM_TAG).flat_map { |field|
29
29
  subfield_values(field, Enriched::Pub::ITEM_DATE_CREATED).filter_map do |date_added|
@@ -34,9 +34,10 @@ module PennMARC
34
34
 
35
35
  format = date_added.size == 10 ? '%Y-%m-%d' : '%Y-%m-%d %H:%M:%S'
36
36
 
37
- DateTime.strptime(date_added, format)
37
+ Time.strptime(date_added, format)
38
38
  rescue StandardError => e
39
- puts "Error parsing date in date added subfield: #{date_added} - #{e}"
39
+ puts 'Error parsing date in date added subfield. ' \
40
+ "mmsid: #{Identifier.mmsid(record)}, value: #{date_added}, error: #{e}"
40
41
  nil
41
42
  end
42
43
  }.max
@@ -46,7 +47,7 @@ module PennMARC
46
47
  # Date last updated is a sixteen character String recorded in
47
48
  # {https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601} format.
48
49
  # @param [MARC::Record] record
49
- # @return [DateTime, nil] The date last updated, or nil if date found in record is invalid
50
+ # @return [Time, nil] The date last updated, or nil if date found in record is invalid
50
51
  def last_updated(record)
51
52
  record.fields('005').filter_map { |field|
52
53
  begin
@@ -56,9 +57,10 @@ module PennMARC
56
57
 
57
58
  next if date_time_string.start_with?('0000')
58
59
 
59
- DateTime.iso8601(date_time_string).to_datetime
60
- rescue ArgumentError => e
61
- puts "Error parsing last updated date: #{date_time_string} - #{e}"
60
+ Time.strptime(date_time_string, '%Y%m%d%H%M%S.%N')
61
+ rescue StandardError => e
62
+ puts 'Error parsing last updated date. ' \
63
+ "mmsid: #{Identifier.mmsid(record)}, value: #{date_time_string}, error: #{e}"
62
64
  nil
63
65
  end
64
66
  }.first
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.0.22'
4
+ VERSION = '1.0.23'
5
5
  end
@@ -10,7 +10,7 @@ describe 'PennMARC::Date' do
10
10
  let(:fields) { [marc_control_field(tag: '008', value: '130827s2010 nyu o 000 1 eng d')] }
11
11
 
12
12
  it 'returns publication date' do
13
- expect(helper.publication(record)).to eq(DateTime.new(2010))
13
+ expect(helper.publication(record)).to eq(Time.new(2010))
14
14
  end
15
15
 
16
16
  it 'returns a year value' do
@@ -33,7 +33,7 @@ describe 'PennMARC::Date' do
33
33
  end
34
34
 
35
35
  it 'returns only the expected date_added value' do
36
- expect(helper.added(record)).to eq DateTime.strptime('2023-10-19', '%Y-%m-%d')
36
+ expect(helper.added(record)).to eq Time.strptime('2023-10-19', '%Y-%m-%d')
37
37
  end
38
38
 
39
39
  it 'does not output any warning to STDOUT' do
@@ -47,7 +47,7 @@ describe 'PennMARC::Date' do
47
47
  let(:fields) { [marc_field(tag: 'itm', subfields: { q: '2023-06-28' })] }
48
48
 
49
49
  it 'returns expected value' do
50
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-28', '%Y-%m-%d'))
50
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-28', '%Y-%m-%d'))
51
51
  end
52
52
 
53
53
  it 'returns a year value' do
@@ -59,7 +59,7 @@ describe 'PennMARC::Date' do
59
59
  let(:fields) { [marc_field(tag: 'itm', subfields: { q: '2023-06-29 11:04:30:10' })] }
60
60
 
61
61
  it 'returns expected value' do
62
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-29 11:04:30:10', '%Y-%m-%d %H:%M:%S'))
62
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-29 11:04:30:10', '%Y-%m-%d %H:%M:%S'))
63
63
  end
64
64
 
65
65
  it 'returns a year value' do
@@ -74,12 +74,15 @@ describe 'PennMARC::Date' do
74
74
  end
75
75
 
76
76
  it 'returns most recent date' do
77
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-29', '%Y-%m-%d'))
77
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-29', '%Y-%m-%d'))
78
78
  end
79
79
  end
80
80
 
81
81
  context 'with invalid date' do
82
- let(:fields) { [marc_field(tag: 'itm', subfields: { q: 'invalid date' })] }
82
+ let(:fields) do
83
+ [marc_control_field(tag: '001', value: 'mmsid'),
84
+ marc_field(tag: 'itm', subfields: { q: 'invalid date' })]
85
+ end
83
86
 
84
87
  it 'returns nil' do
85
88
  expect(helper.added(record)).to be_nil
@@ -88,7 +91,8 @@ describe 'PennMARC::Date' do
88
91
  it 'outputs error message' do
89
92
  expect {
90
93
  helper.added(record)
91
- }.to output("Error parsing date in date added subfield: invalid date - invalid date\n").to_stdout
94
+ }.to output('Error parsing date in date added subfield. mmsid: mmsid, value: invalid date, ' \
95
+ "error: invalid date or strptime format - `invalid date' `%Y-%m-%d %H:%M:%S'\n").to_stdout
92
96
  end
93
97
  end
94
98
  end
@@ -97,7 +101,7 @@ describe 'PennMARC::Date' do
97
101
  let(:fields) { [marc_field(tag: '005', subfields: { q: '20230213163851.1' })] }
98
102
 
99
103
  it 'returns date last updated' do
100
- expect(helper.last_updated(record)).to eq(DateTime.iso8601('20230213163851.1').to_datetime)
104
+ expect(helper.last_updated(record)).to eq(Time.strptime('20230213163851.1', '%Y%m%d%H%M%S.%N'))
101
105
  end
102
106
 
103
107
  it 'returns year value' do
@@ -105,7 +109,10 @@ describe 'PennMARC::Date' do
105
109
  end
106
110
 
107
111
  context 'with invalid date' do
108
- let(:fields) { [marc_field(tag: '005', subfields: { q: 'invalid date' })] }
112
+ let(:fields) do
113
+ [marc_control_field(tag: '001', value: 'mmsid'),
114
+ marc_field(tag: '005', subfields: { q: 'invalid date' })]
115
+ end
109
116
 
110
117
  it 'returns nil' do
111
118
  expect(helper.last_updated(record)).to be_nil
@@ -114,7 +121,8 @@ describe 'PennMARC::Date' do
114
121
  it 'outputs error message' do
115
122
  expect {
116
123
  helper.last_updated(record)
117
- }.to output("Error parsing last updated date: invalid date - invalid date\n").to_stdout
124
+ }.to output('Error parsing last updated date. mmsid: mmsid, value: invalid date, ' \
125
+ "error: invalid date or strptime format - `invalid date' `%Y%m%d%H%M%S.%N'\n").to_stdout
118
126
  end
119
127
  end
120
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pennmarc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.22
4
+ version: 1.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kanning
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-05-24 00:00:00.000000000 Z
13
+ date: 2024-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport