Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22f2aa13f586483

Jump to content

Module:Vikram Samvat

From Wikipedia, the free encyclopedia
--------------------------------------------------------------------------------
-- Module:Vikram Samvat
-- Version 0.2
-- Vikram Samvat calendar for MediaWiki
--------------------------------------------------------------------------------

local p = {}

--------------------------------------------------------------------------------
--Month names
--------------------------------------------------------------------------------

local months = {

    [1] = {
        en = "Baisakh",
        ne = "बैशाख"
    },

    [2] = {
        en = "Jestha",
        ne = "जेष्ठ"
    },

    [3] = {
        en = "Ashadh",
        ne = "अषाढ"
    },

    [4] = {
        en = "Shrawan",
        ne = "श्रावण"
    },

    [5] = {
        en = "Bhadra",
        ne = "भाद्र"
    },

    [6] = {
        en = "Ashwin",
        ne = "आश्विन"
    },

    [7] = {
        en = "Kartik",
        ne = "कार्तिक"
    },

    [8] = {
        en = "Mangsir",
        ne = "मंसिर"
    },

    [9] = {
        en = "Poush",
        ne = "पौष"
    },

    [10] = {
        en = "Magh",
        ne = "माघ"
    },

    [11] = {
        en = "Falgun",
        ne = "फाल्गुण"
    },

    [12] = {
        en = "Chaitra",
        ne = "चैत्र"
    }
	
}
local bsData = {
	[2080] = {
		31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30
	},
	[2081] = {
		31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31
	},
	[2082] = {
		31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30
	},
	[2083] = {
		31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30
	},
	[2084] = {
		31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30
	},
	[2085] = {
		31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30
	}
}
--------------------------------------------------------------------------------
-- Returns the number of days in a BS month
--------------------------------------------------------------------------------
local function getMonthLength(year, month)

    if bsData[year] and bsData[year][month] then
        return bsData[year][month]
    end

    return nil

end
--------------------------------------------------------------------------------
-- Reference date (Epoch)
--------------------------------------------------------------------------------

local epoch = {
    adYear = 2023,
    adMonth = 4,
    adDay = 14,

    bsYear = 2080,
    bsMonth = 1,
    bsDay = 1
}
--------------------------------------------------------------------------------
-- Returns true if Gregorian year is a leap year
--------------------------------------------------------------------------------

local function isLeapYear(year)

    return (year % 4 == 0 and year % 100 ~= 0)
        or (year % 400 == 0)

end
--------------------------------------------------------------------------------
-- Gregorian month lengths
--------------------------------------------------------------------------------

local gregorianMonthLengths = {
    31, -- January
    28, -- February
    31, -- March
    30, -- April
    31, -- May
    30, -- June
    31, -- July
    31, -- August
    30, -- September
    31, -- October
    30, -- November
    31  -- December
}
--------------------------------------------------------------------------------
-- Returns the number of days in a Gregorian month
--------------------------------------------------------------------------------

local function getGregorianMonthLength(year, month)

    if month == 2 and isLeapYear(year) then
        return 29
    end

    return gregorianMonthLengths[month]

end
--------------------------------------------------------------------------------
-- Returns the number of days since the epoch (14 April 2023)
--------------------------------------------------------------------------------

local function daysSinceEpoch(year, month, day)

    local days = 0

    -- Count complete years
    for y = epoch.adYear, year - 1 do
        if isLeapYear(y) then
            days = days + 366
        else
            days = days + 365
        end
    end

    -- Count complete months
    for m = 1, month - 1 do
        days = days + gregorianMonthLengths[m]

        if m == 2 and isLeapYear(year) then
            days = days + 1
        end
    end

    -- Count days
    days = days + day

    -- Remove days before the epoch (14 April)
    if year == epoch.adYear then
        days = days - 104
    end

    return days

end
--------------------------------------------------------------------------------
-- Returns month name
--------------------------------------------------------------------------------

function p.month(frame)

    local n = tonumber(frame.args[1]) or 1
    local lang = frame.args.lang or "en"

    if months[n] then
        return months[n][lang] or months[n]["en"]
    end

    return "Unknown"

end
--------------------------------------------------------------------------------
-- Test function
--------------------------------------------------------------------------------

function p.test()

    return "Module loaded successfully."

end

return p