class Tareek::Dates

Constants

DAYS_IN_A_MONTH
MONTHS

Public Class Methods

convert_to_date(date) click to toggle source
# File lib/tareek.rb, line 66
def convert_to_date(date)
  (date.kind_of? Date) ? date : Date.parse(date)
end
date_of_next(day) click to toggle source
# File lib/tareek.rb, line 36
def date_of_next(day)
  date  = convert_to_date(day)
  delta = date > Date.today ? 0 : 7
  date + delta
end
day_middle_of_next_month_date(year, month) click to toggle source
# File lib/tareek.rb, line 24
def day_middle_of_next_month_date(year, month)
  day_on(get_middle_of_next_month_date(year, month))
end
day_middle_of_past_month_date(year, month) click to toggle source
# File lib/tareek.rb, line 28
def day_middle_of_past_month_date(year, month)
  day_on(get_middle_of_past_month_date(year, month))
end
day_on(date) click to toggle source
# File lib/tareek.rb, line 42
def day_on(date)
  convert_to_date(date).strftime("%A")
end
days_in_a_month_of(month, year) click to toggle source
# File lib/tareek.rb, line 86
def days_in_a_month_of(month, year)
 month = MONTHS.index(month)
 return 29 if(month == 2 && Date.leap?(year.to_i))
 DAYS_IN_A_MONTH[month] 
end
feb_month_of_28_days_for?(year) click to toggle source
# File lib/tareek.rb, line 92
def feb_month_of_28_days_for?(year)
 days_in_a_month_of("Feb", year.to_i) == 28
end
get_middle_of_next_month_date(year, month) click to toggle source
# File lib/tareek.rb, line 16
def get_middle_of_next_month_date(year, month)
  (parse_date(month,year) + 45 * 24 * 60 * 60).to_date
end
get_middle_of_past_month_date(year, month) click to toggle source
# File lib/tareek.rb, line 20
def get_middle_of_past_month_date(year, month)
  (parse_date(month,year) - 15 * 24 * 60 * 60).to_date
end
humanize_with_day(date) click to toggle source
# File lib/tareek.rb, line 50
def humanize_with_day(date)
  convert_to_date(date).strftime('%d-%b-%y')
end
humanize_with_day_and_full_year(date) click to toggle source
# File lib/tareek.rb, line 54
def humanize_with_day_and_full_year(date)
  convert_to_date(date).strftime('%d %b %Y')
end
humanize_without_day(date) click to toggle source
# File lib/tareek.rb, line 46
def humanize_without_day(date)
  convert_to_date(date).strftime('%b %y')
end
omniture_formatted_with_time(date) click to toggle source
# File lib/tareek.rb, line 62
def omniture_formatted_with_time(date)
  convert_to_date(date).strftime('%m/%d/%Y %I:%M:%S %p')
end
parse_date(month,year) click to toggle source
# File lib/tareek.rb, line 32
def parse_date(month,year)
  Time.parse("1-#{month}-#{year} 0:1 UTC")
end
time_at_day(date) click to toggle source
# File lib/tareek.rb, line 58
def time_at_day(date)
  convert_to_date(date).strftime('%I:%M %p')
end
today_date_in_dd_mm_yy_format() click to toggle source
# File lib/tareek.rb, line 70
def today_date_in_dd_mm_yy_format
 Time.now.strftime('%d-%m-%Y')
end
today_date_in_mm_dd_yy_format() click to toggle source
# File lib/tareek.rb, line 74
def today_date_in_mm_dd_yy_format
 Time.now.strftime('%m-%d-%Y')
end
weekday?(day) click to toggle source
# File lib/tareek.rb, line 82
def weekday?(day)
 !(weekend?(day))
end
weekend?(day) click to toggle source
# File lib/tareek.rb, line 78
def weekend?(day)
 [0,6].include?(convert_to_date(day).wday) 
end