hijri_dates
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):
- Go to Structure > Content types > [Type] > Manage display
- Click the gear icon next to any date field
- Check "Use Hijri calendar"
- Choose to use global correction (default) or set a custom correction
- 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):
- Go to Administration > Configuration > Regional > Hijri Dates Settings
- Enter the global date correction value (e.g., "+1 day")
- Save configuration
Field-level Correction (for special cases):
- In field display settings, uncheck "Use global date correction"
- 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.