1. Go to this page and download the library: Download nrngajurel/nepali-calendar library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Carbon\Carbon;
$date = Carbon::create(2024, 4, 13);
$date->toBsArray(); // ['year' => 2081, 'month' => 1, 'day' => 1, 'weekday' => 7]
$date->toBs(); // "2081-01-01" — always BS, ignores mode
$date->toBs('F j, Y'); // "Baishak 1, 2081"
$date->toBs('F j, Y', 'np'); // "बैशाख 1, 2081"
$date->toBs('Y-m-d', 'en', true); // "२०८१-०१-०१" — Devanagari digits
$date->display(); // BS or AD string depending on the resolved mode
$date->displayHuman(); // "Baishak 1, 2081" or "Apr 13, 2024"
$date->displayWithDay(); // "Saturday, Baishak 1, 2081" or "..., Apr 13, 2024"
$date->displayNepali(); // "१ बैशाख २०८१"
$date->displayDateTime(); // date (per mode) + time
Carbon::parseDisplay($request->input('date')); // parses BS or AD input back to a real AD Carbon
use Nrngajurel\NepaliCalendar\Facades\NepaliDate;
NepaliDate::mode(); // 'bs' | 'ad'
NepaliDate::isBs();
NepaliDate::toBs($carbonDate); // BsDate value object
NepaliDate::toAd(2081, 1, 1); // AdDate value object
NepaliDate::display($carbonDate); // same as $date->display()
// Force a mode for the rest of this request/process (e.g. one export):
NepaliDate::setMode('bs');
// ...
NepaliDate::resetMode();
use Nrngajurel\NepaliCalendar\Contracts\CalendarModeResolver;
use Nrngajurel\NepaliCalendar\Resolvers\CallbackCalendarModeResolver;
$this->app->bind(CalendarModeResolver::class, function () {
return new CallbackCalendarModeResolver(
fn () => auth()->user()?->calendar_preference ?? tenant()->calendar_type ?? 'ad'
);
});
final class TenantCalendarModeResolver implements CalendarModeResolver
{
public function __construct(private TenantRepository $tenants) {}
public function mode(): string
{
return $this->tenants->current()->calendar_type; // 'bs' | 'ad'
}
}