1. Go to this page and download the library: Download codryn/phpcalendar 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/ */
codryn / phpcalendar example snippets
use Codryn\PHPCalendar\Calendar\Calendar;
// Create a calendar from built-in profile
$calendar = Calendar::fromProfile('gregorian');
// Parse a date
$date = $calendar->parse('December 25, 2024');
// Format the date
echo $calendar->format($date, 'F d, Y'); // December 25, 2024
// Add 7 days
use Codryn\PHPCalendar\Calendar\TimeSpan;
$future = $date->add(TimeSpan::fromSeconds(86400 * 7));
echo $calendar->format($future, 'F d, Y'); // January 1, 2025
// Calculate difference
$start = $calendar->parse('2024-01-01');
$end = $calendar->parse('2024-12-31');
$span = $calendar->diff($start, $end);
echo $span->getTotalDays(); // 365
use Codryn\PHPCalendar\Calendar\CalendarMapping;
use Codryn\PHPCalendar\Calendar\CalendarMappingConfiguration;
use Codryn\PHPCalendar\Calendar\TimePoint;
// Setup calendars
$gregorian = Calendar::fromProfile('gregorian');
$faerun = Calendar::fromProfile('faerun');
// Define correlation: Jan 1, 2024 = 1 Hammer 1492 DR
$config = new CalendarMappingConfiguration(
sourceCalendarName: 'gregorian',
targetCalendarName: 'faerun',
correlationDate: [
'source' => ['year' => 2024, 'month' => 1, 'day' => 1],
'target' => ['year' => 1492, 'month' => 1, 'day' => 1],
]
);
$mapping = new CalendarMapping($config, $gregorian, $faerun);
// Convert dates between calendars
$gregorianDate = new TimePoint($gregorian, 2024, 12, 25);
$faerunDate = $mapping->convert($gregorianDate);
echo $faerun->format($faerunDate); // Nightal 24, 1492
// Convert back
$backToGregorian = $mapping->reverseConvert($faerunDate);
echo $gregorian->format($backToGregorian); // December 25, 2024
use Codryn\PHPCalendar\Calendar\Calendar;
// Create calendar with German locale
$calendar = Calendar::fromProfile('gregorian', 'de');
echo $calendar->getDisplayName(); // "Gregorianischer Kalender"
// Create calendar with French locale
$calendar = Calendar::fromProfile('gregorian', 'fr');
echo $calendar->getDisplayName(); // "Calendrier Grégorien"
// Get localized month names
$profile = new \Codryn\PHPCalendar\Profile\GregorianProfile();
$profile->setLocale('es');
$months = $profile->getMonthNames();
echo $months[1]; // "Enero" (January in Spanish)
// Get localized epoch notation
$epoch = $profile->getEpochNotation();
echo $epoch['after']; // "d.C." (Spanish for AD/CE)