Need help with moment-hijri?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

xsoh
146 Stars 65 Forks MIT License 53 Commits 36 Opened issues

Description

A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js

Services available

!
?

Need anything else?

Contributors list

# 53,673
Docker
Android
lunar
android...
13 commits
# 320,481
Java
HTML
HTTP
lunar
13 commits
# 555,296
JavaScr...
lunar
2 commits
# 176,667
Windows
Amazon ...
aws-cli
lunar
1 commit
# 436,568
lunar
Java
kafka
HTML
1 commit
# 591,823
JavaScr...
lunar
1 commit
# 309,661
JavaScr...
PHP
Shell
braintr...
1 commit
# 249,802
Shell
hugo
apps-sc...
F#
1 commit
# 218,830
Lua
game-fr...
Discord
lunar
1 commit

NPM version MIT License Build Status

moment-hijri

A Hijri (Based on Umm al-Qura calculations) calendar system plugin for moment.js.

About

Hijri is the Islamic lunar calendar used by Muslims to determine the proper days on which to observe the annual fasting, to attend Hajj, and to celebrate other Islamic holidays and festivals. More information about Hijri can be found at wikipedia.

This plugin adds Hijri calendar support to momentjs library.

Calendar conversion is based on the Umm al-Qura calculations.

Upgrading to 2.0.0

Because of Using 'h' specifier might cause overlap with hour's specifier, the specifier has been changed from

h
to
i
as a prefix. For example in the previous version to get the four digit year,
hYYYY
will be used. In version 2.0 or above it should be replaced by
iYYYY
.

Where to use it?

Like

momentjs
,
moment-hijri
works in browser and in Node.js.

Node.js

npm install moment-hijri
var moment = require('moment-hijri');
moment().format('iYYYY/iM/iD');

Browser


Require.js

require.config({
  paths: {
    "moment": "path/to/moment",
    "moment-hijri": "path/to/moment-hijri"
  }
});
define(["moment-hijri"], function (moment) {
  moment().format('iYYYY/iM/iD');
});

API

This plugin tries to mimic

momentjs
api. Basically, when formatting or parsing a string, add an
i
to the format token such as 'iYYYY' or 'iM'. For example:
m = moment('1410/8/28', 'iYYYY/iM/iD'); // Parse a Hijri date.
m.format('iYYYY/iM/iD [is] YYYY/M/D'); // 1410/8/28 is 1990/3/25

m.iYear(); // 1410 m.iMonth(); // 7 m.iDate(); // 28 m.iDayOfYear(); // 236 m.iWeek(); // 35 m.iWeekYear(); // 1410

m.add(1, 'iYear'); m.add(2, 'iMonth'); m.format('iYYYY/iM/iD'); // 1411/10/28

m.iMonth(11); m.startOf('iMonth'); m.format('iYYYY/iM/iD'); // 1411/12/1

m.iYear(1392); m.startOf('iYear'); m.format('iYYYY/iM/iD'); // 1420/1/1

moment('1436/1/30', 'iYYYY/iMM/iDD').isValid(); // false (This month is only 29 days). moment('1436/2/30', 'iYYYY/iMM/iDD').isValid(); // true (This month is 30 days).

moment('1436/2/6 16:40', 'iYYYY/iM/iD HH:mm').format('YYYY-M-D HH:mm:ss'); // 2014-11-28 16:40:00

moment('2014-11-28 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('iMonth').format('iYYYY/iM/iD HH:mm:ss'); // 1436/2/30 23:59:59

// Complex parse: moment('1990 5 25', 'YYYY iM D').format('YYYY/MM/DD'); // 1990/03/25

To use the Arabic locale: - Load moment-with-locales. - Set the global or local locale to

ar-SA
see here. - use it normally :+1:

Here is example: ```html <!-- 1- Load the moment-with-locales -->

Acknowledgements
-------
This project was built from the great work done by [@behrang](https://github.com/behrang) whose behind [moment-jalaali](https://github.com/jalaali/moment-jalaali) project. 

License

MIT

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.