Skip to content

Instantly share code, notes, and snippets.

@mghaught
Created February 17, 2009 17:28
Show Gist options
  • Save mghaught/65845 to your computer and use it in GitHub Desktop.
Save mghaught/65845 to your computer and use it in GitHub Desktop.
def dates_this_year
first_day = @ctl_config.smc_connection.select_value("select min(created_at) from coupons")
first_day = first_day.nil? ? Date.today : Date.parse(first_day)
first_day = Date.new(first_day.year.to_i)
last_day = Date.new(Date.today.year + 1) - 1
dates = []
first_day.upto(last_day) do |day|
dates << {
:day_of_year => day.yday,
:day_of_month => day.mday,
:day_of_week => day.strftime('%a'),
:day_order => day.strftime("%u").to_i,
:week_of_year => "Week #{day.strftime('%W')}",
:week_order => day.strftime('%W'),
:month => day.strftime('%b'),
:month_order => day.month,
:quarter => ['Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2', 'Q3', 'Q3', 'Q3', 'Q4', 'Q4', 'Q4'][day.month - 1],
:year => day.year,
:sql_date_stamp => day
}
end
dates
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment