donatj / simplecalendar
A light, easy to use calendar rendering library
v0.8.1
2026-10-08 12:29 UTC
Requires
- php: >=7.4
- ext-calendar: *
Requires (Dev)
- ext-dom: *
- corpus/coding-standard: ^0.9.0
- donatj/drop: ^1.1
- donatj/mddoc: ^0.13.0
- friendsofphp/php-cs-fixer: ^3.3
- phpstan/phpstan: ^2.3.0
- phpunit/phpunit: ~8|~9
- squizlabs/php_codesniffer: ^3.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.2
- v0.3.1
- v0.3.0
- dev-fix/improve-test-coverage
- dev-fix/upgrade-phpstan
- dev-ci/check-docs
- dev-ci/add-php-8-6
- dev-phpunit-deprecations
- dev-copilot/drop-php-support-earlier-than-7-4
- dev-phpstan
- dev-donatj-patch-1
- dev-keesiemeijer-master
- dev-patch-1
This package is auto-updated.
Last update: 2026-10-08 12:32:31 UTC
README
A very simple, easy to use PHP calendar rendering class.
Requirements
- php: >=7.4
- ext-calendar: *
Installing
Install the latest version with:
composer require 'donatj/simplecalendar'
Examples
<?php require '../vendor/autoload.php'; echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />'; $calendar = new donatj\SimpleCalendar('June 2010'); echo $calendar->render();
<?php require '../vendor/autoload.php'; echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />'; $calendar = new donatj\SimpleCalendar; $calendar->setStartOfWeek('Sunday'); $calendar->addDailyHtml('Sample Event', 'today', 'tomorrow'); $calendar->setWeekDayNames([ 'Sun', 'Mon', 'Tu', 'W', 'Th', 'F', 'Sa' ]); $calendar->setStartOfWeek('Monday'); echo $calendar->render();
Documentation
Class: donatj\SimpleCalendar
Simple Calendar
Method: SimpleCalendar->__construct
function __construct($calendarDate = null, $today = null)
Parameters
- \DateTimeInterface | int | string | null
$calendarDate - \DateTimeInterface | false | int | string | null
$today
Method: SimpleCalendar->setDate
function setDate($date = null): void
Sets the date for the calendar.
Parameters
- \DateTimeInterface | int | string | null
$date- DateTimeInterface or Date string parsed by strtotime for the calendar date. If null set to current timestamp.
Throws: \Exception
Method: SimpleCalendar->setCalendarClasses
function setCalendarClasses(array $classes): void
Sets the class names used in the calendar
[ 'calendar' => 'SimpleCalendar', 'leading_day' => 'SCprefix', 'trailing_day' => 'SCsuffix', 'today' => 'today', 'event' => 'event', 'events' => 'events', ]
Parameters
- array{calendar?: string,leading_day?: string,trailing_day?: string,today?: string,event?: string,events?: string}
$classes- Map of element to class names used by the calendar.
Method: SimpleCalendar->setToday
function setToday($today = null): void
Sets "today"'s date. Defaults to today.
Parameters
- \DateTimeInterface | false | int | string | null
$today-nullwill default to today,falsewill disable the rendering of Today.
Throws: \Exception
Method: SimpleCalendar->setWeekDayNames
function setWeekDayNames(?array $weekDayNames = null): void
Parameters
- array{0: string,1: string,2: string,3: string,4: string,5: string,6: string} | null
$weekDayNames
Method: SimpleCalendar->addDailyHtml
function addDailyHtml(string $html, $startDate, $endDate = null): void
Add a daily event to the calendar
Parameters
- string
$html- The raw HTML to place on the calendar for this event - \DateTimeInterface | int | string
$startDate- Date string for when the event starts - \DateTimeInterface | int | string | null
$endDate- Date string for when the event ends. Defaults to start date
Throws: \Exception
Method: SimpleCalendar->clearDailyHtml
function clearDailyHtml(): void
Clear all daily events for the calendar
Method: SimpleCalendar->setStartOfWeek
function setStartOfWeek($offset): void
Sets the first day of the week
Parameters
- int | string
$offset- Day the week starts on. ex: "Monday" or 0-6 where 0 is Sunday
Method: SimpleCalendar->show
function show(bool $echo = true): string
Returns/Outputs the Calendar
DEPRECATED
Use render() method instead.
Parameters
- bool
$echo- Whether to echo resulting calendar
Return Value
- string - HTML of the Calendar
Method: SimpleCalendar->render
function render(): string
Returns the generated Calendar