# vietnamese-date

> Vietnamese date

Latest version **1.1.1** (published 2024-08-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install vietnamese-date
pnpm add vietnamese-date
yarn add vietnamese-date
bun add vietnamese-date
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2024-08-05 |
| First published | 2021-11-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | suco2007 |
| Maintainers | suco2007 |
| Keywords | lunar, calendar, vietnamese, date, âm lịch, lịch việt |

## Links

- npm: https://www.npmjs.com/package/vietnamese-date
- npm.io page: https://npm.io/package/vietnamese-date

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2024-08-05
- 1.1.0 — 2024-08-04
- 1.0.0 — 2021-11-27

## README

# Vietnamese lunar date - Âm lịch

```javascript
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

```javascript
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

```javascript
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

```javascript
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

```javascript
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

```javascript
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

---
_Source: https://npm.io/package/vietnamese-date · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
