1.0.2 • Published 1 year ago

@nghiavuive/lunar_date_vi v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Chuyển lịch âm sang lịch dương và ngược lại

Cách sử dụng

  • Tải folder dist về là dùng được.

  • npm

npm i @nghiavuive/lunar_date_vi

Chuyển đổi từ dương sang âm

import { LunarDate, SolarDate } from "../../dist/bundle.js";

const solarDate = new SolarDate(new Date());
const lunarDate = LunarDate.fromSolarDate(solarDate);

console.log(solarDate.get());
console.log(lunarDate.get());

// { day: 21, month: 3, year: 2023, leap: false, julian: 2460025 }
// {day: 1, month: 3, year: 2023, leap: false, julian: 2460025, name: 'Quý Mão'}

Chuyển từ lịch âm sang dương

import { LunarDate, SolarDate } from "../../dist/bundle.js";

const al = new LunarDate({ day: 10, month: 3, year: 2023 });
const dl = al.toSolarDate().get();

// { day: 30, month: 3, year: 2023, leap: false, julian: 2460034 }

API

Một chút về dịch thuật

Can chi trong Tiếng Anh

  • lịch hoàng đạo: Zodiac calendar
  • 12 con giáp: 12 animal designations
  • can chi: sexagenary cycle
  • can heavenly stems
  • chi earthly branches

Vấn đề đổi từ Julian Date sang Solar Date và ngược lại

API

Interface

ICalendar

Input option cho Calendar Object

export interface ICalendar {
  day: number;
  month: number;
  year: number;
}

ISolarDate

Input option cho Solar Object. Kế thừa từ ICalendar

interface ISolarDate extends ICalendar

ILunarDate

Input option cho LunarDate. Kế thừa từ ICalendar

interface ILunarDate extends ICalendar {
  leap?: boolean;
  jd?: number;
}

IZodiacHour

Cung hoàng đạo

interface IZodiacHour {
  name: string;
  time: number[];
}

Solar Class

Solar constructor 1

  • Input ISolarDate option cho Solar Object
  • Return Solar Object
public constructor(date: ISolarDate);
  • Ví dụ:
new SolarDate({ day: 1, month: 1, year: 2023 });

Solar constructor 2

  • Input built-in Date Object
  • Return Solar Object
public constructor(date: Date);
  • Ví dụ:
new SolarDate(new Date());

SolarDate.fromJd

  • Return Solar Date from Julian Date
static fromJd(jd: number): SolarDate
  • Ví dụ
console.log(SolarDate.fromJd(2460035));

// SolarDate2 { day: 31, month: 3, year: 2023, jd: 2460035, leap: false }

solar.toJd

  • Trả về ngày Julian date tương ứng
toJd(): number
  • Ví dụ:
const solar = new SolarDate(new Date());
console.log(solar.toJd());

// 2460035

solar.toDate

  • Trả về dạng Date Object
toDate(): Date
  • Ví dụ:
const solar = new SolarDate(new Date());
console.log(solar.toDate());

// 2023-03-30T17:00:00.000Z

solar.get()

  • Lấy thông tin của đối tượng solar
get();
const dl = new SolarDate(new Date());
console.log(dl.get());

// { day: 31, month: 3, year: 2023, leap: false, julian: 2460035 }

Lunar class

Constructor 1

constructor(date: ILunarDate)
  • Ví dụ:
const al = new LunarDate({ day: 1, month: 1, year: 2023 });

SolarDate.fromSolarDate()

  • Chuyển từ dương lịch sang âm lịch
const dl = new SolarDate(new Date());
console.log(LunarDate.fromSolarDate(dl));

// LunarDate2 { day: 10, month: 2, year: 2023, leap: true, jd: 2460035 }

lunar.get()

  • Lấy thông tin của đối tượng lunar
get();
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.get());

// {
//   day: 10,
//   month: 2,
//   year: 2023,
//   leap: true,
//   julian: 2460035,
//   name: 'Quý Mão'
// }

lunar.getYearCanChi()

  • Lấy can chi của năm
getYearCanChi(): string
  • Ví dụ:
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getYearCanChi());

// Quý Mão

lunar.getMonthCanChi()

  • Lấy Can của tháng
getMonthCanChi(): string
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getMonthCanChi());

// Ất Mão (nhuận)

lunar.getDayCanChi()

  • Lấy Can của ngày
getDayCanChi(): string
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getDayCanChi());

// Mậu Tý

lunar.getGioCanChi()

  • Lấy Can của giơ
getGioCanChi(): string
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getGioCanChi());

// Nhâm Tý

lunar.getDayOfWeek()

  • Thứ trong tuần
getDayOfWeek(): string
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getDayOfWeek());

// Thứ sáu

lunar.getTietKhi()

  • Thứ trong tuần
getTietKhi(): string
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getTietKhi());

// Xuân phân

lunar.getZodiacHour()

  • Lấy giờ hoàng đạo
getZodiacHour(): Array<IZodiacHour>
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.getZodiacHour());

// [
//   { name: 'Tý', time: [ 23, 1 ] },
//   { name: 'Sửu', time: [ 1, 3 ] },
//   { name: 'Mão', time: [ 5, 7 ] },
//   { name: 'Ngọ', time: [ 11, 13 ] },
//   { name: 'Thân', time: [ 15, 17 ] },
//   { name: 'Dậu', time: [ 17, 19 ] }
// ]

lunar.toSolarDate()

  • Lấy giờ hoàng đạo
toSolarDate(): SolarDate
  • Ví dụ
const dl = new SolarDate(new Date());
const al = LunarDate.fromSolarDate(dl);
console.log(al.toSolarDate());
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago