1.1.0 • Published 11 months ago

@nghiavuive/sunset_calc v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

npm npm bundle size npm downloads

Table of Contents

Features

  • Tính toán giờ mặt trời mọc/lặn
  • Cung cấp các hàm tính toán thiên văn như getGeomMeanLongSun, getEccentEarthOrbit,...

Installation

Package manager

Cài đặt qua NPM

npm install @nghiavuive/sunset_calc

Khi cài đặt xong, ta có thể import bằng import hoặc require. Trước khi bắt đầu, đảm bảo rằng package.json"type": "module".

import { LunarDate, SolarDate } from "@nghiavuive/sunset_calc";

Nếu sử dụng Typescript, lưu ý cấu hình tsconfig.json như sau:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "moduleResolution": "node",
    "module": "ESNext"
  },
  "include": ["./**/*.ts"],
  "exclude": ["node_modules"]
}

Nếu sử dụng require

const calendar = require("@nghiavuive/sunset_calc/dist/index.cjs");

CDN

Sử dụng qua jsDelivr

<script src="https://cdn.jsdelivr.net/gh/NghiaCaNgao/SunCalc@latest/dist/index.umd.js"></script>

Examples

Sử dụng ES Module với Typescript. JavaScript tương tự.

Note Nếu sử dụng ts-node thì cần chạy npx ts-node --esm <filename>

Code bên dưới minh họa sử dụng Sun class để tính thời điểm mặt trời lặn.

import { ISun, Sun } from "@nghiavuive/sunset_calc";

const options: ISun = {
  date: new Date(),
  lat: 21,
  long: 105,
  time_zone: 7,
};
const sun = new Sun(options);
console.log(sun.getSunsetTime());

//18:44:24

Nếu sử dụng CommonJs

const _sun = require("@nghiavuive/sunset_calc/dist/index.cjs");

const options = {
  date: new Date(),
  lat: 21,
  long: 105,
  time_zone: 7,
};

const sun = new _sun.Sun(options);
console.log(sun.getSunsetTime());

//18:44:24

API

Interfaces

ISun

Input của Sun class

interface ISun {
  lat: number; // + to N
  long: number; // + to E
  time_zone: number; // + to E
  date: Date;
}

Sun

Tạo thực thể Sun từ ISun.

Note Ngày nhập vào phải bắt đầu từ 1970-01-01

constructor(props: ISun);

Ví dụ:

import { ISun, Sun } from "@nghiavuive/sunset_calc";

const options: ISun = {
  date: new Date(),
  lat: 21,
  long: 105,
  time_zone: 7,
};
const sun = new Sun(options);

sun.setDate()

Đặt lại ngày cho thực thể Sun

setDate(date: Date): void

sun.setLatLong()

Đặt lại vịt trí cho thực thể Sun

 setLatLong(lat: number, long: number):void

sun.setTimeZone()

Đặt lại múi giờ cho thực thể Sun

setTimeZone(time_zone: number): void

sun.get()

Lấy thông tin của thực thể Sun

get();

Ví dụ:

import { ISun, Sun } from "@nghiavuive/sunset_calc";
const options: ISun = {
  date: new Date(),
  lat: 21,
  long: 105,
  time_zone: 7,
};
const sun = new Sun(options);

sun.setDate(new Date(2020, 1, 1));
sun.setLatLong(21, 105);
sun.setTimeZone(7);

console.log(sun.get());

// {
//   lat: 21,
//   long: 105,
//   time_zone: 7,
//   date: 2020-01-31T17:00:00.000Z,
//   jd: 2458880.2083333335
// }

sun.getSunsetTime()

Lấy thời gian mặt trời lặn theo định dạng hh:mm:ss

getSunsetTime(): string

sun.getSunriseTime()

Lấy thời gian mặt trời mọc theo định dạng hh:mm:ss

getSunriseTime(): string

sun.getSunlightDuration()

Lấy thời gian mặt trời chiếu sáng theo định dạng hh:mm:ss

getSunlightDuration(): string

Ví dụ:

import { ISun, Sun } from "@nghiavuive/sunset_calc";
const options: ISun = {
  date: new Date(2023, 5, 23),
  lat: 21,
  long: 105,
  time_zone: 7,
};
const sun = new Sun(options);

console.log(sun.);

// 13:24:31
// 05:19:46
// 18:44:17

Other funcs

convertToJulianDay, getApproxAtmosphericRefraction, getEccentEarthOrbit, getEqOfTime, getGeomMeanAnomSun, getGeomMeanLongSun, getHASunrise, getHourAngle, getJulianCentury, getMeanObliqEcliptic, getObliqCorr, getSolarAzimuthAngle, getSolarElevationAngle, getSolarElevationCorrectedForAtmRefraction, getSolarNoon, getSolarZenithAngle, getSunAppLong, getSunDeclin, getSunEqOfCtr, getSunlightDuration, getSunRadVector, getSunriseTime, getSunRtAscen, getSunsetTime, getSunTrueAnom, getSunTrueLong, getTrueSolarTime, getVarY deg2rad, excelMod, formatTime, rad2deg

Explain soon

1.1.0

11 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago