vietnamese-date

Vietnamese date

Usage no npm install needed!

<script type="module">
  import vietnameseDate from 'https://cdn.skypack.dev/vietnamese-date';
</script>

README

Vietnamese lunar date - Âm lịch

class VietnameseDate {
    // Lunar Year - Năm âm lịch
    year: number;
    
    // Lunar Month - Tháng âm lich
    month: number;

    // Lunar Day of Month - Ngày âm lịch trong tháng
    day: number;

    // Is leap month - Cho biết có phải tháng nhuận không
    isLeapMonth: boolean;

    // Solar Date - Ngày dương lịch
    solarDate: Date;

    // The day number from 01/01/4713 BC (in Julian calendar) - Số ngày tính từ ngày 1 tháng 1 năm 4713 trước công nguyên (theo lịch Julian)
    juliusDayNumber: number;

    // Celestial stem of day - Can của ngày
    celestialStemOfDay: string

    // Terrestrial branch of day - Chi của ngày
    terrestrialBranchOfDay: string

    // Celestial stem of month - Can của tháng
    celestialStemOfMonth: string

    // Terrestrial branch of month - Chi của tháng
    terrestrialBranchOfMonth: string

    // Celestial stem of year - Can của năm
    celestialStemOfYear: string

    // Terrestrial branch of year - Chi của năm
    terrestrialBranchOfYear: string

    // Propitious hours - Các giờ hoàng đạo
    propitiousHours: string

    // Convert to string - Chuyển đổi thành chuỗi
    // formatString: Support 'd', 'D', 'm', 'M', 's', 'L', 'F' - Hỗ trợ 'd', 'D', 'm', 'M', 's', 'L', 'F'
    format(formatString: string): string

    // Return leap month of year, return 0 if year does not have leap month - Trả về tháng nhuận của năm, nếu không phải năm nhuận thì trả về 0.
    static getLeapMonth(lunarYear: number): number
}

Create Lunar date - Tạo một ngày âm

import * as VietnameseDate from 'vietnamese-date';

const lunarDate = new VietnameseDate(2021, 10, 23, false); // tháng 1 đến 12
console.log(lunarDate);

Convert Gregorian date to Lunar date - Chuyển đổi ngày dương sang ngày âm

import VietnameseDate from 'vietnamese-date';

const solarDate = new Date(2021, 10, 27); // Lưu ý: tháng từ 0 đến 11 nên cần trừ đi 1
const lunarDate = new VietnameseDate(solarDate);
console.log(lunarDate);

Convert Lunar date to Gregorian date - Chuyển đổi ngày âm sang ngày dương

console.log(lunarDate.solarDate);

Format lunar date - Chuyển đổi thành chuỗi

console.log("Format lunar date without format string", lunarDate.format(lunarDate));
console.log("Format lunar date with d", lunarDate.format(lunarDate, "d"));
console.log("Format lunar date with D", lunarDate.format(lunarDate, "D"));
console.log("Format lunar date with m", lunarDate.format(lunarDate, "m"));
console.log("Format lunar date with M", lunarDate.format(lunarDate, "M"));
console.log("Format lunar date with s", lunarDate.format(lunarDate, "s"));
console.log("Format lunar date with L", lunarDate.format(lunarDate, "L"));
console.log("Format lunar date with F", lunarDate.format(lunarDate, "F"));

Get leap month of year - Lấy về tháng nhuận của năm

import VietnameseDate from 'vietnamese-date';

for (let year = 2020; year <= 2030; year++) {
    console.log(year, ": ", VietnameseDate.getLeapMonth(year));
}