npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vietnamese-date

v1.1.1

Published

Vietnamese date

Downloads

18

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 VietnameseDate from 'vietnamese-date';

const lunarDate = new VietnameseDate(2021, 10, 23, false);
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';

// Gregorian date must be at Vietnam's timezone - Ngày dương phải được khai báo ở timezone của Việt Nam
const solarDate = new Date('2021-11-27T00:00:00+07:00');
// Gregorian date without specifying a timezone may convert to the wrong lunar date in some cases - Ngày dương lịch mà không chỉ định timezone có thể chuyển đổi sang ngày âm lịch sai trong một số trường hợp
// const solarDate = new Date(2021, 10, 27);
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); // solarDate in Vietnam's timezone - Ngày dương được quy về timezone của Việt Nam

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

console.log("Format lunar date without format string:", lunarDate.format());
// Format lunar date without format string: 07/10/2021
// Format lunar date without format string: 26/04N/2020

console.log("Format lunar date with d:", lunarDate.format("d"));
// Format lunar date with d: 07/10/2021
// Format lunar date with d: 26/04N/2020

console.log("Format lunar date with D:", lunarDate.format("D"));
// Format lunar date with D: Thứ năm, mùng 7 tháng Mười năm 2021
// Format lunar date with D: Thứ tư, ngày 26 tháng Tư (nhuận) năm 2020

console.log("Format lunar date with m:", lunarDate.format("m"));
// Format lunar date with m: 07/10
// Format lunar date with m: 26/04N

console.log("Format lunar date with M:", lunarDate.format("M"));
// Format lunar date with M: mùng 7 tháng Mười
// Format lunar date with M: 26 tháng Tư (nhuận)

console.log("Format lunar date with s:", lunarDate.format("s"));
// Format lunar date with s: 2021 / 10 / 07
// Format lunar date with s: 2020 / 04N/ 26

console.log("Format lunar date with L:", lunarDate.format("L"));
// Format lunar date with L: ngày Quý Hợi tháng Kỷ Hợi năm Tân Sửu
// Format lunar date with L: ngày Tân Mão tháng Tân Tỵ (nhuận) năm Canh Tý

console.log("Format lunar date with F:", lunarDate.format("F"));
// Format lunar date with F: Thứ năm, mùng 7 tháng Mười năm 2021 (ngày Quý Hợi tháng Kỷ Hợi năm Tân Sửu)
// Format lunar date with F: Thứ tư, ngày 26 tháng Tư (nhuận) năm 2020 (ngày Tân Mão tháng Tân Tỵ (nhuận) năm Canh Tý)

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));
}

Release notes

Version 1.1.1

  • Fixed bugs

Version 1.1

  • New
    • Add new constructor VietnameseDate(isoDate: string)
  • Changes
    • All calculations are based on UTC+07:00 timezone