Giter VIP home page Giter VIP logo

calendr's Introduction

CalendR

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight

CalendR is an Object Oriented Calendar management library on top of PHP5.3+ Date objects. You can use it to deal with all your needs about calendars and events.

Complete documentation

Complete documentation is available here.

Installation

CalendR is hosted on packagist, you can install it with composer.

Create a composer.json file

    {
        "require": {
            "yohang/calendr": "^1.1"
        }
    }

Install composer and run it

    wget http://getcomposer.org/composer.phar
    php composer.phar install

(Optional) Autoload CalendR

    require 'vendor/autoload.php';

Contribute

Calendar is open to contributions. Merging delays can vary depending to my free time, but always be welcome.

License

CalendR is licensed under the MIT License - see the LICENSE file for details

calendr's People

Contributors

bertrandq avatar garak avatar jpottier avatar nyholm avatar ovgray avatar samnela avatar yohang avatar zanbaldwin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

calendr's Issues

Period\Range::contains

Shouldn't this method return true if $date->format('U') == $this->begin->format('U')?

[Feature Request] Support Carbon package

Hello Yohang

Is it at all possible that this package could support Carbon along side the Native \DateTime class, because The laravel elougent ORM is using this package out of the box.

And Carbon is a nice wrapper around the DateTime class

It's A LOT of work yeah i know, but it could be possible.

Is there a wa to get the get the current day?

First of all. Great works its very awesome.

But i do some experiments and now i try to mark the today in calendar but i can't find any ways to do that....

Any help solutions for that??

Thanks

Option to start Week period on Sunday and end on Saturday

I noticed when printing out each day of the week and corresponding events for them that weeks seem to start on Monday and end on Sunday. In the US, weeks on calendars typically start on Sunday and end on Saturday. Is there a way to shift this so I can print out weekdays Sunday through Saturday the US style way?

Throw an error when there's no provider specified

I've just lost 15 minutes wondering why my events weren't retrieved, in the end it was just my event provider which wasn't properly loaded. Could you throw an error when there's no provider specified?

Event repositories can't be properly added with Symfony2 & Doctrine2

It's the second time I'm using Calendr for two different projects and I still get this error :

Capture d e cran 2013-04-01 a 17 26 08

The first time I used Calendr I had a PHP 5.4 server so I could use traits. My repository was declared as your first example code. To avoid the above error, I just added implements ProviderInterface to the EventRepository declaration and it was done.

Now my server is under PHP 5.3 so I'm using the second way provided on the doc. But, using this second way doesn't provides all the methods required by ProviderInterface and, at this point, I'm stuck…

new release?

Well, indeed this repo has no releases.
The last tag, anyway, was published back in 2019, so it's currently not possible to install this library on PHP 8 (the only major version currently supported) unless you use dev-master (or the ^3.0@dev alias).

So, it would be nice to get a new tag and a new release.

Sprintf is missing argument in PeriodAbstract

sprintf in PeriodAbstract::__construct is missing an argument and thus breaks if $firstWeekday is out of bounds. Additionally, the message implies that 6 == Friday which isn't true. It should be:

                sprintf('"%s" is not a valid day. Days are between 0 (Sunday) and 6 (Saturday)', $firstWeekday)

February ends in March

This is a dump of February 2015:

Month {#2306 ▼
  -current: null
  #begin: DateTime {#2288 ▼
    +"date": "2015-02-01 00:00:00"
    +"timezone_type": 3
    +"timezone": "Europe/Rome"
  }
  #end: DateTime {#2295 ▼
    +"date": "2015-03-01 00:00:00"
    +"timezone_type": 3
    +"timezone": "Europe/Rome"
  }
  #firstWeekday: 1
}

I'd expect to see it ending 2015-02-28, not 2015-03-01.

First and last day of the week

Hi!

I need to show the first and last day of the week with the format {{ first_monday_number }}-{{ last_saturday_number }} {{ month_name }}. Example with the week number 24: 2017-06-12 to 2017-06-18

<?php

$year = $request->query->has('year') ? $request->query->get('year') : date('Y');
$weeknum = $request->query->has('weeknum') ? $request->query->get('weeknum') : date('W');

$week = $this->get('calendr')->getWeek($year, $weeknum);
$weekEvents = $this->get('calendr')->getEvents($week);

In the twig template:

{{ week.begin.format('j') }} - {{ week.end.format('j') }} of {{ week.format('F') }}

The problem is in {{ week.end.format('j') }} , print "12 - 19 of June" and I need the last day to be on Saturday: 12 - 17 of June.

How can I get the correct date?

Thanks,

CalendR\Event\Exception\NoProviderFound:

        $factory = new \CalendR\Calendar;
        $month = $factory->getMonth(2020, 6);
        $events = $factory->getEvents($month);

CalendR\Event\Exception\NoProviderFound: in file /home/wwwroot/akstest.gewu.pro/tooth/vendor/yohang/calendr/src/CalendR/Event/Manager.php on line 68

Boilerplate code not working

Is this app still working with php 7 and Laravel 5.8?

Because non of the site's bolierplate code is working.

I cannot biuld the calendar, it only renders the day names, Mon to Fri repeteadly.

thanks.

[FEATURE] Add data property to Event

Hi all!

I'm working with this library for a while (It works like a charm BTW), and I really missing what I think is a good new feature.

The default Event model, does not have the possibility to hold a "data" (Where data is whatever you need, it could be an object, an array or a primitive), and you always have to extend default Entity to include your custom data.

While i think this is good for advanced use cases, i think for simple use cases, having a "bag" where store whatever you need (a title, a status, or even an array with more complex data) without having to extend the default model would be perfect.

I don't know what you think, if you agree I can work on a pull request.

Thanks you for your work

Multi-day Events

Hi,

How do you show multi-day events on a calendar? The following piece of code correctly shows events which start on a particular date, but it doesn't show events which span multiple days. I'm using the Indexed Event Collection.

<?php foreach ($eventCollection->find($day) as $event): ?>
    <li><?= $event ?></li>
<?php endforeach ?>

Thanks

First weekday on Week iterator

Why is the first weekday option only working on the Month iterator? When using getWeek(...) and looping through the dates, it always starts with Monday.When using getMonth(...) I get the expected result, the first day is whatever getFirstWeekday() is.

Adding hours

I just began to add hours to days, so we can have a nice 1 day view

https://github.com/lsv/CalendR/tree/hours

But I just got stucked because of the iteration on the month get really weird.

       $start = new \DateTime('2013-01-01');
        $month = new Month($start);

        $i = 0;

        foreach ($month as $week) {
            $this->assertInstanceOf('CalendR\\Period\\Week', $week);
            foreach ($week as $day) {
                /** @var Day $day */
                $this->assertSame($start->format('d-m-Y'), $day->getBegin()->format('d-m-Y'));
                $start->add(new \DateInterval('P1D'));
                $i++;
            }
        }

        $this->assertEquals($i, 31);

This actually gives me 35 in the last assert, and all assertSame is 1 day behind all the time.

Month includes doesn't work properly

For year 2012 and month 12, day 31 in not included in the month.
If I'll make this check, it will return false:

$month->includes($day); // where $day is 2012-12-31

In your code you have the following:

public function includes(PeriodInterface $period, $strict = true)
{
    if (true === $strict) {
        return
                $this->contains($period->getBegin()) &&
                $this->contains($period->getEnd());
    }
...

This check $this->contains($period->getBegin()) will return TRUE, but this one will return FALSE: $this->contains($period->getEnd()). This is because ->getEnd() returns the next day.

CalendR\Period\Day('begin'=>DateTime('date'=>'2012-12-31 00:00:00', 'timezone_type'=> 3, 'timezone'=> ... ), 'end'=>DateTime('date'=>'2013-01-01 00:00:00', 'timezone_type'=> 3, 'timezone'=> ... ))

events in extendedMonth miss events on last sunday

With the current implementation for Month->extendedMonth() the period ends on midnight saturday to sunday. This means using this Period in for instance $factory->getEvents($month->extendedMonth()) misses these events. Shouldn't the Period end on midnight sunday to monday?

Update documentation

There is some minor changes to do in the documentation :

  • Search and fix typos
  • Add documentation for the weekday option

Frustraing class

I went through your "documentation". Your examples lack of parenthesis so I get parse errors, and on top of that, I get fatal errors as well:

Fatal error: Call to undefined method CalendR\Period\Month::containsPeriod()

Wrong return types in Calendar

Calendar class uses PeriodInterface as return type for getYear, getMonth, getWeek.
Such method should return, respectively, Year, Month, Week, that are implementing \Iterator.
With the current code, a call to foreach (new Calendar)->getMonth() is marked as invalid by phpstorm ("Can not iterate PeriodInterface").

Fix Twig deprecation warnings

Using an instance of "Twig_Function_Method" for function "calendr_year" is deprecated since version 1.21. Use Twig_SimpleFunction instead.
Using an instance of "Twig_Function_Method" for function "calendr_month" is deprecated since version 1.21. Use Twig_SimpleFunction instead.
Using an instance of "Twig_Function_Method" for function "calendr_week" is deprecated since version 1.21. Use Twig_SimpleFunction instead.
Using an instance of "Twig_Function_Method" for function "calendr_day" is deprecated since version 1.21. Use Twig_SimpleFunction instead.
Using an instance of "Twig_Function_Method" for function "calendr_events" is deprecated since version 1.21. Use Twig_SimpleFunction instead.

Support Symfony 3

I'm using this bundle with Symfony 2.8 and the only deprecation I found until now is the following
The Symfony\Component\OptionsResolver\OptionsResolver::replaceDefaults method is deprecated since version 2.6 and will be removed in 3.0. Use the clear() and setDefaults() methods instead.
So, using setDefaults should be fine, along with allowing ^3.0 in composer.json

I am trying to build a simple calendar how can I access the day's date

object(CalendR\Period\Week)#567 (4) {
["current":"CalendR\Period\Week":private]=>
NULL
["begin":protected]=>
object(DateTime)#566 (3) {
["date"]=>
string(19) "2012-04-02 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["end":protected]=>
object(DateTime)#587 (3) {
["date"]=>
string(19) "2012-04-09 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["firstWeekday":protected]=>
int(1)
}

when I go echo $day->begin->date I get Cannot access protected property CalendR\Period\Day::$begin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.