natilosir / verta
This Package helps developers to work with Jalali Datetime class for Laravel Framework PHP
Fund package maintenance!
Requires
- php: ^8.0
- hekmatinasser/jalali: ^8.2.3
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/validation: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^6.23|^7.0|^8.0|^11.0
This package is not auto-updated.
Last update: 2026-07-21 15:11:51 UTC
README
natilosir/verta
The Verta is package for change solar calendar and gregorian together and provide helper function to use date and time.
Verta extend class PHP Datetime and Jalali, compatible with Carbon Package.
This package has been created by Nasser Hekmati under the license of MIT.
Quick view
- Installation
- Usage
- Getters
- Setters
- Formatting
- Modification
- Boundaries
- Compression
- Validation
- Localization
- Validation Request
- Licence
- Contributors
Installation
composer require natilosir/verta
| Laravel Version | Package Version |
|---|---|
| 8.0 | 8.0 |
| 9.0 | 8.2 |
| 10.0 | 8.3 |
| 11.0 | 8.4 |
| 12.0 | 8.5 |
Usage
use verta datetime jalali
echo verta(); //1401-05-24 00:00:00
Gregorian to Jalali
change gregorian to jalali and reverse
echo verta('2022-08-15'); //1401-05-24 00:00:00
jalali to Gregorian
change jalali to gregorian and reverse
echo Verta::parse('1401-05-24 14:12:32')->datetime(); //2022-08-15 00:00:00
Carbon to Jalali
change carbon to jalali and reverse
echo now()->toJalali(); //1401-05-24 00:00:00
Jalali to Carbon
change jalali to gregorian and reverse
echo verta()->toCarbon(); //2022-08-15 00:00:00
Getters
access part of jalali datetime
$v = verta(); // 1396-03-14 14:18:23 echo $v->year; // 1396
Setters
set part of jalali datetime
$v = verta(); // 1396-03-14 14:18:23 echo $v->year = 1395;
Fluent Setters
set multiple part of jalali datetime
$v = verta(); // 1396-03-14 14:18:23 echo $v->setTimeString('12:25:45');
Formatting
show datetime variant datetime
echo verta()->format('Y.m.d'); // 1401.05.24 echo verta()->formatWord('l dS F'); // دوشنبه بیست و چهارم مرداد
Common Formats
show common datetime variant datetime
echo verta()->formatJalaliDatetime(); // output 1395/10/07 14:12:25
Difference for Humans
show difference format readable humans
echo verta('-13 month')->formatDifference(); // 1 سال قبل
Modification
manipulate jalali datetime
echo verta()->addWeeks(3); ...
Boundaries
get boundary jalali datetime
echo verta()->startWeek(3);
Compression
get compression jalali datetime
echo verta('+2 day')->gte('2022-08-15');
Difference
calculate difference two jalali datetime
echo verta('+13 day')->diffMonths('2022-08-15');
Validation
check datetime check is valid
echo Verta::isLeapYear(1394); // false
Localization
set language for formatting datetime
Verta::setLocale('ar');
Validation Request
validation input form
'birthday' => ['required', 'jdate_before_equal']
Fluent Builder
The Fluent Builder allows you to construct a date step‑by‑step using a fluent interface. You can specify each component (year, month, day, hour, minute, second) and then call make() to build the final Verta instance.
Creating from Gregorian (fromCarbon)
Verta::fromCarbon()without arguments returns a builder that treats values as Gregorian.- You can also pass an existing
Carboninstance to directly create aVertaand also populate the builder properties.
use Hekmatinasser\Verta\Verta; // Build a Gregorian date and convert to Jalali $verta = Verta::fromCarbon() ->year(2025) ->month(6) ->day(1) ->hour(14) ->minute(30) ->second(0) ->make(); // Jalali: 1404-03-11 14:30:00 // Using an existing Carbon instance $carbon = Carbon::create(2025, 6, 1); $verta = Verta::fromCarbon($carbon); // Direct conversion with builder values set
Creating from Jalali (fromJalali)
Verta::fromJalali()without arguments returns a builder that treats values as Jalali.- Passing an existing
Vertaclones it and also sets the builder properties.
// Build a Jalali date directly $verta = Verta::fromJalali() ->year(1404) ->month(3) ->day(11) ->hour(14) ->minute(30) ->second(0) ->make(); // 1404-03-11 14:30:00 // Clone an existing Verta with builder properties $original = Verta::createJalali(1404, 3, 11); $cloned = Verta::fromJalali($original);
Smart Conversion (from)
The from() method intelligently converts various input types:
| Input Type | Output |
|---|---|
Verta |
Carbon |
Carbon or DateTimeInterface |
Verta (with builder values set) |
| String (interpreted as Jalali) | Verta (with builder values set) |
$carbon = Verta::from($vertaInstance); // Verta → Carbon $verta = Verta::from(Carbon::now()); // Carbon → Verta (with builder) $verta = Verta::from('1404-03-11 12:30'); // String → Verta (Jalali)
Builder Methods
The builder provides the following fluent methods:
| Method | Description |
|---|---|
year(int) |
Set the year |
month(int) |
Set the month (1–12) |
day(int) |
Set the day of month |
hour(int) |
Set the hour (0–23) |
minute(int) |
Set the minute (0–59) |
second(int) |
Set the second (0–59) |
make() |
Build and return a Verta instance |
If any component is not set, the following defaults are used:
- Year and month: from the current time (
now()) - Day:
1 - Hour, minute, second:
0
// Only year and month are set – day defaults to 1, time to 00:00:00 $verta = Verta::fromJalali()->year(1404)->month(3)->make();
Public Properties (For Debugging)
After make(), the builder values are copied into public properties (Year, Month, Day, Hour, Minute, Second) for inspection (e.g., when using dd() or debugging). Do not use these properties for calculations – always rely on the getter methods for accurate Jalali values.
$verta = Verta::fromCarbon()->year(2025)->month(6)->make(); echo $verta->Year; // 2025 (Gregorian value as entered) echo $verta->Month; // 6
To retrieve the correct Jalali components, use the getters:
echo $verta->getYear(); // 1404 echo $verta->getMonth(); // 3
Note: The public properties reflect the raw input values (Gregorian or Jalali) and are not automatically converted. They are provided solely for debugging.
Internal Flag: isGregorian
The builder uses a protected property isGregorian to determine how the input values should be interpreted:
true: Values are treated as Gregorian (used byfromCarbon)false: Values are treated as Jalali (used byfromJalali)
This flag is automatically set by the factory methods and does not require manual intervention.
These new features provide a more expressive and flexible way to work with date conversions and constructions in Verta.
Licence
This package has been created by Nasser Hekmati under the license of MIT.
Contributors
Thanks to people who contributed for grow verta.
