hijri

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 4 Imported by: 9

README

Go-Hijri

Go Report Card Go Reference

Go-Hijri is a Go package for converting Gregorian date to Hijrian date and vice-versa. There are two supported Hijrian calendar :

  • the arithmetic calendar which calculated based on arithmetic rules rather than by observation or astronomical calculation,
  • the Umm al-Qura calendar which calculated using astronomical rules that used and created by Saudi Arabia and most Islamic country.

Usage Examples

package main

import (
	"fmt"
	"time"

	"github.com/hablullah/go-hijri"
)

func main() {
	// 1 January 2020 to arithmetic Hijri calendar
	newYear := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
	hijriDate, _ := hijri.CreateHijriDate(newYear, hijri.Default)
	fmt.Printf("%s AD = %04d-%02d-%02d H (arithmetic)\n",
		newYear.Format("2006-01-02"),
		hijriDate.Year,
		hijriDate.Month,
		hijriDate.Day)

	// 1 January 2019 to Umm al-Qura calendar
	ummAlQuraDate, _ := hijri.CreateUmmAlQuraDate(newYear)
	fmt.Printf("%s AD = %s, %04d-%02d-%02d H (Umm al-Qura)\n",
		newYear.Format("2006-01-02"),
		ummAlQuraDate.Weekday.String(),
		ummAlQuraDate.Year,
		ummAlQuraDate.Month,
		ummAlQuraDate.Day)

	// 1 Ramadhan 1410 arithmetic Hijri to Gregorian
	stdRamadhan := hijri.HijriDate{Year: 1410, Month: 9, Day: 1}
	fmt.Printf("1410-09-01 H (arithmetic) = %s AD\n",
		stdRamadhan.ToGregorian().Format("2006-01-02"))

	// 1 Ramadhan 1442 Umm al-Qura to Gregorian
	ummAlQuraRamadhan := hijri.UmmAlQuraDate{Year: 1410, Month: 9, Day: 1}
	fmt.Printf("1410-09-01 H (Umm al-Qura) = %s AD\n",
		ummAlQuraRamadhan.ToGregorian().Format("2006-01-02"))
}

Codes above will give us following results :

2020-01-01 AD = 1441-05-05 H (arithmetic)
2020-01-01 AD = Thursday, 1441-05-06 H (Umm al-Qura)
1410-09-01 H (arithmetic) = 1990-03-28 AD
1410-09-01 H (Umm al-Qura) = 1990-03-27 AD

Resource

  1. Anugraha, R. 2012. Mekanika Benda Langit. (PDF)
  2. Van Gent, R. H. 2019. Islamic-Western Calendar Converter. (Website)
  3. Van Gent, R. H. 2019. The Umm al-Qura Calendar of Saudi Arabia. (Website)
  4. Strous, Dr. 2019. Astronomy Answers: Julian Days Number. (Website)

License

Go-Hijri is distributed using MIT license.

Documentation

Overview

Hijri is package for converting Gregorian date into Hijri date and vice versa. Hijri or Islamic calendar system itself is a lunar calendar used in many Muslim countries, with a year has 12 months and 354 days or 355 days in a leap year.

Hijri calendar only recognizes one era: A.H. (Latin "Anno Hegirae", which means "the year of the migration," in reference to the migration of Muhammad (PBUH) from Mecca). With that said, Hijri calendar is not proleptic, so there are no negative Hijri year.

This package supports two kind of Hijri calendar, the arithmetic calendar and Umm al-Qura calendar.

The arithmetic or tabular Hijri calendar (or simply Hijri) is a rule-based variation of the Islamic calendar, in which months are worked out by arithmetic rules rather than by observation or astronomical calculation. It is introduced by Muslim astronomers in the 8th century CE to predict the approximate beginning of the months in the Islamic lunar calendar.

It has a 30-year cycle with 11 leap years of 355 days and 19 years of 354 days. In the long term, it is accurate to one day in about 2,500 solar years or 2,570 lunar years. It also deviates up to about one or two days in the short term. However, there are several patterns of leap years to decide which years within the 30 are leap.

The Umm al-Qura calendar is astronomical-based calendar that used and created by Saudi Arabia. It is also used by several neighbouring states on the Arabian Peninsula such as Bahrain and Qatar. For this calendar, each month has either 29 or 30 days, but usually in no discernible order.

The implementation of Umm al-Qura calendar in this package is based on Javascript code by R.H. van Gent from Utrecht University. The date must be between 14 March 1937 (1 Muharram 1356 H) and 16 November 2077 (29 Dhu al-Hijjah 1500 H).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HijriDate

type HijriDate struct {
	Day     int64
	Month   int64
	Year    int64
	Pattern LeapYearsPattern
}

HijriDate is date that uses arithmetic Islamic calendar system.

func CreateHijriDate

func CreateHijriDate(date time.Time, leapPattern LeapYearsPattern) (HijriDate, error)

CreateHijriDate converts normal Gregorian date to Hijri date. Since Hijri calendar is not proleptic any date before 16 July 622 CE (1 Muharram 1 H) will make this method throws error.

func (HijriDate) ToGregorian

func (h HijriDate) ToGregorian() time.Time

ToGregorian convert Hijri date to Gregorian date using Golang standard time.

type LeapYearsPattern

type LeapYearsPattern uint8

LeapYearsPattern is patterns of leap years in the 30 year cycle.

const (
	// Default is the most commonly used leap years pattern. In this pattern, leap year happened
	// on years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 & 29.
	Default LeapYearsPattern = iota

	// Base15 is leap years pattern that used by Microsoft, and they named it as "Kuwaiti algorithm".
	// In this pattern, leap year happened on years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26 & 29.
	Base15

	// Fattimid is leap years pattern that used in Fattimid empire. In this pattern, leap year
	// happened on years 2, 5, 8, 10, 13, 16, 19, 21, 24, 27 & 29.
	Fattimid

	// HabashAlHasib is leap years pattern that created using research from Habash al-Hasib,
	// an astronomer from Abbasid empire (766-869 in Iraq). In this pattern, leap year happened on
	// years 2, 5, 8, 11, 13, 16, 19, 21, 24, 27 & 30.
	HabashAlHasib
)

type UmmAlQuraDate

type UmmAlQuraDate struct {
	Day     int64
	Month   int64
	Year    int64
	Weekday time.Weekday
}

UmmAlQuraDate is a date that uses astronomical-based Islamic calendar system that used in Saudi Arabia.

func CreateUmmAlQuraDate

func CreateUmmAlQuraDate(date time.Time) (UmmAlQuraDate, error)

CreateUmmAlQuraDate converts Gregorian date to Umm al-Qura date.

func (UmmAlQuraDate) ToGregorian

func (uq UmmAlQuraDate) ToGregorian() time.Time

ToGregorian convert Umm al-Qura date to Gregorian date using Golang standard time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL