PHPackages                             garkavenkov/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. garkavenkov/calendar

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

garkavenkov/calendar
====================

Calendar

0.7.3(2y ago)022MITPHP

Since Sep 24Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (16)Used By (0)

Сalendar
========

[](#сalendar)

Calendar

Installation
------------

[](#installation)

Use [Composer](https://getcomposer.org "Composer")

> composer require garkavenkov/calendar

Usage
-----

[](#usage)

### Initialization

[](#initialization)

```
use Garkavenkov\Calendar\Calendar;

$cldr = new Calendar();
```

This code creates calendar based on current date. If you need to create calendar on particular month and year, pass parameters to class constructor

```
$cldr = new Calendar(year: 2022, month: 10);
```

By default calendar creates with week begins on Sunday. If you need week begin on Monday, pass next parameter to class constructor

```
$cldr = new Calendar(year: 2022, month: 10, week_begins_on_monday:true);
```

Also you can set language for day's and month's names. In this you need to pass additional parameter to constructor

```
$cldr = new Calendar(year: 2022, month: 10, week_begins_on_monday:true, lang: 'ua');
```

### Calendar structure

[](#calendar-structure)

To get calendar use command:

```
$cldr = new Calendar(year: 2022, month: 10, week_begins_on_monday:true, lang: 'ua');
$cal = $cldr->get();
print_r($cal);
```

The calendar has the following structure:

```
Array
(
    [info] => Array
        (
            [weekDayNames] => Array
                (
                    [0] => Понеділок
                    [1] => Вівторок
                    [2] => Середа
                    [3] => Четвер
                    [4] => П`ятниця
                    [5] => Субота
                    [6] => Неділя
                )
            [months] => Array
                (
                    [0] => Січень
                    [1] => Лютий
                    [2] => Березень
                    [3] => Квітень
                    [4] => Травень
                    [5] => Червень
                    [6] => Липень
                    [7] => Серпень
                    [8] => Вересень
                    [9] => Жовтень
                    [10] => Листопад
                    [11] => Грудень
                )
            [month] => Array
                (
                    [index] => 10
                    [name] => Жовтень
                )
            [year] => 2022
        )
    [weeks] => Array
        (
            [0] => Array
                (
                    [number] => 39
                    [days] => Array
                        (
                            [0] => Array
                                (
                                    [date] => 2022-09-26
                                    [mday] => 26
                                    [wday] => 1
                                    [mon] => 9
                                    [year] => 2022
                                    [yday] => 268
                                    [weekday] => Понеділок
                                    [month] => Вересень
                                )

                             ...
                            [6] => Array
                                (
                                    [date] => 2022-10-02
                                    [mday] => 2
                                    [wday] => 0
                                    [mon] => 10
                                    [year] => 2022
                                    [yday] => 274
                                    [weekday] => Неділя
                                    [month] => Жовтень
                                )

                        )
                )

            ...

            [5] => Array
                (
                    [number] => 44
                    [days] => Array
                        (
                            ...
                            [6] => Array
                                (
                                    [date] => 2022-11-06
                                    [mday] => 6
                                    [wday] => 0
                                    [mon] => 11
                                    [year] => 2022
                                    [yday] => 309
                                    [weekday] => Неділя
                                    [month] => Листопад
                                )
                        )
                )
        )
)

```

Methods
-------

[](#methods)

#### getCalendarBoundaries($format)

[](#getcalendarboundariesformat)

If you need to get calendar first and last day, use folowing code:

```
$boundaries = $cal->getCalendarBoundaries($format = null);
print_r($boundaries);
```

This method returns an array of calendar start and end dates

```
Array
(
    [0] => Array
        (
            [date] => 2022-09-26
            [mday] => 26
            [wday] => 1
            [mon] => 9
            [year] => 2022
            [yday] => 268
            [weekday] => Понеділок
            [month] => Вересень
        )

    [1] => Array
        (
            [date] => 2022-11-06
            [mday] => 6
            [wday] => 0
            [mon] => 11
            [year] => 2022
            [yday] => 309
            [weekday] => Неділя
            [month] => Листопад
        )

)

```

You can pass $format variable into method.

```
$boundries = $cal->getCalendarBoundaries('Y-m-d');
```

With this format methods will return array with formated date

```
Array
(
    [0] => 2022-26-09
    [1] => 2022-06-11
)

```

#### getMonthBoundaries($format = null)

[](#getmonthboundariesformat--null)

Method `getMonthBoundaries()` returns array with first and last day of the calendar month

```
$boundries = $cal->getMonthBoundaries();
```

```
Array
(
    [0] => Array
        (
            [date] => 2022-10-01
            [mday] => 1
            [wday] => 6
            [mon] => 10
            [year] => 2022
            [yday] => 273
            [weekday] => Субота
            [month] => Жовтень
        )

    [1] => Array
        (
            [date] => 2022-10-31
            [mday] => 31
            [wday] => 1
            [mon] => 10
            [year] => 2022
            [yday] => 303
            [weekday] => Понеділок
            [month] => Жовтень
        )

)

```

Likewise `getCalendarBoundaries()` you can pass a `$format` variable to a method and get the formatted dates

```
$boundries = $cal->getMonthBoundaries('Y-m-d');
```

```
Array
(
    [0] => 2022-10-01
    [1] => 2022-10-31
)

```

#### getWeekdays()

[](#getweekdays)

Method `getWeekdays()` returns an array containing the names of the days of the week.

```
$days = $cal->getWeekdays();
print_r($days);
```

```
Array
(
    [0] => Понеділок
    [1] => Вівторок
    [2] => Середа
    [3] => Четвер
    [4] => П`ятниця
    [5] => Субота
    [6] => Неділя
)

```

#### getMonths()

[](#getmonths)

Method `getMonths()` returns an array containing the names of the months.

```
$months = $cal->getMonths();
print_r($months);
```

```
Array
(
    [0] => Січень
    [1] => Лютий
    [2] => Березень
    [3] => Квітень
    [4] => Травень
    [5] => Червень
    [6] => Липень
    [7] => Серпень
    [8] => Вересень
    [9] => Жовтень
    [10] => Листопад
    [11] => Грудень
)

```

#### injectIntoDay(string $title, array $events, string $array\_function)

[](#injectintodaystring-title-array-events-string-array_function)

This method allows to inject data into a day with particular `$title`. For example, there is a set of data `$events` containing date and some information e.g.

```
$events = array(
    ['date' => '2022-10-01', 'name' => 'todo1'],
    ['date' => '2022-10-01', 'name' => 'todo2'],
    ['date' => '2022-10-02', 'name' => 'todo1'],
    ['date' => '2022-10-02', 'name' => 'todo2'],
    ['date' => '2022-10-02', 'name' => 'todo3'],
);

....

```

Following code will inject this dataset into calendar with title `todos`

```
$cal->injectIntoDay('todos', $events);
print_t($cal->get());
```

output

```
...
    [5] => Array
        (
            [date] => 2022-10-01
            [mday] => 1
            [wday] => 6
            [mon] => 10
            [year] => 2022
            [yday] => 273
            [weekday] => Субота
            [month] => Жовтень
            [todos] => Array
                (
                    [0] => Array
                        (
                            [date] => 2022-10-01
                            [name] => todo1
                        )
                    [1] => Array
                        (
                            [date] => 2022-10-01
                            [name] => todo2
                        )
                )
        )
    [6] => Array
        (
            [date] => 2022-10-02
            [mday] => 2
            [wday] => 0
            [mon] => 10
            [year] => 2022
            [yday] => 274
            [weekday] => Неділя
            [month] => Жовтень
            [todos] => Array
                (
                    [0] => Array
                        (
                            [date] => 2022-10-02
                            [name] => todo1
                        )
                    [1] => Array
                        (
                            [date] => 2022-10-02
                            [name] => todo2
                        )
                    [2] => Array
                        (
                            [date] => 2022-10-02
                            [name] => todo3
                        )
                )
        )
    ...

```

It is also possible to pass `$array_function` to perform operation with dataset in `$events`.

Following code will inject this result of `count` function performed on dataset into calendar with title `todos`

```
$cal->injectIntoDay('todos', $events, 'count');
print_t($cal->get());
```

output

```
...
    [5] => Array
        (
            [date] => 2022-10-01
            [mday] => 1
            [wday] => 6
            [mon] => 10
            [year] => 2022
            [yday] => 273
            [weekday] => Субота
            [month] => Жовтень
            [todos] => 2
        )
    [6] => Array
        (
            [date] => 2022-10-02
            [mday] => 2
            [wday] => 0
            [mon] => 10
            [year] => 2022
            [yday] => 274
            [weekday] => Неділя
            [month] => Жовтень
            [todos] => 3
        )
    ...

```

#### getWeeksNumbers()

[](#getweeksnumbers)

This method returns an array containing calendar's weeks numbers.

```
$numbers = $cal->getWeeksNumbers();
print_r($numbers);
```

output

```
Array
(
    [0] => 39
    [1] => 40
    [2] => 41
    [3] => 42
    [4] => 43
    [5] => 44
)

```

#### getWeek(int $number)

[](#getweekint-number)

This method returns an array containing calendar's week by number `$number`.

```
$week = $cal->getWeek(40);
print_r($week);
```

output

```
Array
(
    [1] => Array
        (
            [number] => 40
            [days] => Array
                (
                    [0] => Array
                        (
                            [date] => 2022-10-03
                            [mday] => 3
                            [wday] => 1
                            [mon] => 10
                            [year] => 2022
                            [yday] => 275
                            [weekday] => Понеділок
                            [month] => Жовтень
                        )
                   ...
                    [6] => Array
                        (
                            [date] => 2022-10-09
                            [mday] => 9
                            [wday] => 0
                            [mon] => 10
                            [year] => 2022
                            [yday] => 281
                            [weekday] => Неділя
                            [month] => Жовтень
                        )
                )
        )
)

```

#### getCalendarInfo(string $dateFormat = null)

[](#getcalendarinfostring-dateformat--null)

This method returns an array containing basic information about calendar, i.e. month, year, calendar's and month's boundries

```
$info = $cal->getCalendarInfo();
print_r($info);
```

output

```
Array
(
    [year] => 2022
    [month] => Array
        (
            [index] => 10
            [name] => Жовтень
        )
    [calendarBoundaries] => Array
        (
            [0] => Array
                (
                    [date] => 2022-09-26
                    [mday] => 26
                    [wday] => 1
                    [mon] => 9
                    [year] => 2022
                    [yday] => 268
                    [weekday] => Понеділок
                    [month] => Вересень
                )
            [1] => Array
                (
                    [date] => 2022-11-06
                    [mday] => 6
                    [wday] => 0
                    [mon] => 11
                    [year] => 2022
                    [yday] => 309
                    [weekday] => Неділя
                    [month] => Листопад
                )
        )
    [monthBoundaries] => Array
        (
            [0] => Array
                (
                    [date] => 2022-10-01
                    [mday] => 1
                    [wday] => 6
                    [mon] => 10
                    [year] => 2022
                    [yday] => 273
                    [weekday] => Субота
                    [month] => Жовтень
                )
            [1] => Array
                (
                    [date] => 2022-10-31
                    [mday] => 31
                    [wday] => 1
                    [mon] => 10
                    [year] => 2022
                    [yday] => 303
                    [weekday] => Понеділок
                    [month] => Жовтень
                )
        )
)

```

It is possible to output calendar's and month's boundries in particular format. To do this, you need to pass a parameter with the necessary format

```
$info = $cal->getCalendarInfo(format: 'Y-m-d');
print_r($info);
```

output

```
Array
(
    [year] => 2022
    [month] => Array
        (
            [index] => 10
            [name] => Жовтень
        )
    [calendarBoundaries] => Array
        (
            [0] => 2022-09-26
            [1] => 2022-11-06
        )
    [monthBoundaries] => Array
        (
            [0] => 2022-10-01
            [1] => 2022-10-31
        )
)

```

#### getDay(string $date)

[](#getdaystring-date)

This method returns an array containing particular day information

```
$day = $cal->getDay('2022-10-22');
print_r($day);
```

output

```
Array
(
    [0] => Array
        (
            [date] => 2022-10-22
            [mday] => 22
            [wday] => 6
            [mon] => 10
            [year] => 2022
            [yday] => 294
            [weekday] => Субота
            [month] => Жовтень
        )
)

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~38 days

Recently: every ~127 days

Total

15

Last Release

789d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d8dec7c047130aa35c0dc054df1af7a0833c2f2fbb3cd9c89011149eea1efa58?d=identicon)[garkavenkov](/maintainers/garkavenkov)

---

Top Contributors

[![garkavenkov](https://avatars.githubusercontent.com/u/10245674?v=4)](https://github.com/garkavenkov "garkavenkov (16 commits)")

### Embed Badge

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

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

###  Alternatives

[daverandom/exceptional-json

JSON encoding and decoding that throws exceptions on failure

321.4M9](/packages/daverandom-exceptional-json)

PHPackages © 2026

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