Module:Nirmaljoshi/sandbox explained

local p = ; --This function converts nepali date to english date-- See MOS for date format(Wikipedia:Manual of Style/Dates and numbers)--The output can be checked by using following code in article page/template page---->Retruns full date---->Retruns years e.g. 2007-2008

function p.returnEnglishDate(frame) -- add a function to p local n_year = tonumber(frame.args.nepaliYear) local n_month = tonumber(frame.args.nepaliMonth) local n_day = tonumber(frame.args.nepaliDay) --define variables to hold converted date local e_date -- when nepali day or month is missing, retrun the year only -- or when date is out of range(2000-2089 BS), return year only -- or when there are error in days or months, return year only local e_year1 local e_year2 if (n_month

nil or n_month>12 or n_day

nil or n_day>32 or n_year < 2000 or n_year > 2089) then e_year1=n_year-57 e_year2=n_year-56 e_date=n_year .. ' BS ('.. e_year1 .. '-' .. e_year2 .. ')' return e_date end -- when both month and day is given, and year is in range and return compelte date --- calculate e_date=p.nep_to_eng(n_year, n_month, n_day) return e_dateend

function p.nep_to_eng(yy, mm, dd) local def_nyy = 2000 local def_nmm = 1 local def_ndd = 1 -- equivalent nepali dates -- initializate local total_nDays = 0 local i = 0 local k = 1 local numDay = 0 -- array for nepali calendar local bs= --declear array to hold bikram sambat calendar and fill the array bs[1]= bs[2]= bs[3]= bs[4]= bs[5]= bs[6]= bs[7]= bs[8]= bs[9]= bs[10]= bs[11]= bs[12]= bs[13]= bs[14]= bs[15]= bs[16]= bs[17]= bs[18]= bs[19]= bs[20]= bs[21]= bs[22]= bs[23]= bs[24]= bs[25]= bs[26]= bs[27]= bs[28]= bs[29]= bs[30]= bs[31]= bs[32]= bs[33]= bs[34]= bs[35]= bs[36]= bs[37]= bs[38]= bs[39]= bs[40]= bs[41]= bs[42]= bs[43]= bs[44]= bs[45]= bs[46]= bs[47]= bs[48]= bs[49]= bs[50]= bs[51]= bs[52]= bs[53]= bs[54]= bs[55]= bs[56]= bs[57]= bs[58]= bs[59]= bs[60]= bs[61]= bs[62]= bs[63]= bs[64]= bs[65]= bs[66]= bs[67]= bs[68]= bs[69]= bs[70]= bs[71]= bs[72]= bs[73]= bs[74]= bs[75]= bs[76]= bs[77]= bs[78]= bs[79]= bs[80]= bs[81]= bs[82]= bs[83]= bs[84]= bs[85]= bs[86]= bs[87]= bs[88]= bs[89]= bs[90]= bs[91]=

-- if additional calander becomes available, please put here --count total days for upto given year for i = 0, yy - def_nyy-1 do for j = 2, 13 do total_nDays = total_nDays + bs[k][j] end k = k + 1 end --count and add days for the months for j = 2, mm - 1+1 do total_nDays = total_nDays + bs[k][j] end --count and add total days within the month total_nDays = total_nDays + dd aaa= total_nDays --

---calculation of equivalent english date-- --

local def_eyy = 1943 local def_emm = 4 local def_edd = 14 - 1 -- 1 Baisakh 2000 BS=14 April, 1943 AD -- array for english calendar local month = --normal english year local lmonth = --leap english year local a = 0 -- to hold days of a month during calculation local total_eDays = def_edd local day = 4 - 1 local m = def_emm local y = def_eyy while (total_nDays ~= 0) do if (p.is_leap_year(y)) then a = lmonth[m] else a = month[m] end total_eDays = total_eDays + 1 day = day + 1 if (total_eDays > a) then m = m + 1 total_eDays = 1 if (m > 12) then y = y + 1 m = 1 end end if (day > 7) then day = 1 end total_nDays = total_nDays - 1 end numDay = day local monthNameEnglish= local monthNameNepali= returnVal=total_eDays..' '..monthNameEnglish[m]..' '..y..' ('.. dd ..' '.. monthNameNepali[mm]..' '.. yy..' BS)' return returnValend

function p.is_leap_year(year) --this function checks if the given year is a leap year or not local returnVal local a = tonumber(year) if math.fmod(a,100)

0 then if math.fmod(a,400)

0 then returnVal = true else returnVal = false end else if math.fmod(a,4)