Last active
August 29, 2015 14:01
sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nep_to_eng(*args) | |
date = args.map{|val| val.to_i} | |
date_error = date_valid(date, "np") | |
unless date_error.empty? | |
return date_error.collect{ |error| "Enter appropriate #{error}"} | |
else | |
en_start_year = 1943; en_start_month = 4; en_start_day = 14 - 1 | |
np_start_year = 2000; np_start_month = 1; np_start_day = 1 | |
day_of_week = 4 - 1 | |
en_days_in_month = [0,31,28,31,30,31,30,31,31,30,31,30,31] | |
leap_en_days_in_month = [0,31,29,31,30,31,30,31,31,30,31,30,31] | |
np_year_diff = args[2] - np_start_year - 1; np_total_days = 0 | |
(0..np_year_diff).each do |idx| | |
BsDate::BS_DATES[idx].shift | |
np_total_days += BsDate::BS_DATES[idx].inject(:+) | |
end | |
np_month_diff = args[1] - 1 | |
(1..np_month_diff).each{| idx| np_total_days += BsDate::BS_DATES[args[2] - np_start_year][idx] } | |
np_total_days += args[0] | |
day_in_month = en_start_day; month_number = en_start_month; year = en_start_year | |
while np_total_days != 0 | |
total_month_days = Date.leap?(year) ? leap_en_days_in_month[month_number] : en_days_in_month[month_number] | |
day_in_month += 1; day_of_week += 1 | |
if day_in_month > total_month_days | |
month_number += 1; day_in_month = 1 | |
(year += 1; month_number = 1) if month_number > 12 | |
end | |
day_of_week = 1 if day_of_week > 7 | |
np_total_days -= 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment