Skip to content
Laravel Rust Packagev1.0.0MIT LicenseAI Ready

Laravel Rust Hijri

Hijri (Islamic) dates for Laravel Rust applications. Register one service provider, set the day adjustment, format, language and time zone with HIJRI_* environment variables, and print Hijri dates in your MiniJinja views with the hijri filter. Forms validate Hijri dates with HijriDateRule, models store Hijri dates with the AsHijri column, and handlers convert dates with the same settings. The calendar comes from the Pharaonic Hijri crate, and the package is the Laravel Rust counterpart of Laravel Hijri.

AI Ready

Hijri ships an agent guideline for your AGENTS.md and a hijri-development skill for .agents/skills/, so Claude Code, Cursor, Codex or Amp write correct Hijri filters, rules, model columns and conversions. See AI Ready.

Template Filter

{{ post.created_at|hijri }} prints a Hijri date in any MiniJinja view.

Validation Rule

Accept only YYYY-MM-DD Hijri dates that exist in the calendar.

Environment Configuration

Adjustment, format, language and time zone, each with a default.

Arabic and English Months

Month names in Arabic or English, per application or per date.

AI Ready

An agent guideline and a hijri-development skill, bundled in the crate.

Model Columns

AsHijri stores the Gregorian date and reads it back as Hijri.

Quick Tip

Laravel Rust works in UTC. If your users live in Riyadh or Cairo, set HIJRI_TIMEZONE, so a post created at 23:30 UTC shows the Hijri date of their day, not of the day in London.

#Installation

Add the package with Cargo, then register its service provider.

#Requirements

  • Rust 1.99 or newer (the package's rust-version, the same as the framework's)
  • Laravel Rust 0.1.4 or later, below 2.0
  • MiniJinja views, only for the hijri template filter

#Cargo Installation

Applications that render MiniJinja views enable the minijinja feature, which adds the template filter:

Terminal
cargo add pharaonic-laravel-hijri --features minijinja

Inertia applications that don't render MiniJinja views leave it out:

Terminal
cargo add pharaonic-laravel-hijri

Add the database feature for model columns:

Terminal
cargo add pharaonic-laravel-hijri --features minijinja,database

Or add the dependency to Cargo.toml yourself:

Cargo.toml
1[dependencies]
2pharaonic-laravel-hijri = { version = "1", features = ["minijinja", "database"] }

#Register the Service Provider

Laravel Rust doesn't discover packages automatically. Add the provider in src/app.rs:

src/app.rs
1use laravel::Application;
2use pharaonic_laravel_hijri::HijriServiceProvider;
3 
4pub fn configure() -> laravel::foundation::ApplicationBuilder {
5 Application::configure()
6 .with_providers(|providers| {
7 providers.add(HijriServiceProvider);
8 })
9}
Installation Complete

You're all set! The defaults work without any configuration: English month names, the -1 day adjustment, and UTC. See Configuration to change them.

#Configuration

The package reads four environment variables into its HijriConfig section. Each has a default, so you only set the ones you want to change.

VariableFieldDefaultDescription
HIJRI_ADJUSTMENTadjustment-1Days added to every conversion from a Gregorian date, to follow local moon sighting
HIJRI_FORMATformat%-d %B %YThe default format of the hijri filter
HIJRI_LANGUAGElanguageenMonth names: ar or en (also arabic or english, in any case)
HIJRI_TIMEZONEtimezoneUTCThe time zone a timestamp is read in before it becomes a date

For an Arabic site in Saudi Arabia, your .env might read:

.env
1HIJRI_ADJUSTMENT=0
2HIJRI_LANGUAGE=ar
3HIJRI_TIMEZONE=Asia/Riyadh

#The Day Adjustment

The calendar is tabular: it computes months instead of following moon sighting, so it can be a day or two off your local calendar. HIJRI_ADJUSTMENT shifts every conversion from a Gregorian date by whole days. The default -1 matches the Laravel (PHP) package and Pharaonic Hijri; 0 uses the tabular calendar as it is.

#Formats

HIJRI_FORMAT uses the strftime directives of Pharaonic Hijri:

DirectiveOutput
%Yyear, at least four digits: 1445
%ylast two digits of the year: 45
%m / %-mmonth: 09 / 9
%d / %-d / %eday: 05 / 5 / 5
%jday of the year, three digits: 247
%Bmonth name in the language: Ramadan
%%a literal %

Weekday directives such as %A aren't supported, because the weekday belongs to the Gregorian date.

#Changing Settings in Code

Package settings load before your application's, so you may change any field in src/app.rs:

src/app.rs
1use laravel::Application;
2use pharaonic_laravel_hijri::{HijriConfig, HijriServiceProvider, Language};
3 
4pub fn configure() -> laravel::foundation::ApplicationBuilder {
5 Application::configure()
6 .with_providers(|providers| {
7 providers.add(HijriServiceProvider);
8 })
9 .with_config(|config, _| {
10 config.section_mut::<HijriConfig>().language = Language::Arabic;
11 })
12}
Checked at Startup

An unknown HIJRI_LANGUAGE stops the application when it's created. An unsupported directive in HIJRI_FORMAT or an unknown HIJRI_TIMEZONE stops it at boot, with a message that names the variable, before it serves a request.

#Basic Usage

With the provider registered and the minijinja feature on, print a Hijri date in any view with the hijri filter:

resources/views/posts/show.html
1<time datetime="{{ post.created_at }}">{{ post.created_at|hijri }}</time>

A post created on 11 March 2024 shows 1 Ramadan 1445, or 1 رَمضان 1445 with HIJRI_LANGUAGE=ar.

Validate a Hijri date in a form with HijriDateRule:

src/http/requests.rs
1use pharaonic_laravel_hijri::HijriDateRule;
2 
3#[laravel::input]
4#[validate(anyone)]
5pub struct StoreEvent {
6 #[validate(required, HijriDateRule)]
7 pub starts_on: String,
8}

And convert dates in a handler with the configured adjustment:

src/http/controllers/events.rs
1use laravel::config::Section;
2use laravel::time::civil::date;
3use pharaonic_laravel_hijri::HijriConfig;
4 
5pub async fn ramadan(hijri: Section<HijriConfig>) -> laravel::Result<String> {
6 let date = hijri.converter().to_hijri(date(2024, 3, 11))?;
7 
8 assert_eq!(date.to_string(), "1445-09-01");
9 
10 Ok(date.strftime(&hijri.format, hijri.language)?)
11}

The next sections cover each part in detail.

#Template Filter

The minijinja feature registers a hijri filter for your MiniJinja views. It takes a Gregorian date and prints its Hijri date with your configuration.

resources/views/posts/show.html
1{{ post.created_at|hijri }}

#What It Accepts

The filter reads the text that Laravel Rust's date and time types serialize to:

ValueExampleDate used
A date (civil::Date)2024-03-11that date
A date and time (civil::DateTime)2024-03-11T09:30:00its date
A timestamp (Timestamp)2024-03-10T23:30:00Zits date in HIJRI_TIMEZONE
A zoned date-time (ZonedDateTime)2024-03-10T20:00:00-05:00[America/Chicago]its date in its own time zone
none or an undefined variableprints nothing

Anything else, such as 11/03/2024 or a number, is a template error, so a mistake shows up in development instead of printing a wrong date. A Hijri date string such as 1445-09-01 is read as a Gregorian date, so pass Gregorian values to the filter.

#Options

Pass a format as the first argument, and language or adjustment by name. Each one overrides the configuration for that date only:

resources/views/events/show.html
1{{ event.starts_at|hijri("%Y/%m/%d") }} {# 1445/09/01 #}
2{{ event.starts_at|hijri(language="ar") }} {# 1 رَمضان 1445 #}
3{{ event.starts_at|hijri("%-d %B", adjustment=0) }} {# 2 Ramadan #}

language takes the same values as HIJRI_LANGUAGE. An unknown option name is a template error.

#Machine-Readable Dates

Wrap the Hijri date in a <time> element so browsers, search engines and screen readers get the Gregorian date too:

resources/views/posts/show.html
1<time datetime="{{ post.published_on }}">{{ post.published_on|hijri }}</time>
Without the Feature

Without minijinja, the provider registers no filter, and a view that uses |hijri fails to render. Enable the feature in Cargo.toml if your application renders MiniJinja views.

#Validation

HijriDateRule accepts a Hijri date in the YYYY-MM-DD format that exists in the calendar, such as 1445-09-01 or 1445-9-1. Put it on a String field of a validated struct:

src/http/requests.rs
1use pharaonic_laravel_hijri::HijriDateRule;
2 
3#[laravel::input]
4#[validate(anyone)]
5pub struct StoreEvent {
6 #[validate(required, HijriDateRule)]
7 pub starts_on: String,
8 #[validate(HijriDateRule)]
9 pub ends_on: Option<String>,
10}

It rejects 1445-02-30 (Safar 1445 has 29 days), 1445-13-01 and 01/09/1445. Like most rules, it skips a missing or blank field, so add required when the date must be there.

#Reading the Date

The handler receives the validated text. Parse it into a HijriDate; the rule already checked it, so parsing succeeds:

src/http/controllers/events.rs
1use laravel::prelude::*;
2use pharaonic_laravel_hijri::{HijriDate, HijriDateRule};
3 
4#[laravel::input]
5#[validate(anyone)]
6pub struct StoreEvent {
7 #[validate(required, HijriDateRule)]
8 pub starts_on: String,
9}
10 
11pub async fn store(Valid(event): Valid<StoreEvent>) -> laravel::Result<String> {
12 let starts_on: HijriDate = event.starts_on.parse()?;
13 let gregorian = starts_on.to_gregorian()?;
14 
15 Ok(format!("The event starts on {gregorian}"))
16}

#The Message

A failed check reads "The starts on field must be a valid Hijri date." Replace it for one field with .message(...), which may use the :attribute placeholder:

src/http/requests.rs
1use pharaonic_laravel_hijri::HijriDateRule;
2 
3#[laravel::input]
4#[validate(anyone)]
5pub struct StoreEvent {
6 #[validate(required, HijriDateRule.message("Enter the :attribute as YYYY-MM-DD, such as 1445-09-01."))]
7 pub starts_on: String,
8}
Arabic Messages

Laravel Rust has no translation files yet, so the built-in message is English. Use .message(...) to show it in Arabic.

#Models

With the database feature, AsHijri is a model column that holds a Hijri date, the counterpart of Laravel Hijri's AsHijri cast. The database keeps the Gregorian date in a date column, so other applications and reports still read a normal date, and your model reads it back as a Hijri date.

Cargo.toml
1[dependencies]
2pharaonic-laravel-hijri = { version = "1", features = ["database"] }

#Declaring the Column

Create a date column in the migration:

database/migrations/2026_12_02_000000_create_events_table.rs
1use laravel::db::AnyTransaction;
2 
3pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
4 tx.schema()
5 .create("events", |table| {
6 table.id();
7 table.string("name");
8 table.date("starts_on");
9 table.date("ends_on").nullable();
10 })
11 .await
12}

Then declare the field as AsHijri, or Option<AsHijri> for a nullable column:

src/models/event.rs
1use laravel::model::model;
2use pharaonic_laravel_hijri::AsHijri;
3 
4#[model]
5pub struct Event {
6 pub id: i64,
7 pub name: String,
8 pub starts_on: AsHijri,
9 pub ends_on: Option<AsHijri>,
10}

#Creating Rows

Build the value from a Hijri date with AsHijri::new, or from a Gregorian date with AsHijri::from_gregorian. Both take a converter; pass the configured one so the stored date follows HIJRI_ADJUSTMENT:

src/http/controllers/events.rs
1use laravel::config::Section;
2use laravel::model::{create, model};
3use pharaonic_laravel_hijri::{AsHijri, HijriConfig, HijriDate};
4 
5#[model]
6pub struct Event {
7 pub id: i64,
8 pub name: String,
9 pub starts_on: AsHijri,
10 pub ends_on: Option<AsHijri>,
11}
12 
13pub async fn store(hijri: Section<HijriConfig>) -> laravel::Result<String> {
14 let starts_on = AsHijri::new(HijriDate::new(1445, 9, 1)?, hijri.converter())?;
15 
16 let event = create!(Event {
17 name: "Ramadan".to_owned(),
18 starts_on,
19 ends_on: None,
20 })
21 .await?;
22 
23 Ok(format!("Stored {}", event.starts_on.gregorian())) // "Stored 2024-03-11"
24}

#Reading Rows

Reading a row converts the stored Gregorian date with the configured HIJRI_ADJUSTMENT. hijri() returns the HijriDate and gregorian() the stored date:

src/http/controllers/events.rs
1use laravel::model::model;
2use pharaonic_laravel_hijri::{AsHijri, Language};
3 
4#[model]
5pub struct Event {
6 pub id: i64,
7 pub name: String,
8 pub starts_on: AsHijri,
9 pub ends_on: Option<AsHijri>,
10}
11 
12pub async fn show(id: i64) -> laravel::Result<String> {
13 let event = Event::find_or_fail(id).await?;
14 
15 assert_eq!(event.starts_on.to_string(), "1445-09-01");
16 
17 Ok(event.starts_on.hijri().strftime("%-d %B %Y", Language::English)?) // "1 Ramadan 1445"
18}

Changing HIJRI_ADJUSTMENT later changes how stored rows read, never the stored dates, as with the Laravel (PHP) package.

#Filtering

Compare the column with an AsHijri value; the query compares the Gregorian dates:

src/http/controllers/events.rs
1use laravel::model::model;
2use pharaonic_laravel_hijri::{AsHijri, Converter, HijriDate};
3 
4#[model]
5pub struct Event {
6 pub id: i64,
7 pub name: String,
8 pub starts_on: AsHijri,
9 pub ends_on: Option<AsHijri>,
10}
11 
12pub async fn first_of_ramadan() -> laravel::Result<Vec<Event>> {
13 let day = AsHijri::new(HijriDate::new(1445, 9, 1)?, Converter::default())?;
14 
15 Ok(Event::query().filter(Event::starts_on.eq(day)).get().await?)
16}

#JSON and Inertia

In JSON and Inertia responses, the column is its Hijri date as YYYY-MM-DD, such as "starts_on": "1445-09-01", the same as the AsHijri cast. A None column is null.

Forms

Validated input fields can't be AsHijri. Validate the field as a String with HijriDateRule, parse it into a HijriDate, then build the column with AsHijri::new.

Inside the Application

Reading an AsHijri column needs the application's configuration, which every query inside a handler, job or command has. Reading one elsewhere, such as in a task started with tokio::spawn, returns an error. Use laravel::task::spawn instead.

#Dates in Your Code

The package re-exports the Pharaonic Hijri types, HijriDate, Converter, Language and Error, so you don't need a second dependency to work with Hijri dates in handlers, jobs and commands.

#Reading the Configuration

Take the configuration as a Section<HijriConfig> argument in a handler, or read it with laravel::config().section::<HijriConfig>() anywhere else, such as in a job or a command. converter() returns a Converter with the configured adjustment:

src/support/calendar.rs
1use laravel::time::civil::Date;
2use pharaonic_laravel_hijri::{Error, HijriConfig};
3 
4pub fn hijri_label(date: Date) -> Result<String, Error> {
5 let config = laravel::config();
6 let hijri = config.section::<HijriConfig>();
7 let hijri_date = hijri.converter().to_hijri(date)?;
8 
9 hijri_date.strftime(&hijri.format, hijri.language)
10}

HijriDate::from_gregorian() always uses the default adjustment of -1. Use the configured converter when HIJRI_ADJUSTMENT matters.

#Timestamps

A Timestamp, such as a model's created_at, is an instant without a date. Read it in your time zone first, then convert the date:

src/http/controllers/posts.rs
1use laravel::time::Timestamp;
2use laravel::time::tz::TimeZone;
3use pharaonic_laravel_hijri::{HijriConfig, HijriDate};
4 
5pub fn published_on(config: &HijriConfig, created_at: Timestamp) -> laravel::Result<HijriDate> {
6 let time_zone = TimeZone::get(&config.timezone)?;
7 let date = created_at.to_zoned_datetime(time_zone).date();
8 
9 Ok(config.converter().to_hijri(date)?)
10}

#Errors

The Pharaonic Hijri Error converts into laravel::Error, so ? works in handlers. Its variants are InvalidDate, OutOfRange, Parse, UnknownDirective and UnknownLanguage; see the Pharaonic Hijri docs for when each happens, and for Hijri date math and formatting.

#Cargo Features

FeatureDefaultEnables
databaseoffThe AsHijri model column, and the framework's database feature
minijinjaoffThe hijri template filter, and the framework's minijinja feature

Without features, the package still registers its configuration, checks it at startup, and provides HijriDateRule and the re-exported types. Turn on the features your application uses:

Cargo.toml
1[dependencies]
2pharaonic-laravel-hijri = { version = "1", features = ["database", "minijinja"] }

The package itself depends on Laravel Rust with its default features off, so it never adds Inertia or MiniJinja to your application unless you ask for them. database doesn't pick a database either: your application's database-postgres, database-mysql or database-sqlite feature does.

#AI Ready

Hijri is AI ready. The crate ships an agent guideline and an Agent Skill in the same format as the AGENTS.md and .agents/skills/ of every new Laravel Rust application, so the coding agent working on your application (Claude Code, Cursor, Codex, Amp, Copilot…) knows how to use the package.

#Install

Laravel Rust doesn't discover package resources, so copy them once from the installed crate. Run this from your application's root (it needs jq):

Terminal
hijri="$(cargo metadata --format-version 1 --locked | jq -r '.packages[] | select(.name == "pharaonic-laravel-hijri") | .manifest_path | rtrimstr("/Cargo.toml")')/resources/agents"
mkdir -p .agents/skills
cp -R "$hijri/skills/hijri-development" .agents/skills/
cat "$hijri/guidelines.md" >> AGENTS.md

The skill lands next to the framework's skills in .agents/skills/hijri-development/, and the guideline becomes a ## Hijri dates section at the end of AGENTS.md, which the application's CLAUDE.md already imports. Commit both, so every agent session and every teammate gets them.

#What the Agent Learns

ResourceLoadedCovers
Guideline (resources/agents/guidelines.md)In every session, as part of AGENTS.mdThe provider, the HIJRI_* settings, config.converter(), the hijri filter, HijriDateRule and AsHijri, with one example
Skill hijri-developmentWhen the agent shows, validates, stores or converts Hijri datesSetup and features, every setting, converting dates, the filter options, the rule, model columns, pitfalls and testing

#After an Update

When you update the crate, run the cp -R line again to refresh the skill. Compare the ## Hijri dates section of your AGENTS.md with the new guidelines.md and replace it if it changed, instead of appending it twice.

Edit Your Copy

The copies belong to your application. Add your own conventions to them, such as which models use AsHijri or the format your designers chose, the way the framework suggests for its own skills.

#API Reference

Everything below is exported from the crate root, pharaonic_laravel_hijri. The full reference is on docs.rs.

#HijriServiceProvider

ItemDescription
HijriServiceProviderUnit struct implementing laravel::foundation::ServiceProvider. Register it with providers.add(HijriServiceProvider)
config()Loads HijriConfig from the environment
register()With minijinja, registers the hijri filter
boot()Fails startup when HIJRI_FORMAT or HIJRI_TIMEZONE is invalid

#HijriConfig

A #[non_exhaustive] configuration section (Debug, Clone, Default). Read it with Section<HijriConfig> or config().section::<HijriConfig>(), and change it with section_mut::<HijriConfig>().

Field / MethodTypeDescription
adjustmenti32HIJRI_ADJUSTMENT, default -1
formatStringHIJRI_FORMAT, default %-d %B %Y
languageLanguageHIJRI_LANGUAGE, default Language::English
timezoneStringHIJRI_TIMEZONE, default UTC
converter(&self)ConverterA converter with the configured adjustment

#HijriDateRule

ItemDescription
HijriDateRuleUnit struct implementing laravel::validation::ValidationRule. Accepts YYYY-MM-DD Hijri dates that exist; message "The :attribute field must be a valid Hijri date."

#hijri Filter

UsageDescription
value|hijriFormats with HIJRI_FORMAT, HIJRI_LANGUAGE and HIJRI_ADJUSTMENT
value|hijri("%Y/%m/%d")Another format
value|hijri(language="ar")Another language: ar, en, arabic, english
value|hijri(adjustment=0)Another adjustment

#AsHijri

With the database feature. A Copy value (Debug, Clone, PartialEq, Eq, Hash, Display, Serialize) for a date column.

MethodDescriptionReturns
AsHijri::new(hijri, converter)From a Hijri date; finds the Gregorian date with the converterResult<AsHijri, Error>
AsHijri::from_gregorian(date, converter)From a Gregorian date (impl Into<civil::Date>)Result<AsHijri, Error>
hijri(self)The Hijri dateHijriDate
gregorian(self)The stored Gregorian datecivil::Date
to_string()The Hijri date as YYYY-MM-DDString

AsHijri converts into HijriDate and civil::Date with From. Rows decode with the configured HIJRI_ADJUSTMENT, and JSON serializes the Hijri YYYY-MM-DD.

#Re-exports from Pharaonic Hijri

TypeDescription
HijriDateA Hijri date: conversion, date math, strftime, parsing
ConverterConverts between calendars with an adjustment
LanguageArabic or English; parses from ar/en
ErrorInvalidDate, OutOfRange, Parse, UnknownDirective, UnknownLanguage

Their methods are documented in the Pharaonic Hijri API reference.

#Coming from Laravel Hijri

The package follows the Laravel (PHP) package where the framework allows it. The differences:

Laravel Hijri (PHP)Laravel Rust Hijri
HIJRI_ADJUSTMENT, default -1The same variable and default
config('pharaonic.hijri.format') with ISO tokens, D MMMM YYYYHIJRI_FORMAT with strftime directives, %-d %B %Y
The application locale picks the languageHIJRI_LANGUAGE, because Laravel Rust has no application locale
@hijri($post->created_at) Blade directive{{ post.created_at|hijri }} MiniJinja filter
<x-hijri-date :date="$date" /> component<time datetime="{{ date }}">{{ date|hijri }}</time>
new HijriDateRule#[validate(HijriDateRule)]
English and Arabic validation messagesAn English message, replaceable with .message(...)
A global adjustment set at bootNo global state: HijriConfig::converter() carries the adjustment
'starts_on' => AsHijri::class caststarts_on: AsHijri model field, with the database feature
Carbon mixinThe methods of HijriDate

A YYYY-MM-DD date gives the same Hijri date in both packages with the same adjustment.

#Examples

#1. Hijri Dates on Blog Posts

Show when each post was published, in the reader's calendar:

src/http/controllers/posts.rs
1use laravel::prelude::*;
2use laravel::time::Timestamp;
3use serde::Serialize;
4 
5#[derive(Serialize)]
6pub struct Post {
7 pub title: String,
8 pub created_at: Timestamp,
9}
10 
11pub async fn index() -> laravel::Result<Response> {
12 let posts = vec![Post {
13 title: "Ramadan Kareem".to_owned(),
14 created_at: "2024-03-10T23:30:00Z".parse()?,
15 }];
16 
17 Ok(view("posts.index", data! { posts }).into_response())
18}
resources/views/posts/index.html
1{% for post in posts %}
2 <article>
3 <h2>{{ post.title }}</h2>
4 <time datetime="{{ post.created_at }}">{{ post.created_at|hijri }}</time>
5 </article>
6{% endfor %}
.env
1HIJRI_LANGUAGE=ar
2HIJRI_TIMEZONE=Asia/Riyadh

With these settings, the post shows 1 رَمضان 1445: 23:30 UTC on 10 March is already 11 March in Riyadh.

#2. Booking a Date in the Hijri Calendar

Let users book by Hijri date and store the Gregorian date:

src/http/controllers/bookings.rs
1use laravel::prelude::*;
2use pharaonic_laravel_hijri::{HijriDate, HijriDateRule};
3 
4#[laravel::input]
5#[validate(anyone)]
6pub struct StoreBooking {
7 #[validate(required, HijriDateRule)]
8 pub day: String,
9}
10 
11pub async fn store(Valid(booking): Valid<StoreBooking>) -> laravel::Result<String> {
12 let day: HijriDate = booking.day.parse()?;
13 let gregorian = day.to_gregorian()?;
14 
15 Ok(format!("Booked for {gregorian}"))
16}

#3. Both Calendars Side by Side

Show the Hijri date in Arabic next to the Gregorian date:

resources/views/events/show.html
1<p>
2 {{ event.starts_on }}
3 ({{ event.starts_on|hijri("%-d %B %Y هـ", language="ar") }})
4</p>

For 2024-04-10, this prints 2024-04-10 (1 شوّال 1445 هـ).

#4. A Ramadan Countdown

Count the days to the next Ramadan in a handler, with the configured adjustment:

src/http/controllers/ramadan.rs
1use laravel::config::Section;
2use pharaonic_laravel_hijri::{HijriConfig, HijriDate};
3 
4pub async fn countdown(hijri: Section<HijriConfig>) -> laravel::Result<String> {
5 let converter = hijri.converter();
6 let today = converter.to_hijri(laravel::time::today())?;
7 
8 let year = if today.month() < 9 { today.year() } else { today.year() + 1 };
9 let ramadan = HijriDate::new(year, 9, 1)?;
10 
11 Ok(format!("{} days until Ramadan {year}", today.days_until(ramadan)))
12}

#Troubleshooting

#A view fails because the hijri filter is unknown

The filter is behind the minijinja feature. Enable it in Cargo.toml (features = ["minijinja"]) and make sure HijriServiceProvider is registered in src/app.rs.

#The application doesn't start: "HIJRI_FORMAT ... is invalid"

The format has a directive Pharaonic Hijri doesn't support, often a weekday (%A, %a) or a time (%H). See Formats for the supported directives, and format the weekday from the Gregorian date instead.

#The application doesn't start: "HIJRI_TIMEZONE ... is invalid"

Use an IANA time zone name, such as Asia/Riyadh, Africa/Cairo or UTC. Abbreviations such as AST aren't time zone names.

#The application doesn't start because of HIJRI_LANGUAGE

HIJRI_LANGUAGE accepts ar, en, arabic or english, in any case. Locale tags such as ar-SA aren't accepted.

#Dates are one day off

Either the adjustment doesn't match your local calendar, or a timestamp is read in UTC. Set HIJRI_ADJUSTMENT (0 for the tabular calendar, -1 by default) and HIJRI_TIMEZONE to your users' time zone.

#"hijri expects a date, a date-time or a timestamp"

The filter received text that isn't one of the shapes in Template Filter, such as 11/03/2024, or an empty string. Pass the model's date or timestamp field itself, or use none for a missing date.

#A number fails with "must be a string"

Validated fields check their type before their rules. Declare the Hijri date field as String, and send it as text.

#"AsHijri needs pharaonic_laravel_hijri::HijriServiceProvider to be registered"

Reading an AsHijri column uses the package's configuration. Register HijriServiceProvider in src/app.rs.

#"AsHijri can only be read inside the application"

The query ran outside the application, such as in a task started with tokio::spawn. Start the task with laravel::task::spawn, which keeps the application's context.

#The database build fails with "non-exhaustive patterns" errors

Laravel Rust's database feature needs a database backend. Enable database-postgres, database-mysql or database-sqlite on laravel-rust in your application's Cargo.toml.

#Upgrade Guide

#1.x

1.0.0 is the first release of the package. There are no upgrade steps yet.

Coming from the Laravel (PHP) package? See Coming from Laravel Hijri for the mapping and the differences.

Contributors

Amazing people who made this package possible

This package wouldn't exist without the contributions of our amazing community. A huge thank you to everyone who has helped improve Laravel Rust Hijri!

Moamen Eltouny

@MoamenEltouny

8 contributions

Want to Contribute?

We welcome contributions from everyone! Whether it's bug fixes, new features, or documentation improvements - every contribution counts.

Was this page helpful?

Something wrong or missing? Report it on GitHub .