PHPackages                             benhall14/php-calendar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. benhall14/php-calendar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

benhall14/php-calendar
======================

A simple PHP class to generate calendars.

2.0.7(7mo ago)9822.6k↓34.4%33[1 PRs](https://github.com/benhall14/php-calendar/pulls)MITPHPPHP &gt;=8.0CI passing

Since Feb 4Pushed 2mo ago9 watchersCompare

[ Source](https://github.com/benhall14/php-calendar)[ Packagist](https://packagist.org/packages/benhall14/php-calendar)[ Docs](https://github.com/benhall14/php-calendar)[ RSS](/packages/benhall14-php-calendar/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (25)Used By (0)

PHP Calendar
============

[](#php-calendar)

A PHP class that makes generating calendars as easy as possible.

You can use the addEvent() or addEvents() methods to mark events on the generated calendar.

This is fully compatible with *PHP 5 through to **PHP 8.1+***

Installation via Composer
=========================

[](#installation-via-composer)

You can now install this class via composer.

```
$ composer require benhall14/php-calendar

```

**Remember** to add the composer autoloader before using the class and use the correct namespace.

```
require 'vendor/autoload.php';

use benhall14\phpCalendar\Calendar as Calendar;

```

Usage
=====

[](#usage)

Please make sure you have added the required classes.

#### Styling

[](#styling)

You can apply styles in one of three ways:

1. Using $calendar-&gt;stylesheet() after you have initialised a calendar;

```
    $calendar = new Calendar;
    $calendar->stylesheet();
```

2. Using the calendar.css (or calendar.min.css) from the css directory;

```

```

3. Create your own stylesheet and add it to the head of your HTML document.

#### Migration

[](#migration)

With the release of 2.0, there were some breaking changes. This includes how dates are passed to the draw method, and the translations.

The display() method no longer works like this:

```
$calendar->display(array(date('Y-m-d')));
```

Instead, it now expects an associative array, like:

```
$calendar->display(['startDate' => '2025-05-01']);
```

See "Translated Calendars" for more information on how calendars are now translated.

#### Draw a 'Month View' calendar

[](#draw-a-month-view-calendar)

In its simplest form, use the following to create a calendar for current month. This will use all defaults (English, Week starting on Sunday, including stylesheet, printing to the page).

```
    (new Calendar)->display();
```

Or, you can break it down with full customisability:

```
    # create the calendar object
    $calendar = new Calendar;

    # change the weekly start date to "Monday"
    $calendar->useMondayStartingDate();

    # or revert to the default "Sunday"
    $calendar->useSundayStartingDate();

    # (optional) - if you want to use full day names instead of initials (ie, Sunday instead of S), apply the following:
    $calendar->useFullDayNames();

    # to revert to initials, use:
    $calendar->useInitialDayNames();

    # use the French locale, with days and month names being translated to French.
    $calendar->setLocale('fr_FR');
    # This uses the Carbon locales - https://carbon.nesbot.com/guide/getting-started/localization.html#localization

    # add your own table class(es)
    $calendar->addTableClasses('class-1 class-2 class-3');
    # or using an array of classes.
    $calendar->addTableClasses(['class-1', 'class-2', 'class-3']);

    # (optional) - if you want to hide certain weekdays from the calendar, for example a calendar without weekends, you can use the following methods:
    $calendar->hideSaturdays();		# This will hide Saturdays
    $calendar->hideSundays(); 		# This will hide Sundays
    $calendar->hideMondays(); 		# This will hide Mondays
    $calendar->hideTuesdays(); 		# This will hide Tuesdays
    $calendar->hideWednesdays();	# This will hide Wednesdays
    $calendar->hideThursdays();		# This will hide Thursdays
    $calendar->hideFridays();		# This will hide Fridays

    # custom data attributes - you can add custom data attributes to days using the following:
    $calendar->addDataAttribute('2025-01-14', 'data-attribute-1', 'value-1');

    # or for multiple attributes
    $calendar->addDataAttributes('2025-01-14', ['data-attribute-1' => 'value', 'data-attribute-2' => 'value-2']);

    # options for draw method
    $options = [
        'color' => 'blue', # One of the predefined colour schemes.
        'startDate' => date('Y-m-d'), # the start date of the calendar.
        'timeInterval' => 10, # the interval between the times - only applicable on the week view calendar.
        'startTime' => '09:00', # the starting time for the week view calendar. For a 9-5 calendar, use 09:00
        'endTime' => '17:00', # the end time for the weekview calendar. For a 9-5 calendar, use 17:00
    ];
    $calendar->draw($options);

    # if needed, add event
	$calendar->addEvent(
	    '2022-01-14',   # start date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    '2022-01-14',   # end date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    'My Birthday',  # event name text
	    true,           # should the date be masked - boolean default true
	    ['myclass', 'abc'],   # (optional) additional classes in either string or array format to be included on the event days
	    ['event-class', 'abc']   # (optional) additional classes in either string or array format to be included on the event summary box
	);

    # or for multiple events

	$events = array();

	$events[] = array(
		'start' => '2022-01-14',
		'end' => '2022-01-14',
		'summary' => 'My Birthday',
		'mask' => true,
		'classes' => ['myclass', 'abc'],
        'event_box_classes' => ['event-box-1']
	);

	$events[] = array(
		'start' => '2022-12-25',
		'end' => '2022-12-25',
		'summary' => 'Christmas',
		'mask' => true
	);

	$calendar->addEvents($events);

    # finally, to draw a calendar
    echo $calendar->draw(date('Y-m-d')); # draw this months calendar

    # this can be repeated as many times as needed with different dates passed, such as:
    echo $calendar->draw(date('Y-01-01')); # draw a calendar for January this year
    echo $calendar->draw(date('Y-02-01')); # draw a calendar for February this year
    echo $calendar->draw(date('Y-03-01')); # draw a calendar for March this year
    echo $calendar->draw(date('Y-04-01')); # draw a calendar for April this year
    echo $calendar->draw(date('Y-05-01')); # draw a calendar for May this year
    echo $calendar->draw(date('Y-06-01')); # draw a calendar for June this year

    # to use the pre-made color schemes, call the ->stylesheet() method and then pass the color choice to the draw method, such as:
    echo $calendar->draw(date('Y-m-d'));            # print a (default) turquoise calendar
    echo $calendar->draw(date('Y-m-d'), 'purple');  # print a purple calendar
    echo $calendar->draw(date('Y-m-d'), 'pink');    # print a pink calendar
    echo $calendar->draw(date('Y-m-d'), 'orange');  # print a orange calendar
    echo $calendar->draw(date('Y-m-d'), 'yellow');  # print a yellow calendar
    echo $calendar->draw(date('Y-m-d'), 'green');   # print a green calendar
    echo $calendar->draw(date('Y-m-d'), 'grey');    # print a grey calendar
    echo $calendar->draw(date('Y-m-d'), 'blue');    # print a blue calendar

    # you can also call ->display(), which handles the echo'ing and adding the stylesheet.
    echo $calendar->display(['date' => date('Y-m-d')]); # draw this months calendar
```

#### Draw a 'Week View' calendar

[](#draw-a-week-view-calendar)

Instead of a 'month view' calendar, you can now render as a 'week view'. To do this, simply use -&gt;useWeekView(). Remember, when adding events to a week-view calendar, you need to include the time too (see events above).

```
    $events = array();

    $events[] = array(
        'start' => '2022-01-14 14:40',
        'end' => '2022-01-14 15:10',
        'summary' => 'My Birthday',
        'mask' => true,
        'classes' => ['myclass', 'abc']
    );

    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 1',
        'mask' => true
    );
    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 2',
        'mask' => true
    );

    $calendar = new Calendar;

    $calendar->addEvents($events)->setTimeFormat('00:00', '00:00', 10)->useWeekView()->display(['startDate' => date('Y-m-d'), 'color' => 'green']);
```

You can change the start/end times of the day, along with the time interval by using the -&gt;setTimeFormat method:

```
    $calendar->setTimeFormat('09:00', '17:00', 10)->useWeekView()->display(['startDate' => date('Y-m-d'), 'green']);
    # This will print a week view calendar with 10 minute slots from 9AM to 5PM - ie. 08:00, 08:10, 08:20 and so on.
```

#### Monday Start Date

[](#monday-start-date)

You can now change the weekly start date from a **Sunday** to a **Monday**. To activate this, simple use the **useMondayStartingDate()** method before you 'draw'.

```
    $calendar = new Calendar;
    $calendar->useMondayStartingDate();
    $calendar->display(['startDate' => date('Y-m-d'), 'color' => 'green']);
```

#### Translated Calendars

[](#translated-calendars)

We now use automatically from the date and the setLocale() method. If you use -&gt;setLocale('fr\_FR'), then the days and month names will be French. For more information on the Carbon localization, see

Credits
=======

[](#credits)

- [GeoSot](https://github.com/GeoSot)

Requirements
============

[](#requirements)

**Carbon**

License
=======

[](#license)

Copyright (c) 2016-2022 Benjamin Hall,

Licensed under the MIT license

Donate?
=======

[](#donate)

If you find this project helpful or useful in any way, please consider getting me a cup of coffee - It's really appreciated :)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://paypal.me/benhall14)

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance77

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 64.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~128 days

Recently: every ~88 days

Total

23

Last Release

210d ago

Major Versions

1.5.4 → 2.02024-10-18

PHP version history (2 changes)1.0PHP &gt;=5.3

2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9865a064095eed7df440011181fc539fa069fab79828d5fa61de6ca20d2f2326?d=identicon)[benhall14](/maintainers/benhall14)

---

Top Contributors

[![benhall14](https://avatars.githubusercontent.com/u/17323507?v=4)](https://github.com/benhall14 "benhall14 (54 commits)")[![GeoSot](https://avatars.githubusercontent.com/u/22406063?v=4)](https://github.com/GeoSot "GeoSot (20 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![pascalchevrel](https://avatars.githubusercontent.com/u/454375?v=4)](https://github.com/pascalchevrel "pascalchevrel (1 commits)")[![Pony2001](https://avatars.githubusercontent.com/u/116486946?v=4)](https://github.com/Pony2001 "Pony2001 (1 commits)")[![rickyosser](https://avatars.githubusercontent.com/u/22371262?v=4)](https://github.com/rickyosser "rickyosser (1 commits)")[![wsmwason](https://avatars.githubusercontent.com/u/1227493?v=4)](https://github.com/wsmwason "wsmwason (1 commits)")[![damiankw](https://avatars.githubusercontent.com/u/12539594?v=4)](https://github.com/damiankw "damiankw (1 commits)")[![nazaralwi](https://avatars.githubusercontent.com/u/37035339?v=4)](https://github.com/nazaralwi "nazaralwi (1 commits)")

---

Tags

calendarcalendarsphptimedatecalendarcalendars

###  Code Quality

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/benhall14-php-calendar/health.svg)

```
[![Health](https://phpackages.com/badges/benhall14-php-calendar/health.svg)](https://phpackages.com/packages/benhall14-php-calendar)
```

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
