Skip to content

Commit

Permalink
Merge pull request #9 from mhoogendoorn/date_yyyymmdd
Browse files Browse the repository at this point in the history
Recognize yyyymmdd date in Reckon::App#date_for.
  • Loading branch information
cantino committed Apr 15, 2013
2 parents cbb0f10 + 45285f6 commit 6d35ae4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 6d35ae4

Please sign in to comment.