This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christof Dorner
committed
May 3, 2012
1 parent
1fd8a81
commit ac17ec8
Showing
4 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
module EPUBInfo | ||
module Utils | ||
DC_NAMESPACE = { 'dc' => 'http://purl.org/dc/elements/1.1/' } | ||
|
||
def self.parse_iso_8601_date(date_str) | ||
case date_str.count('-') | ||
when 0 | ||
Date.strptime(date_str, '%Y') | ||
when 1 | ||
Date.strptime(date_str, '%Y-%m') | ||
when 2 | ||
Date.strptime(date_str, '%Y-%m-%d') | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe EPUBInfo::Utils do | ||
describe '#parse_iso_8601_date' do | ||
it 'should parse only year' do | ||
EPUBInfo::Utils.parse_iso_8601_date('2012').should == Date.new(2012, 1, 1) | ||
end | ||
|
||
it 'should parse only year, and month' do | ||
EPUBInfo::Utils.parse_iso_8601_date('2012-02').should == Date.new(2012, 2, 1) | ||
end | ||
|
||
it 'should parse year, month, and day' do | ||
EPUBInfo::Utils.parse_iso_8601_date('2012-02-03').should == Date.new(2012, 2, 3) | ||
end | ||
end | ||
end | ||
|