# encoding: UTF-8 require 'spec_helper' describe "Date methods (searchworks.rb)" do before(:all) do @smods_rec = Stanford::Mods::Record.new @ns_decl = "xmlns='#{Mods::MODS_NS}'" end context "pub_dates" do it "should choose the first date" do m = " 1904 1904 1906 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_dates.should == ['1906','1904','1904'] end end context "pub_date" do it "should choose the first date" do m = " 1904 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1904' end it "should parse a date" do m = " Aug. 3rd, 1886 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1886' end it "should remove question marks and brackets" do m = " Aug. 3rd, [18]86? " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1886' end it 'should handle an s after the decade' do m = " early 1890s " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1890' end it 'should choose a date ending with CE if there are multiple dates' do m = "7192 AM (li-Adam) / 1684 CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1684' end it 'should handle hyphenated range dates' do m = "1282 AH / 1865-6 CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1865' end it 'should work with multiple 4 digit dates' do m = "Text dated June 4, 1594; miniatures added by 1596" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1594' end it 'should work on 3 digit BC dates' do m = "300 B.C." @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_year.should == '-700' @smods_rec.pub_date.should == '-700' @smods_rec.pub_date_sort.should =='-700' @smods_rec.pub_date_facet.should == '300 B.C.' end it 'should handle century based dates' do m = "13th century AH / 19th CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date_facet.should == '19th century' @smods_rec.pub_date_sort.should =='1800' @smods_rec.pub_date.should == '18--' end it 'should handle multiple CE dates' do m = "6 Dhu al-Hijjah 923 AH / 1517 CE -- 7 Rabi I 924 AH / 1518 CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '1517' @smods_rec.pub_date_sort.should =='1517' @smods_rec.pub_date_facet.should == '1517' end it 'should handle this case from walters' do m = "Late 14th or early 15th century CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '14--' @smods_rec.pub_date_sort.should =='1400' @smods_rec.pub_date_facet.should == '15th century' end it 'should work on 3 digit dates' do m = "966 CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '966' @smods_rec.pub_date_sort.should =='0966' @smods_rec.pub_date_facet.should == '966' end it 'should work on 3 digit dates' do m = "3rd century AH / 9th CEmonographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date.should == '8--' @smods_rec.pub_date_sort.should =='0800' @smods_rec.pub_date_facet.should == '9th century' end it 'should use the dateIssued without marc encoding for pub_date_display and the one with marc encoding for indexing, sorting and faceting' do m = "[186-?]1860monographic" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) @smods_rec.pub_date_display.should == '[186-?]' @smods_rec.pub_date.should =='1860' @smods_rec.pub_date_sort.should =='1860' @smods_rec.pub_date_facet.should == '1860' end end # pub_date context "dates with u notation (198u, 19uu)" do context "single digit u notation (198u)" do before(:all) do m = " 198u 9999 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) end it "get_u_year recognizes notation" do dates = ["198u", "9999"] uDate = @smods_rec.get_u_year dates uDate.should eql("1980") end it 'pub_date: 198u = 1980' do @smods_rec.pub_date.should == '1980' end it "pub_date_sort: 198u = 1980" do @smods_rec.pub_date_sort.should =='1980' end it "pub_date_facet: 198u = 1980" do @smods_rec.pub_date_facet.should == '1980' end end context "double digit u notation (19uu)" do before(:all) do m = " 19uu 9999 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) end it "get_u_year recognizes notation" do dates = ["19uu", "9999"] uDate = @smods_rec.get_u_year dates uDate.should eql("19--") end it 'pub_date: 19uu = 19--' do @smods_rec.pub_date.should == '19--' end it "pub_date_sort: 19uu = 1900" do @smods_rec.pub_date_sort.should =='1900' end it "pub_date_facet: 19uu = 20th century" do @smods_rec.pub_date_facet.should == '20th century' end end end # u notation context 'pub_date_sort' do before :all do m = " Aug. 3rd, 1886 " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) end it 'should work on normal dates' do @smods_rec.stub(:pub_date).and_return('1945') @smods_rec.pub_date_sort.should == '1945' end it 'should work on 3 digit dates' do @smods_rec.stub(:pub_date).and_return('945') @smods_rec.pub_date_sort.should == '0945' end it 'should work on century dates' do @smods_rec.stub(:pub_date).and_return('16--') @smods_rec.pub_date_sort.should == '1600' end it 'should work on 3 digit century dates' do @smods_rec.stub(:pub_date).and_return('9--') @smods_rec.pub_date_sort.should == '0900' end end end