Carbon (Date & Time Management)
The artiframe add carbon command installs the nesbot/carbon package, taking PHP's standard DateTime class to the next level.
It is the industry standard for comparing dates, adding/subtracting time, or generating human-readable formats like "3 days ago" or "1 month later".
💡 Information: Direct Usage
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the
src/Service folder for this package. The installation simply includes the package into the project via Composer.
The codes below are basic usage examples demonstrating the package's native operations. For more information, please review the Carbon Documentation.
Installation
terminal
$ artiframe add carbon
Usage Example
Tip: Carbon respects the language files in your project or your server's
setlocale() configurations. You can use Carbon::setLocale('en'); to force English.
TimeController.php
<?php
use Carbon\Carbon;
// Set language to English
Carbon::setLocale('en');
// 1. Current Time
$now = Carbon::now();
echo $now->toDateTimeString(); // 2026-09-18 10:30:00
// 2. Human-Readable Reading (DiffForHumans)
$registrationDate = Carbon::create(2023, 1, 15);
echo "Registered: " . $registrationDate->diffForHumans(); // e.g., "3 years ago"
// Future calculation
$expiryDate = Carbon::now()->addDays(15);
echo "Membership Expires: " . $expiryDate->diffForHumans(); // "in 15 days"
// 3. Age / Duration Calculation
$birthday = Carbon::parse('1995-05-20');
echo "Your Age: " . $birthday->age; // 31 (based on 2026)
// 4. Time Manipulations
$deadline = Carbon::now()
->addYears(1)
->subMonths(2)
->endOfMonth();
echo "Campaign Deadline: " . $deadline->format('d/m/Y');
// 5. Comparisons
if (Carbon::now()->isWeekend()) {
echo "It's the weekend!";
}
if ($birthday->isPast()) {
echo "Your birthday has passed.";
}