Drupal is a registered trademark of Dries Buytaert

hijri_dates

6 sites No security coverage
View on drupal.org

Hijri Dates provides Drupal sites with Hijri (lunar) calendar support for content dates. It integrates with core field formatters, Views, and Twig templates with automatic language detection and centralized date correction capabilities. Perfect for multilingual sites needing to display dates in both Gregorian and Hijri formats.

Features

  • Field formatters for timestamp, datetime, and daterange fields - works with all core date field types
  • Automatic language detection - displays Arabic or English month names based on the interface language
  • Global date correction - centralized configuration for moon sighting variations with field-level override options
  • Twig integration - filter and function for easy use in custom templates
  • Views compatibility - works with all Views date fields using the same field formatters
  • Developer API - clean service for programmatic date conversion in custom modules

Usage

Field formatters (works in content displays and Views):

  1. Go to Structure > Content types > [Type] > Manage display
  2. Click the gear icon next to any date field
  3. Check "Use Hijri calendar"
  4. Choose to use global correction (default) or set a custom correction
  5. Save the display settings

The module extends the standard Drupal date formatters, so it works anywhere date fields are displayed, including Views, entity displays, and field formatters.

Date Correction:

Global Correction (recommended):

  1. Go to Administration > Configuration > Regional > Hijri Dates Settings
  2. Enter the global date correction value (e.g., "+1 day")
  3. Save configuration

Field-level Correction (for special cases):

  1. In field display settings, uncheck "Use global date correction"
  2. Enter a custom correction value

Common correction values:

+1 day    # Common adjustment
-1 day    # Subtract one day

Twig templates:

{# Using filter syntax #}
{{ node.created.value|hijri }}
{{ node.created.value|hijri('medium') }}
{{ node.created.value|hijri('!Y/m/d', '+1 day') }}

{# Using function syntax #}
{{ hijri(node.created.value, 'medium', '+1 day') }}

PHP integration:

// Get the service
$hijri_service = \Drupal::service('hijri_dates.service');

// Basic usage
$hijri_date = $hijri_service->formatHijri($timestamp);

// With format and correction
$hijri_date = $hijri_service->formatHijri($timestamp, 'medium', '+1 day');

// With custom format
$hijri_date = $hijri_service->formatHijri($timestamp, '!Y/m/d');

// With DateTime objects
$date = new \DateTime('2023-05-15');
$hijri_date = $hijri_service->formatHijri($date);

Format Support

Supports standard PHP date format patterns:

  • l, D - Weekday names (full, short)
  • F, M - Month names (full, short)
  • j, d - Day of month (with/without leading zeros)
  • Y, y - Year (4-digit, 2-digit)
  • H, h, i, s - Time components

Incompatible: S, T, e, I, O, P, Z, c, r, U (timezone and special formats)

Language Handling

  • Arabic interface: Arabic month/day names and numerals (e.g., "٢٢ رجب ١٤٤٦")
  • English interface: Transliterated names and Western numerals (e.g., "Rajab 22, 1446")

Requirements

  • Drupal 9/10
  • ArPHP Library (^7.0.0, automatically installed via Composer)

The module now includes a configuration page at Administration > Configuration > Regional > Hijri Dates Settings for managing global date correction.

Activity

Total releases
3
First release
Jun 2025
Latest release
8 months ago
Release cadence
0 days
Stability
0% stable

Release Timeline

Releases

Version Type Release date
1.0.0-alpha3 Pre-release Jun 22, 2025
1.0.0-alpha2 Pre-release Jun 22, 2025
1.0.0-alpha1 Pre-release Jun 22, 2025