module BcaParser::TimeKeeper
Constants
- DAYS
- MAX_DAYS
- MONTHS
Public Class Methods
checkDateForBalance(start_date, start_month, end_date, end_month)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 26 def self.checkDateForBalance(start_date, start_month, end_date, end_month) start_day = TimeKeeper.makeDateFromString(start_date, start_month, Time.now.year) end_day = TimeKeeper.makeDateFromString(end_date, end_month, Time.now.year) if !compareDate(start_day, end_day) return false end if !nowAndPast?(start_day, end_day) return false end if !inRangeMaxDays?(start_day, end_day) return false else return true end end
checkDayMonth(day, month, year=nil)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 103 def self.checkDayMonth(day, month, year=nil) day = day.to_i month = month.to_i if !MONTHS.include?(month) return false end year ||= Time.now.year if checkLeapYear(year) if month == 2 total_days = 29 end else total_days = DAYS[month-1] end if day > 0 and day <= total_days return true else return false end end
checkLeapYear(year)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 61 def self.checkLeapYear(year) year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) ? true : false end
checkMonthForBalance(month)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 15 def self.checkMonthForBalance(month) month = month.to_i now_month = Time.now.month if month >= now_month or month < now_month - 2 false else true end end
compareDate(date1, date2)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 69 def self.compareDate(date1, date2) date2 >= date1 ? true : false end
getIndonesianMonth(month)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 73 def self.getIndonesianMonth(month) month = month.to_i case month when 1 'Januari' when 2 'Februari' when 3 'Maret' when 4 'April' when 5 'Mei' when 6 'Juni' when 7 'Juli' when 8 'Agustus' when 9 'September' when 10 'Oktober' when 11 'Nopember' when 12 'Desember' end end
inRangeMaxDays?(start_day, end_day)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 53 def self.inRangeMaxDays?(start_day, end_day) if end_day - start_day <= MAX_DAYS return true else return false end end
makeDateFromString(day, month, year)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 65 def self.makeDateFromString(day, month, year) date = Time.new(year.to_i, month.to_i, day.to_i) end
nowAndPast?(start_day, end_day)
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 44 def self.nowAndPast?(start_day, end_day) now = Time.now if start_day <= now && end_day <= now return true else return false end end
twoPreviousMonths()
click to toggle source
# File lib/bcaparser/time_keeper.rb, line 10 def self.twoPreviousMonths month = Time.new.month [month - 2, month - 1] end