Hijri

NAME

Date::Calendar::Hijri - Arithmetic variant of the Hijri calendar

SYNOPSIS

Converting a Gregorian date (e.g. 7th February 2021) into Hijri


use Date::Calendar::Hijri;
my Date $dt-greg;
my Date::Calendar::Hijri $dt-hijri;

$dt-greg  .= new(2021, 2, 7);
$dt-hijri .= new-from-date($dt-greg);

say $dt-hijri;
# --> 1442-06-24
say $dt-hijri.strftime("%A %d %B %Y");
# --> Yaum al-Ahad 24 Jumaada al-Thaani 1442

Converting a Hijri date (e.g. 1 Muharram 1443) into Gregorian


use Date::Calendar::Hijri;
my Date::Calendar::Hijri $dt-hijri;
my Date $dt-greg;

$dt-hijri .= new(year => 1443, month => 1, day => 1);
$dt-greg   = $dt-hijri.to-date;

say $dt-greg;
# --> 2021-08-10

Converting a date while caring about sunset:


use Date::Calendar::Strftime;
use Date::Calendar::Gregorian;
use Date::Calendar::Hijri;

my Date::Calendar::Gregorian $dt-greg;
my Date::Calendar::Hijri     $dt-hijri;

$dt-greg  .= new(year => 2024, month => 11, day => 13, daypart => before-sunrise());
$dt-hijri .= new-from-date($dt-greg);
say $dt-hijri.strftime("%A %d %B %Y");        # -->  "Yaum al-Arbi'a 11 Jumaada al-Awal 1446"

$dt-greg  .= new(year => 2024, month => 11, day => 13, daypart => daylight());
$dt-hijri .= new-from-date($dt-greg);
say $dt-hijri.strftime("%A %d %B %Y");        # -->  "Yaum al-Arbi'a 11 Jumaada al-Awal 1446" again

$dt-greg  .= new(year => 2024, month => 11, day => 13, daypart => after-sunset());
$dt-hijri .= new-from-date($dt-greg);
say $dt-hijri.strftime("%A %d %B %Y");        # -->  "Yaum al-Khamees 12 Jumaada al-Awal 1446"

DESCRIPTION

The real Hijri calendar is an observational calendar. That means that calendar events, such as switching from a month to the next, depend of the observation of some astronomical events, such as observing the moon crescent after a new moon. But there is an unofficial arithmetic variant, which differs from the real one by one or two days.

Date::Calendar::Hijri is a class representing dates in the arithmetic variant of the Hijri calendar. It allows you to convert a Hijri date into Gregorian (or possibly other) calendar and the other way.

METHODS

Constructors

new

Create an Hijri date by giving the year, month and day numbers, plus optionally the day part (before-sunrise, daylight or after-sunset).

new-from-date

Build an Hijri date by cloning an object from another class. This other class can be the core class Date or any Date::Calendar::xxx class with a daycount method and, hopefully, a daypart method.

new-from-daycount

Build an Hijri date from the Modified Julian Day number and the daypart value.

Accessors

gist

Gives a short string representing the date, in YYYY-MM-DD format.

year, month, day

The numbers defining the date.

daycount

Modified Julian Day Number (a day-only scheme based on 17 November 1858).

daypart

A number indicating which part of the day. This number should be filled and compared with the following subroutines, with self-documenting names:

  • before-sunrise()

  • daylight()

  • after-sunset()

month-name

The month of the date, as a string.

month-abbr

The month of the date, as a 3-char string.

day-name

The name of the day within the week.

day-of-week

The number of the day within the week (1 for Sunday / Yaum al-Ahad, 7 for Saturday / Yaum al-Sabt).

week-number

The number of the week within the year, 1 to 50 or 1 to 51. Similar to the "ISO date" as defined for Gregorian date. Week number 1 is the Sun→Sat span that contains the first Wednesday / Yaum al-Arbi'a of the year, week number 2 is the Sun→Sat span that contains the second Wednesday / Yaum al-Arbi'a of the year and so on.

week-year

Mostly similar to the year attribute. Yet, the last days of the year and the first days of the following year can be sort-of transferred to the other year. The week-year attribute reflects this transfer. While the real year always begins on 1st Muharram and ends on the 29th or 30th Thu al-Hijjah, the week-year always begins on Sunday / Yaum al-Ahad and it always ends on Saturday / Yaum al-Sabt.

day-of-year

How many days since the beginning of the year. 1 to 354 on normal years, 1 to 355 on leap years.

Other Methods

to-date

Clones the date into a core class Date object or some Date::Calendar::xxx compatible calendar class. The target class name is given as a positional parameter. This parameter is optional, the default value is "Date" for the Gregorian calendar.

To convert a date from a calendar to another, you have two conversion styles, a "push" conversion and a "pull" conversion. For example, while converting "11 Jumaada al-Awal 1446" to the French Revolutionary calendar, you can code:


use Date::Calendar::Hijri;
use Date::Calendar::FrenchRevolutionary;

my  Date::Calendar::Hijri               $d-orig;
my  Date::Calendar::FrenchRevolutionary $d-dest-push;
my  Date::Calendar::FrenchRevolutionary $d-dest-pull;

$d-orig .= new(year  => 1446
             , month =>    5
             , day   =>   11);
$d-dest-push  = $d-orig.to-date("Date::Calendar::FrenchRevolutionary");
$d-dest-pull .= new-from-date($d-orig);
say $d-orig, ' ', $d-dest-push, ' ', $d-dest-pull;
# --> "1446-05-11 0233-02-23 0233-02-23"

When converting from the core class Date, use the pull style. When converting to the core class Date, use the push style. When converting from any class other than the core class Date to any other class other than the core class Date, use the style you prefer. For the Gregorian calendar, instead of the core class Date, you can use the child class Date::Calendar::Gregorian which allows both push and pull styles.

strftime

This method is very similar to the homonymous functions you can find in several languages (C, shell, etc). It also takes some ideas from printf-similar functions. For example


$df.strftime("%04d blah blah blah %-25B")

will give the day number padded on the left with 2 or 3 zeroes to produce a 4-digit substring, plus the substring " blah blah blah ", plus the month name, padded on the right with enough spaces to produce a 25-char substring. Thus, the whole string will be at least 42 chars long. By the way, you can drop the "at least" mention, because the longest month name is 17-char long, so the padding will always occur and will always include at least 8 spaces.

A strftime specifier consists of:

  • A percent sign,

  • An optional minus sign, to indicate on which side the padding occurs. If the minus sign is present, the value is aligned to the left and the padding spaces are added to the right. If it is not there, the value is aligned to the right and the padding chars (spaces or zeroes) are added to the left.

  • An optional zero digit, to choose the padding char for right-aligned values. If the zero char is present, padding is done with zeroes. Else, it is done wih spaces.

  • An optional length, which specifies the minimum length of the result substring.

  • An optional "E" or "O" modifier. On some older UNIX system, these were used to give the extended or localized version of the date attribute. Here, they rather give alternate variants of the date attribute. Not used with the Hijri calendar.

  • A mandatory type code.

The allowed type codes are:

%A

The full day of week name.

%b

The abbreviated month name.

%B

The full month name.

%d

The day of the month as a decimal number (range 01 to 30).

%e

Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space.

%f

The month as a decimal number (1 to 12). Unlike %m, a leading zero is replaced by a space.

%F

Equivalent to %Y-%m-%d (the ISO 8601 date format)

%G

The "week year" as a decimal number. Mostly similar to %Y, but it may differ on the very first days of the year or on the very last days. Analogous to the year number in the so-called "ISO date" format for Gregorian dates.

%j

The day of the year as a decimal number (range 001 to 355).

%m

The month as a two-digit decimal number (range 01 to 12), including a leading zero if necessary.

%n

A newline character.

%Ep

Gives a 1-char string representing the day part:

  • ☾ or U+263E before sunrise,

  • ☼ or U+263C during daylight,

  • ☽ or U+263D after sunset.

Rationale: in C or in other programming languages, when strftime deals with a date-time object, the day is split into two parts, before noon and after noon. The %p specifier reflects this by giving a "AM" or "PM" string.

The 3-part splitting in the Date::Calendar::xxx may be considered as an alternate splitting of a day. To reflect this in strftime, we use an alternate version of %p, therefore %Ep.

%t

A tab character.

%u

The day of week as a 1..7 number.

%V

The week number as defined above, similar to the week number in the so-called "ISO date" format for Gregorian dates.

%Y

The year as a decimal number.

%%

A literal `%' character.

PROBLEMS AND KNOWN BUGS

As already stated, this module does not give the real Hijri dates, but dates from a variant calendar which follows closely, but imperfectly, the Hijri calendar.

The month names and the day names are transcribed from the Arabic script to the Latin script. There are several methods for this transcription. So the names in this module may differ from the transcribed names you find in other places.

Security issues

Another issue, as explained in the Date::Calendar::Strftime documentation. Please ensure that format-string passed to strftime comes from a trusted source. For example, by including a outrageous length in a strftime specifier, an untrusted source can drain your PC's RAM very fast.

Relations with :ver<0.0.x> classes and with core class Date

Version 0.1.0 (and API 1) was introduced to ease the conversions with other calendars in which the day is defined as midnight-to-midnight. If all Date::Calendar::xxx classes use version 0.1.x and API 1, the conversions will be correct. But if some Date::Calendar::xxx classes use version 0.0.x and API 0, there might be problems.

A date from a 0.0.x class has no daypart attribute. But when "seen" from a 0.1.x class, the 0.0.x date seems to have a daypart attribute equal to daylight. When converted from a 0.1.x class to a 0.0.x class, the date may just shift from after-sunset (or before-sunrise) to daylight, or it may shift to the daylight part of the prior (or next) date. This means that a roundtrip with cascade conversions may give the starting date, or it may give the date prior or after the starting date.

If you install <Date::Calendar::Hijri:ver<0.1.0>>, why would you refrain from upgrading other Date::Calendar::xxxx classes? So actually, this issue applies mainly to the core class Date, because you may prefer avoiding the installation of Date::Calendar::Gregorian.

Time

This module and the Date::Calendar::xxx associated modules are still date modules, they are not date-time modules. The user has to give the daypart attribute as a value among before-sunrise, daylight or after-sunset. There is no provision to give a HHMMSS time and convert it to a daypart parameter.

SEE ALSO

Raku Software

Date::Calendar::Strftime or https://github.com/jforget/raku-Date-Calendar-Strftime

Date::Calendar::Gregorian or https://github.com/jforget/raku-Date-Calendar-Gregorian

Date::Calendar::Julian or https://github.com/jforget/raku-Date-Calendar-Julian

Date::Calendar::Hebrew or https://github.com/jforget/raku-Date-Calendar-Hebrew

Date::Calendar::CopticEthiopic or https://github.com/jforget/raku-Date-Calendar-CopticEthiopic

Date::Calendar::MayaAztec or https://github.com/jforget/raku-Date-Calendar-MayaAztec

Date::Calendar::FrenchRevolutionary or https://github.com/jforget/raku-Date-Calendar-FrenchRevolutionary

Date::Calendar::Persian or https://github.com/jforget/raku-Date-Calendar-Persian

Date::Calendar::Bahai or https://github.com/jforget/raku-Date-Calendar-Bahai

Perl 5 Software

Date::Hijri

DateTime

DateTime::Calendar::Hijri

Date::Hijri::Simple

Date::Converter

Other Software

date(1), strftime(3)

calendar/cal-islam.el in emacs or xemacs.

CALENDRICA 4.0 -- Common Lisp, which can be download in the "Resources" section of https://www.cambridge.org/us/academic/subjects/computer-science/computing-general-interest/calendrical-calculations-ultimate-edition-4th-edition?format=PB&isbn=9781107683167 (Actually, I have used the 3.0 version which is not longer available)

https://api.kde.org/4.14-api/kdelibs-apidocs/kdecore/html/kcalendarsystemislamiccivil_8cpp_source.html Since the KDE version number will change, you should rather use a search engine: https://html.duckduckgo.com/html?q=calendarsystemislamiccivil%20KDElibs

Books

Calendrical Calculations (Third or Fourth Edition) by Nachum Dershowitz and Edward M. Reingold, Cambridge University Press, see http://www.calendarists.com or https://www.cambridge.org/us/academic/subjects/computer-science/computing-general-interest/calendrical-calculations-ultimate-edition-4th-edition?format=PB&isbn=9781107683167.

La saga des calendriers, by Jean Lefort, published by Belin (Pour la Science), ISBN 2-90929-003-5 See https://www.belin-editeur.com/la-saga-des-calendriers (website no longer responding).

Internet

Claus Tøndering's FAQ.

https://www.funaba.org/cc (website no longer working).

https://en.wikipedia.org/wiki/Islamic_calendar

AUTHOR

Jean Forget <J2N-FORGET at orange dot fr>

COPYRIGHT AND LICENSE

Copyright 2021, 2024 (c) Jean Forget, all rights reserved

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Date::Calendar::Hijri v0.1.0

Arithmetic Variant of the Hijri Calendar

Authors

  • Jean Forget

License

Artistic-2.0

Dependencies

Date::Calendar::Strftime

Test Dependencies

Provides

  • Date::Calendar::Hijri
  • Date::Calendar::Hijri::Names

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.