npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chajdate

v1.0.0

Published

Convert and format shamsi/jalali/persian date to gregory and vice versa.

Downloads

8

Readme

chaj

Is modern browser fast and small with zero dependency native JavaScript datetime converting and formatting from Shamsi/Jalali/Persian to Gregory and vice versa.

The API using modern browser Intl.DateTimeFormat object for date and time formatting.

تبدیل و تغیر تاریخ هجری شمسی/جلالی به میلادی و برعکس آن برای بروزر های جدید و Nodejs

Quick Info:

Shamsi/Jalali/Persian or Solar Hijri Calendar currently using in Afghanistan, Iran and Tajikistan you can find more info Here the API converting and formatting datetime to gregory and vice versa.

Getting Started

Installation - فعالسازی

in Browser: در بروزر

You can Download and link to file.

<script src="path/to/chaj.js"></script>

Via npm package manager در Nodejs

npm install chajdate

Usage: - استفاده

  • Currently, there is only one public method: Chaj.format()

The method taking tow paramters date as string in ISO 8601 format, and second param as object with all available and valid properties of Intl.DateTimeFormat - Options and return converted/formatted date as string/array

Example: مثالها

By default Chaj.format() with zero param return current local date & time.



const Chaj = require('chajdate');

// with no parameters.
Chaj.format() // current date 0000/00/00


// convert/format gregory to shamsi/jalali/persian
Chaj.format('2022-10-25') // 1401/8/3

// convert/format shamsi/jalali/persian to gregory
Chaj.format('1401-8-25', {shamsi: true}) // 11/16/2022

// Customize the date by adding more options
Chaj.format(null, {dateStyle: 'full'}) // current date

Chaj.format('2022-10-25', {dateStyle: 'full'}) // 1401 عقرب 3, سه‌شنبه

Chaj.format('1401-10-02', {shamsi: true, dateStyle: 'full'}) // Friday, December 23, 2022

Parameters/Options

  • First Param Date as string in ISO 8601 format a space instead of the "T" is allowed.

    Chaj.format('2022-10-25T12:00:00.000Z')` - `Chaj.format('2022-10-25 14:25')
  • Second Param as object {} you can pass all Intl.DateTimeFormat - Options at once.

    Chaj.format('2022-10-25', {
      dateStyle: 'full',
      locale: 'en-US',
      timeZone: 'Asia/Kabul', 
      calendar: 'persian'}
      )
  • Converting shamsi/jalali/persian date to gregory add shamsi as boolean default is false.

    Chaj.format('1401-8-25', {
      shamsi: true, 
      dateStyle: 'full', 
      locale: 'en-US', 
      timeZone: 'Asia/Kabul', 
      calendar: 'persian'}
      )
  • By default it converting/formatting date with local datetime. you can add utc key to option with boolean value default is false for converting/formatting date and time to UTC.

    Chaj.format('1401-8-25', {
      shamsi: true,
      utc: true,
      dateStyle: 'full',
      locale: 'en-US',
      timeZone: 'Asia/Kabul',
      calendar: 'persian'}
      )

Return value.

By default it return as string you can add toArray as boolean for returning value as array of objects.

Default Paramters/Options:

  • Date as string current local date & time.
  • Options as object
    timeZone: 'Asia/Kabul',
    calendar: 'persian',
    locale: 'fa-AF-u-nu-latn',
    utc: false,
    shamsi: false,
    toArray: false

More Options:

you can find more formatting information about Intl.DateTimeFormat - Options , Thanks to MDN documentation Here

Browser/Nodejs Support

Chrome | Firefox | Safari | Opera | Edge | Nodejs --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔

TODO: add more public methods.

License

MIT