simorgh
v1.0.6
Published
A package for date conversion and calendar
Readme
PolyDate Library
The PolyDate library provides a versatile representation of dates with conversions between Julian days, Shamsi (Persian), Hijri (Islamic), and Gregorian dates. It includes utility methods for creating PolyDate instances and converting them to and from JavaScript Date objects.
Installation
To use the PolyDate library in your project, follow these steps:
- Download the PolyDate library files.
- Include the library files in your project directory.
- Import the necessary classes in your code:
import BaseDate from "../Base/BaseDate";
import PolyDate from "path-to-your-PolyDate-file";Getting Started
Creating a PolyDate
To create a PolyDate instance, use the PolyDate.Build() method, providing a BaseDate object:
const baseDate = new GregorianDate(2024, 2, 21); // Example Gregorian date
const polyDate = PolyDate.Build(baseDate);Current Date and Time
To create a PolyDate representing the current date and time, use the PolyDate.now() method:
const currentDate = PolyDate.now();Converting to JavaScript Date
You can convert a PolyDate instance to a JavaScript Date object using the toDate() method:
const jsDate = polyDate.toDate();PolyDate Properties
A PolyDate instance has the following properties:
julianDay: Julian day converter service associated with the PolyDate.shamsi: Shamsi (Persian) date representation.hijri: Hijri (Islamic) date representation.gregorian: Gregorian date representation.
Examples
Example 1: Creating a PolyDate
const gregorianDate = new GregorianDate(2024, 2, 21);
const polyDate = PolyDate.Build(gregorianDate);Example 2: Current Date and Time
const currentDate = PolyDate.now();Example 3: Converting to JavaScript Date
const jsDate = polyDate.toDate();Notes
- The library internally uses various date representations and services for conversions.
- The
Buildmethod optimizes date conversion using Julian days. - For efficient performance, consider using the
Buildmethod instead of directly creating a PolyDate instance.
