包详细信息

@calidy/dayjs-calendarsystems

calidy-com1.2kSEE LICENSE IN LICENSE.md1.11.3

Calendar Systems Management for Day.js

dayjs, date, time, immutable

自述文件

Dayjs Calendar Systems

Install | License | Usage | Contributing


Day.js Calendar Systems Plugin extends Day.js library to allow the use of different non-gregorian calendar systems like:

  • Persian (a.k.a.: Jalaali, Shamsi, Khorshidi),
  • Arabic (a.k.a: Hijri, Islamic, Umalqura, Ghamari),
  • Hebrew (a.k.a: Jewish),
  • Amazigh (a.k.a: Berber),
  • and more to come (PRs are welcome).

With this plugin, Day.js will be available to more than 200 million additional users worldwide (Estimated number of non-gregorian calendar users).

With the @calidy/dayjs-calendarsystems plugin, we bring the capacity to run and use all non-gregorian calendar systems to Dayjs.


Features

  • Register and use different calendar systems.
  • Typescript exports and definitions.
  • Compatible with all official Dayjs plugins.
  • No need for hacks, use dayjs apis in the standard way.
  • Small and light plugin, no overhead.
  • Convert between different calendar systems.
  • 🌍 🗓️ 📅 Default Gregorian calendar system included.
  • 🌍 🗓️ 🇮🇷 Persian Calendar system available.
  • 🌍 🗓️ 🇸🇦 Islamic (Hijri, Umalqura) Calendar system. Note: we will use the default "islamic-umalqura" calendar system for "islamic" calendar system.
  • 🌍 🗓️ 🇮🇱 Hebrew (Jewish) Calendar system.
  • 🌍 🗓️ ⵣ Amazigh (Berber) Calendar system.
  • 🌍 🗓️ 🇪🇹 [WIP] Ethiopian Calendar system.
  • 🌍 🗓️ 🇮🇳 [TODO] Indian Calendar system.
  • 🌍 🗓️ 🇨🇳 [TODO] Chinese Calendar system.
  • 🌍 ✅ Fixes translations of month names in Dayjs for non-gregorian and gregorian calendar systems (This is based on my knowledge, please PR to add more fixes).
  • [TODO] Parse date strings from different calendar systems
  • [TODO] Add more tests for all Dayjs Plugins

API

All API operations and Dayjs plugins may be used as instructed by Dayjs with the specific calendar system when this plugin is used, for more information checkout Dayjs Documentation

Installation

NPM

npm install --save @calidy/dayjs-calendarsystems

YARN

yarn add --save @calidy/dayjs-calendarsystems

Usage

import dayjs from "dayjs";
import calendarSystems from "@calidy/dayjs-calendarsystems";

// Note: Gregorian Calendar System is included by default,
//       so there is no need to import the `GregoryCalendarSystem` file here.

import PersianCalendarSystem from "@calidy/dayjs-calendarsystems/calendarSystems/PersianCalendarSystem";

// ...
// ALL YOU OTHER dayjs.extend() calls
// ...
// After all other dayjs plugins are initialized, extend dayjs with our calendar systems plugin:
dayjs.extend(calendarSystems);

// Register new calendar system
dayjs.registerCalendarSystem("persian", new PersianCalendarSystem());

// Set default dayjs config (for all following instances) to a specific calendar system:
// dayjs.toCalendarSystem("persian");

// Convert a dayjs instance to a specific calendar system.
let date = dayjs().toCalendarSystem("persian");

// Convert a date from a specific calendar system without initializing a dayjs instance.
date = dayjs.fromCalendarSystem('persian', 1402, 2, 17);

Adding Custom Calendar Systems

This plugin allows you to add your own custom calendar systems. Each calendar system must be an object with the following properties:

  • convertToGregorian(year: number, month: number, day: number): { year: number; month: number; day: number; } | void: a function that converts a date from the current calendar system to the Gregorian calendar.
  • convertFromGregorian(date: Date | string | number | undefined | null): { year: number; month: number; day: number; } | void: a function that converts a Gregorian date to the current calendar system.

License

This project is DUAL LICENSED.

  • For non-commercial use, this project uses the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) licence.
  • For commercial use (when you or your company earns revenue directly or indirectly using this project), a valid commercial licensed is required.

Please see the LICENSE.md file for details.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Please see the CONTRIBUTING.md file for details. Please see the CODE_OF_CONDUCT.md file for details.

Support

If you have any issues or feature requests, please file issues and feature requests on the GitHub repo.

Acknowledgements

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.11.3 (2024-02-29)

Bug Fixes

  • amazigh calendar and tests are stable now. (34b4e5e)

1.11.2 (2024-02-28)

Bug Fixes

1.11.1 (2024-02-28)

1.11.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

1.10.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

  • buildtime issues, add eslintrc (13b5594)
  • typo in function brackets (595d119)
  • update babel build config (7d448cb)

1.9.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

  • buildtime issues, add eslintrc (13b5594)
  • typo in function brackets (595d119)
  • update babel build config (7d448cb)

1.8.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

  • buildtime issues, add eslintrc (13b5594)
  • typo in function brackets (595d119)
  • update babel build config (7d448cb)

1.7.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

  • buildtime issues, add eslintrc (13b5594)
  • typo in function brackets (595d119)

1.6.0 (2024-02-28)

Features

  • add Amazigh calendar system (2d9a8e9)

Bug Fixes

  • typo in function brackets (595d119)

1.4.0 (2023-06-21)

Features

  • code optimization, cleanup and more functions. Added a WIP for Ethiopian calendar, still not stable. Fixed timezone and utc calculations (731d5c5)

1.3.0 (2023-06-02)

Features

  • Added Hebrew Calendar System, hebrew tests, fix typescript issues, code cleanup, introduced new isLeapYear function (rewrites dayjs plugin to work on all calendar systems) (fd550e1)

1.2.0 (2023-05-31)

Features

  • Huge perf improvement by caching Intl Api formatters (7f19395)

1.1.3 (2023-05-23)

Bug Fixes

  • complexe calendar system conversions are now working, example: persian to islamic to gregory to persian.... (3f5c633)

1.1.2 (2023-05-23)

Bug Fixes

  • update method to accepts all units (c23b049)

1.1.1 (2023-05-23)

Bug Fixes

  • add hijri (islamic) to CalendarSystem type export (605dbe0)

1.1.0 (2023-05-23)

Features

  • new hijri/islamic calendar system available. (5a14c21)

1.0.19 (2023-05-22)

Bug Fixes

  • persian calendar converter is now using astronomical calculations and fixes leap year calculations. added more tests and cleaned the underlayer converter library. (c0ea087)

1.0.18 (2023-05-22)

Bug Fixes

  • more typescript cleaning and fixing, add more docs (4b42986)

1.0.17 (2023-05-22)

Bug Fixes

  • typescript export calendar types as CalendarSystem type (b81c93a)

1.0.16 (2023-05-22)

Bug Fixes

  • more typescript cleaning and fixing (949eb8d)

1.0.15 (2023-05-22)

Bug Fixes

  • typescript cleaning and fixing (4b6c6f0)

1.0.14 (2023-05-21)

Bug Fixes

  • utc and timezone plugins are now compatible with our plugin. more tests are welcome (c6f5c3b)

1.0.13 (2023-05-21)

Bug Fixes

  • timezone plugin compatibility. Note: when extending dayjs with plugins, make sure to have utc and timeZone plugins AFTER our calendarSystems plugin (470b66c)

1.0.12 (2023-05-20)

Bug Fixes

  • workaround for minification and classnames check (3ec030f)

1.0.11 (2023-05-20)

Bug Fixes

  • file names in exported dist plugins (2228de8)

1.0.10 (2023-05-20)

Bug Fixes

  • folder names and paths typo in builder (b080591)
  • package.json syntax (8abd5cb)

1.0.9 (2023-05-20)

Bug Fixes

1.0.8 (2023-05-20)

Bug Fixes

  • fixing file structure and names and example (35d2ecb)

1.0.7 (2023-05-20)

Bug Fixes

  • fixing npm publish scripts (3f48f12)

1.0.6 (2023-05-20)

Bug Fixes

  • add .yarnrc to help yarn pick the .npmrc file for auth (9f2fdc6)

1.0.5 (2023-05-20)

1.0.4 (2023-05-20)

Bug Fixes

1.0.3 (2023-05-20)

Bug Fixes

  • prepare for npm publishing (c9ca47b)

1.0.2 (2023-05-20)

1.0.1 (2023-05-20)

Bug Fixes

  • prepare for npm publishing (23056f8)
  • prepare for npm publishing (2b76d88)

1.0.0 (2023-05-20)

Features

Bug Fixes

  • Licensing update, fix author and contributors fields and info (060e607)
  • Licensing update, fix author and contributors fields and info (9adc7b9)