Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize yyyymmdd date in Reckon::App#date_for. #9

Merged
merged 1 commit into from
Apr 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/reckon/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def date_for(index)
value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})\d+\[\d+\:GMT\]$/ # chase format
value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\.(\d{2})\.(\d{4})$/ # german format
value = [$3, $2, $1].join("/") if value =~ /^(\d{2})\-(\d{2})\-(\d{4})$/ # nordea format
value = [$1, $2, $3].join("/") if value =~ /^(\d{4})(\d{2})(\d{2})/ # yyyymmdd format
begin
guess = Chronic.parse(value, :context => :past)
if guess.to_i < 953236800 && value =~ /\//
Expand Down
12 changes: 12 additions & 0 deletions spec/reckon/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@simple_csv = Reckon::App.new(:string => SIMPLE_CSV)
@german_date = Reckon::App.new(:string => GERMAN_DATE_EXAMPLE)
@danish_kroner_nordea = Reckon::App.new(:string => DANISH_KRONER_NORDEA_EXAMPLE, :csv_separator => ';', :comma_separates_cents => true)
@yyyymmdd_date = Reckon::App.new(:string => YYYYMMDD_DATE_EXAMPLE)
end

it "should be in testing mode" do
Expand Down Expand Up @@ -57,6 +58,7 @@
@two_money_columns.money_column_indices.should == [3, 4]
@harder_date_example_csv.money_column_indices.should == [1]
@danish_kroner_nordea.money_column_indices.should == [3]
@yyyymmdd_date.money_column_indices.should == [3]
end

it "should detect the date column" do
Expand All @@ -65,6 +67,7 @@
@two_money_columns.date_column_index.should == 0
@harder_date_example_csv.date_column_index.should == 0
@danish_kroner_nordea.date_column_index.should == 0
@yyyymmdd_date.date_column_index.should == 1
end

it "should consider all other columns to be description columns" do
Expand All @@ -73,6 +76,7 @@
@two_money_columns.description_column_indices.should == [1, 2, 5]
@harder_date_example_csv.description_column_indices.should == [2, 3, 4, 5, 6, 7]
@danish_kroner_nordea.description_column_indices.should == [1, 2, 4]
@yyyymmdd_date.description_column_indices.should == [0, 2]
end
end

Expand Down Expand Up @@ -103,6 +107,7 @@
@danish_kroner_nordea.money_for(3).should == -995.00
@danish_kroner_nordea.money_for(4).should == -3452.90
@danish_kroner_nordea.money_for(5).should == -655.00
@yyyymmdd_date.money_for(0).should == -123.45
end

it "should handle the comma_separates_cents option correctly" do
Expand Down Expand Up @@ -132,6 +137,9 @@
@danish_kroner_nordea.date_for(0).year.should == Time.parse("2012/11/16").year
@danish_kroner_nordea.date_for(0).month.should == Time.parse("2012/11/16").month
@danish_kroner_nordea.date_for(0).day.should == Time.parse("2012/11/16").day
@yyyymmdd_date.date_for(0).year.should == Time.parse("2012/12/31").year
@yyyymmdd_date.date_for(0).month.should == Time.parse("2012/12/31").month
@yyyymmdd_date.date_for(0).day.should == Time.parse("2012/12/31").day
end
end

Expand Down Expand Up @@ -240,4 +248,8 @@
27-08-2012;Dankort-nota MATAS - 20319 18230;27-08-2012;-655,00;21127,45
CSV

YYYYMMDD_DATE_EXAMPLE = (<<-CSV).strip
DEBIT,20121231,"ODESK***BAL-27DEC12 650-12345 CA 12/28",-123.45
CSV

end