Code Monkey home page Code Monkey logo

Comments (17)

rlanvin avatar rlanvin commented on August 28, 2024

No, it does not. DTEND is not part of the RRULE property, and does not have any impact on the recurrence rule as far as I know. Same for duration. In other words, this library will give you all the occurrences of a recurring event, but does not care when the event itself ends, or how long it lasts.

What is your use case for DTEND in the context of a recurring event?

from php-rrule.

marcorivm avatar marcorivm commented on August 28, 2024

I'm working in the context of time windows to work on given tasks, these time windows are recurrent, as in you must do this every day between 5 and 6 pm.

I think it's worth something in the context of knowing if an event is happening right now. (Also a nextOcurrence() method would be nice)

Looks like google calendar uses two separate fields for the first ocurrence which defines duration
https://developers.google.com/google-apps/calendar/concepts/events-calendars#recurring_events

Also I'm not very familiar with RRULE or the RFC5545, but I do think the DTEND and DTSTART parameters are considered part of the RRULE string. Just checked they are considered different properties of the iCalendar, I was misunderstanding some concepts.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

I think it's worth something in the context of knowing if an event is happening right now.

I see your point, however now we're taking about events with 2 dates (DTSTART and DTEND), whereas the RRULE string (and therefore this library) only work with one date (the start date). The duration itself is a constant, so it doesn't impact the recurrence rule, and that is why it's not part of the RRULE string.

My approach to that would be to built another class on top of RRule (e.g. RRule\Event) that would take DTSTART and DTEND, and calculate the duration of the event. The class would use RRule to get the start time of each occurence, and simply add the duration to get the end time of each event. It would return an array of two datetimes (start and stop), instead of just one like RRule. Methods such as occursAt would need to test if it's between the start and the stop.

That could be an interesting addition to this lib for sure, but it's a whole new layer and I do not think I will have to the time to work on it anytime soon. You're welcome to make a pull request if you want though.

Also a nextOcurrence() method would be nice

Sure, but I don't really understand what would the method do? You can already get the Nth occurrence with array access syntax ($rrule[x]), and/or traverse the RRule like a array of occurences with foreach.

Just checked they are considered different properties of the iCalendar, I was misunderstanding some concepts.

You probably got mixed up between DTEND (the end time of the event, whether the event is recurring or not) and the COUNT and UNTIL parts of the RRULE string (the end condition of the recurrence rule).

from php-rrule.

gordonzhao avatar gordonzhao commented on August 28, 2024

It actually affects the getOccurrencesBetween function. Currently it only checks the occurrences' start datetime.
For example, for

DTSTART:20160315
RRULE:FREQ=MONTHLY;UNTIL=20160625
DTEND:20160320

getOccurrencesBetween('2016-03-16','2016-03-19') will return empty array.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

getOccurrencesBetween('2016-03-16','2016-03-19') will return empty array.

Indeed, and unless I'm terribly mistaken, this is the behavior specified in the RFC for RRULE strings. In your example, there is no event that starts between 2016-03-16 00:00:00 and 2016-03-19 00:00:00. There is an event that started before and is still ongoing, but that's not what this is meant to calculate.

If you want to also get the event that are still ongoing, you should call getOccurencesBetween with "start - duration", and end. Following up with the suggestion I gave above, this could be wrapped into a RRule\Event that would know the duration and automatically do this kind of math for you before calling RRule\RRule.

The other option is to have an additional parameter such as $consider_duration true/false (default false) in the various methods (getOccurencesBetween, occursAt, etc.). At the moment, I'm not sure what is the best approach.

from php-rrule.

gordonzhao avatar gordonzhao commented on August 28, 2024

Yes, start - duration is what I use. You are right, it's just the function name confused me at the very beginning, and I read the code to find out what it does. I guess adding some comment should be alright?

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

I guess adding some comment should be alright?

Sure. I didn't realize the names would be confusing, so I didn't really comment these methods, but this is done now (feel free to add more if you want). I also updated the documentation of the wiki to make it clearer that there is no notion of duration.

from php-rrule.

marcorivm avatar marcorivm commented on August 28, 2024

The other option is to have an additional parameter such as $consider_duration true/false (default false) in the various methods (getOccurencesBetween, occursAt, etc.). At the moment, I'm not sure what is the best approach.

I think there might be something more suitable than an additional parameter, which IMHO seems kind of dirty. I think the RRule\Event approach would be nice, and should provide an abstraction layer for working with events with a given duration or without it.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

Alright. I'll need to finish the implementation of the recurrence set first (see #7) and then I'll see how I can make a nice additional layer to work with duration. This class would need to work with either a single recurrence rule, or a recurrence set. Right now I'm thinking something similar to a Decorator pattern.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

@marcorivm Did you close the issue because you don't need this feature anymore? Or because you found a workaround?

from php-rrule.

linquize avatar linquize commented on August 28, 2024

Use case: The start time is the same, but end time is different
Mon-Fri: 10am-7pm
Sat: 10am-6pm

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

@linquize Could you be a little bit more specific? How would like the lib to handle this use case exactly? And how is this use cased coded by the iCal format?

from php-rrule.

linquize avatar linquize commented on August 28, 2024

I have no idea how ical can represent this case.

from php-rrule.

eberkund avatar eberkund commented on August 28, 2024

Hello, I really need duration support for a project I am working on. I would be happy to join the discussion and help contribute. What is the status of #7?

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

@eberkund Hello! To summarize the status: duration (and DTEND) are not part of the scope of RRULE.

RRULE just gives you the start date of each occurrences and then it's up to you to simply add the duration to get the end time if you need it. In most projects I have heard of, this library is used for single dates (such as when to send a reminder for example), however if you need duration I reckon it's fairly easy to do one extra calculation on top.

Now if you want to make a lightweight helper class on top of RRule that does exactly that (i.e. works with 2 dates -start and end - instead of just the start date), why not, I'm open to consider adding it to the library. However I don't want this lib to become a complete iCal event parser - it wasn't designed for that and there are other libs that do it better already.

Happy to have new contributors anyway, so feel free to say what's on your mind!

from php-rrule.

eberkund avatar eberkund commented on August 28, 2024

I ended up writing a quick helper function to achieve what I needed for now however I wouldn't mind revisting this if there a more generic solution that can be implemented. But I am not comfortable enough in this domain to propose any sort of spec just yet. What are those libraries you mention that implement a more iCal features? I wouldn't mind taking a look.

from php-rrule.

rlanvin avatar rlanvin commented on August 28, 2024

@eberkund I have heard of sabre/vobject, but never tried it myself. If you do try it, I wouldn't mind getting your feedback, maybe it'll also help others who have the sames requirements as you.

I think the quick helper is the way to go with php-rrule because again this lib is really just meant to quickly & efficiently calculate recurring occurrences - it wasn't designed with full-fledged events in mind.

from php-rrule.

Related Issues (20)

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.