Skip to content

Commit

Permalink
Please drop your db: adding day of week as number.
Browse files Browse the repository at this point in the history
  • Loading branch information
thbar committed Jul 1, 2011
1 parent ed40713 commit fc0871f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions etl/migrations/002_create_date_dimension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def self.up
t.string :date
t.string :month
t.string :day_of_week
t.integer :day_of_week_as_number
t.string :year
t.string :year_and_month
t.date :sql_date_stamp
Expand Down
1 change: 1 addition & 0 deletions lib/date_dimension_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def build
record[:date] = date.strftime("%Y-%m-%d")
record[:month] = Date::MONTHNAMES[date.month].downcase
record[:day_of_week] = Date::DAYNAMES[date.wday].downcase
record[:day_of_week_as_number] = date.wday
record[:year] = date.year.to_s
record[:year_and_month] = record[:year] + "-" + date.month.to_s.rjust(2,'0')
record[:sql_date_stamp] = date
Expand Down
4 changes: 4 additions & 0 deletions spec/date_dimension_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def day(from, key=nil)
days('2007-12-01', '2007-12-07', :day_of_week).should eql(%w(saturday sunday monday tuesday wednesday thursday friday))
end

it "should return all the days of week as numbers starting by sunday as 0" do
days('2007-12-01', '2007-12-07', :day_of_week_as_number).should eql([6, 0, 1, 2, 3, 4, 5])
end

it "should return a sql_date_stamp" do
day('1991-1-1', :sql_date_stamp).should eql(Date.parse("1991-1-1"))
end
Expand Down

0 comments on commit fc0871f

Please sign in to comment.