Runt::TExprUtils

Utility methods common to some expressions

Public Instance Methods

days_left_in_month(date) click to toggle source
# File lib/runt/temporalexpression.rb, line 247
def days_left_in_month(date)
  return max_day_of_month(date) - date.day
end
max_day_of_month(date) click to toggle source
# File lib/runt/temporalexpression.rb, line 251
def max_day_of_month(date)
  # Contributed by Justin Cunningham who took it verbatim from the Rails 
  # ActiveSupport::CoreExtensions::Time::Calculations::ClassMethods module 
  # days_in_month method. 
  month = date.month
  year = date.year
  if month == 2
    !year.nil? && 
      (year % 4 == 0) && 
      ((year % 100 != 0) || 
       (year % 400 == 0)) ?  29 : 28
  elsif month <= 7
    month % 2 == 0 ? 30 : 31
  else
    month % 2 == 0 ? 31 : 30
  end
end
week_from_end_matches?(index,date) click to toggle source
# File lib/runt/temporalexpression.rb, line 281
def week_from_end_matches?(index,date)
  n = days_left_in_month(date) + 1
  week_in_month(n)==index.abs
end
week_from_start_matches?(index,date) click to toggle source
# File lib/runt/temporalexpression.rb, line 277
def week_from_start_matches?(index,date)
  week_in_month(date.day)==index
end
week_in_month(day_in_month) click to toggle source
# File lib/runt/temporalexpression.rb, line 243
def week_in_month(day_in_month)
  ((day_in_month - 1) / 7) + 1
end
week_matches?(index,date) click to toggle source
# File lib/runt/temporalexpression.rb, line 269
def week_matches?(index,date)
  if(index > 0)
    return week_from_start_matches?(index,date)
  else
    return week_from_end_matches?(index,date)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.