Module:Sandbox/Ralvahkaset/amlich

-- Module:Sandbox/Ralvahkaset/amlich
-- Vietnamese Lunar Calendar (Âm Lịch) converter for Wikipedia
-- Converts Gregorian dates to Vietnamese lunar dates
-- Usage: {{#invoke:Sandbox/Ralvahkaset/amlich|main|year|month|day}}
-- Example: {{#invoke:Sandbox/Ralvahkaset/amlich|main|2025|7|25}} → "Ngày 1 Tháng Sáu (nhuận) Năm Ất Tỵ"

local utils = require('Module:Sandbox/Ralvahkaset/a utils')
local convert = require('Module:Sandbox/Ralvahkaset/a convert')
local format = require('Module:Sandbox/Ralvahkaset/a format')

local p = {}

-- Main function to be invoked from template
-- frame.args[1] = year (yyyy)
-- frame.args[2] = month (mm)  
-- frame.args[3] = day (dd)
function p.main(frame)
    local args = frame.args
    
    -- Get parameters
    local year = tonumber(args[1])
    local month = tonumber(args[2])
    local day = tonumber(args[3])
    
    -- Validate inputs
    if not year or not month or not day then
        return '<span class="error">Lỗi: Vui lòng nhập đầy đủ năm, tháng, ngày. ' ..
               'Cú pháp: {{#invoke:Sandbox/Ralvahkaset/amlich|main|năm|tháng|ngày}}</span>'
    end
    
    -- Validate date ranges
    if month < 1 or month > 12 then
        return '<span class="error">Lỗi: Tháng phải từ 1 đến 12</span>'
    end
    
    if day < 1 or day > 31 then
        return '<span class="error">Lỗi: Ngày phải từ 1 đến 31</span>'
    end
    
    -- Validate year range
    if year < 1583 then
        return '<span class="error">Lỗi: Năm phải từ 1583 trở đi</span>'
    end
    
    -- Default timezone for Vietnam (UTC+7)
    local timeZone = 7.0
    
    -- Convert solar to lunar
    local lunarYear, lunarMonth, lunarDay, lunarLeap, juliusDayNumber = 
        convert.ConvertSolar2Lunar(year, month, day, timeZone)
    
    -- Format the result
    local result = format.FormatLunarDate(lunarYear, lunarMonth, lunarDay, lunarLeap, juliusDayNumber)
    
    return result
end

-- Alternative function with full Can Chi information
-- Usage: {{#invoke:Sandbox/Ralvahkaset/amlich|full|year|month|day}}
function p.full(frame)
    local args = frame.args
    
    -- Get parameters
    local year = tonumber(args[1])
    local month = tonumber(args[2])
    local day = tonumber(args[3])
    
    -- Validate inputs
    if not year or not month or not day then
        return '<span class="error">Lỗi: Vui lòng nhập đầy đủ năm, tháng, ngày. ' ..
               'Cú pháp: {{#invoke:Sandbox/Ralvahkaset/amlich|full|năm|tháng|ngày}}</span>'
    end
    
    -- Validate date ranges
    if month < 1 or month > 12 then
        return '<span class="error">Lỗi: Tháng phải từ 1 đến 12</span>'
    end
    
    if day < 1 or day > 31 then
        return '<span class="error">Lỗi: Ngày phải từ 1 đến 31</span>'
    end
    
    -- Validate year range
    if year < 1583 then
        return '<span class="error">Lỗi: Năm phải từ 1583 trở đi</span>'
    end
    
    -- Default timezone for Vietnam (UTC+7)
    local timeZone = 7.0
    
    -- Convert solar to lunar
    local lunarYear, lunarMonth, lunarDay, lunarLeap, juliusDayNumber = 
        convert.ConvertSolar2Lunar(year, month, day, timeZone)
    
    -- Format the result with full Can Chi
    local result = format.FormatFullLunarDate(lunarYear, lunarMonth, lunarDay, lunarLeap, juliusDayNumber)
    
    return result
end

-- Function to get leap month of a lunar year
-- Usage: {{#invoke:Sandbox/Ralvahkaset/amlich|leapmonth|lunarYear}}
function p.leapmonth(frame)
    local args = frame.args
    local lunarYear = tonumber(args[1])
    
    if not lunarYear then
        return '<span class="error">Lỗi: Vui lòng nhập năm âm lịch</span>'
    end
    
    if lunarYear < 1583 then
        return '<span class="error">Lỗi: Năm phải từ 1583 trở đi</span>'
    end
    
    local timeZone = 7.0
    local leapMonth = convert.GetLeapMonth(lunarYear, timeZone)
    
    if leapMonth == 0 then
        return 'Năm ' .. lunarYear .. ' không có tháng nhuận'
    else
        local monthName = format.GetMonthName(leapMonth)
        return 'Năm ' .. lunarYear .. ' có tháng nhuận là tháng ' .. monthName
    end
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.