dipesh/calendar

A PHP package that builds a complete Nepali calendar effortlessly, serving as a wrapper around the dipesh/nepali-date package. It allows users to generate and manipulate a full Nepali calendar, add events, and perform date calculations without any prior knowledge of the underlying system.

v1.0.2 2024-08-18 08:26 UTC

This package is not auto-updated.

Last update: 2025-04-13 11:39:48 UTC


README

Laravel Logo

Nepali Calendar

The Nepali Calendar is a comprehensive PHP package for generating and managing a Nepali calendar. It acts as a wrapper for the dipesh/nepali-date package, enabling users to easily create a full Nepali calendar and manage events within it, all without needing extensive knowledge of the Nepali date system.

Features

  • Comprehensive Nepali Calendar: Generate and work with a complete Nepali calendar.
  • Event Management: Add, update, and manage events for each day.
  • Dynamic Event Handling: Add events using callables or arrays, allowing integration with databases or other sources.
  • Intuitive Navigation: Simple methods for navigating months and years.

Installation

To install the Nepali Calendar package, use Composer:

composer require dipesh/calendar

Usage

Basic Setup

Create a new calendar instance. By default, it initializes to the current date, but you can provide a specific date if needed.

use Dipesh\Calendar\Calendar;

// Create a new calendar instance with the current date
$calendar = new Calendar();

// Create a new calendar instance with a specific date
$specificDate = '2079/01/01'; // Nepali date format
$calendar = new Calendar($specificDate);

Setting Events

Add events for specific days using the setEvent method. You can also set multiple events at once with the setEvents method.

Adding a Single Event

// Add a single event on the 1st of the month
$calendar->setEvent(1, 'New Year Celebration');

Adding Multiple Events

You can use an associative array of events or a callable function for dynamic event setting.

// Define an array of events
$events = [
    14 => 'Valentine\'s Day Celebration',
    28 => 'End of Month Gathering',
];

// Set multiple events at once
$calendar->setEvents($events);

Navigating the Calendar

Easily move through the months and years:

// Move to the next month
$calendar->nextMonth();

// Move to the previous month
$calendar->prevMonth();

// Move to the next year
$calendar->nextYear();

// Move to the previous year
$calendar->prevYear();

Using Callbacks for Dynamic Event Fetching

Define a callable function to fetch and set events dynamically, such as from a database.

// Function to fetch events from a database
$fetchEvents = function ($calendarInstance, $days) {
    // Simulated database fetch
    $dbEvents = [
        5 => 'Public Holiday',
        15 => 'Community Event',
    ];

    // Add events to the calendar
    foreach ($dbEvents as $day => $event) {
        $calendarInstance->setEvent($day, $event);
    }
};

// Set events using the callback function
$calendar->setEvents($fetchEvents);

Example Project

To help you get started with the Nepali Calendar package, an example project is available for you to download and inspect. This project demonstrates how to implement the calendar with event management features effectively.

Screenshot of Example Project

Example Project Screenshot

Download Example Project

You can download the example project from the following link:

Download Example Project

Contributing

Contributions are welcome! If you have suggestions, improvements, or bug fixes, please submit a pull request or open an issue.

License

This package is licensed under the MIT License. For more details, see the LICENSE file.