Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xsoh/Hijri.js

A tool for the Islamic calender (Hijri) in Javascript
https://github.com/xsoh/Hijri.js

calendar gregorian hijri hijri-calendar

Last synced: about 19 hours ago
JSON representation

A tool for the Islamic calender (Hijri) in Javascript

Awesome Lists containing this project

README

        

Hijri.js
========

A simple implementation for the Islamic calender(Hijri) in Javascript

## The Problem
I made this project just because I did not found any correct and open source Hijri converter. Each time I try one its either stored in database and fetch the data each time or it does not give me the correct date "specially when I try before 1420H"

## Usage
### Current Day
To get Today in Hijri:
```html


Today is:

function initWork() {
//Today
var todayElement = document.getElementById("today");
todayElement.innerHTML = HijriJS.today().toString();
}

```
### Conversion
To convert between Hijri and Gregorian use the ``HijriJS.toHijri(dateString, splitter)`` to convert Gregorian to Hijri
or ``HijriJS.toGregorian(dateString, splitter)`` to convert Hijri to Gregorian where the splitter is the symbol splits the date (e.g. for 1434/1/1 is ``HijriJS.toGregorian("1434/1/1", "/")``):
```html




 


function convertToHijri() {
var gregorianDate = document.getElementById("gregorianInput").value
var hijriDate = document.getElementById("hijriDate");

var date = HijriJS.toHijri(gregorianDate, "/");
hijriDate.innerHTML = date.toString();
}

```
### Formating
More advanced is to print the date with different format you can use ``date.toFormat(yourStringFormat);`` where yourStringFormat can be:
- **YYYY**: For the four digit year notation e.g. 1434.
- **YY**: For two year notation e.g. 34 of 1434.
- **mm**: For two digit month notation e.g. 03.
- **m**: For one digit month notation e.g. 3.
- **dd**: For two digit day notation.
- **d**: For one digit day notation.
- **n**: For calender notation "H for Hijri or G for Gregorian".

You can use the same example above and change it like this:
```javascript

function convertToHijri() {
var gregorianDate = document.getElementById("gregorianInput").value
var hijriDate = document.getElementById("hijriDate");

var date = HijriJS.toHijri(gregorianDate, "/");
hijriDate.innerHTML = date.toFormat("dd/mm/yyyyN");
}

```