Giter VIP home page Giter VIP logo

suncalc's Introduction

Sun Calculator


Thư viện Javascript tính toán thời gian mặt trời mọc/lặn và hơn thế nữa

Cloned từ NOAA Solar Calculator NOAA

npm npm bundle size npm downloads Coverage Status

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

suncalc's People

Contributors

nghiacangao avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.