Git Product home page Git Product logo

Comments (7)

jkbrzt avatar jkbrzt commented on June 5, 2024

Can you give a more specific example of what you want to achieve?

from rrule.

khaledpro2012 avatar khaledpro2012 commented on June 5, 2024

example
FREQ=MINUTELY;DTSTART=20130827T003000Z;INTERVAL=30;WKST=MO;COUNT=10;UNTIL=20131227T023000Z; Starttime=03:00;Endtime=04:00

result
1 Tue Aug 27 2013 03:00:00 GMT+0300 (Arab Standard Time)
2 Tue Aug 27 2013 03:30:00 GMT+0300 (Arab Standard Time)

3 Tue Aug 28 2013 03:00:00 GMT+0300 (Arab Standard Time)
4 Tue Aug 28 2013 03:30:00 GMT+0300 (Arab Standard Time)

5 Tue Aug 29 2013 03:00:00 GMT+0300 (Arab Standard Time)
6 Tue Aug 29 2013 03:30:00 GMT+0300 (Arab Standard Time)

7 Tue Aug 30 2013 03:00:00 GMT+0300 (Arab Standard Time)
8 Tue Aug 30 2013 03:30:00 GMT+0300 (Arab Standard Time)

9 Tue Aug 31 2013 03:00:00 GMT+0300 (Arab Standard Time)
10 Tue Aug 31 2013 03:30:00 GMT+0300 (Arab Standard Time)

now return time in all day and go to next day
i need specific time in day

from rrule.

jkbrzt avatar jkbrzt commented on June 5, 2024

This can be done by filtering the result, such as:

var rule = RRule.fromString('FREQ=MINUTELY;DTSTART=20130827T003000Z;INTERVAL=30;WKST=MO;COUNT=10;UNTIL=20131227T023000Z');
var allDates = rule.all();

var filteredDates = []
for (var i = 0; i < allDates.length; i++) {
    var date = allDates[i], hours = date.getHours(), minutes = date.getMinutes();
    if (hours == 3 || (hours == 4 && minutes == 0)) {
         filteredDates.push(date);
    }
}
console.log(filteredDates);

from rrule.

khaledpro2012 avatar khaledpro2012 commented on June 5, 2024

thank you for help me

but i think Count option not get all result correct because will get all result in same day

example
var rule = RRule.fromString('FREQ=MINUTELY;DTSTART=20130827T003000Z;INTERVAL=30;WKST=MO;COUNT=10;UNTIL=20131227T023000Z');
var allDates = rule.all();

it will get top 10 in same day and loop filter get 2 record only

result
1 Tue Aug 27 2013 03:30:00 GMT+0300 (Arab Standard Time)
2 Tue Aug 27 2013 04:00:00 GMT+0300 (Arab Standard Time)
3 Tue Aug 27 2013 04:30:00 GMT+0300 (Arab Standard Time)
4 Tue Aug 27 2013 05:00:00 GMT+0300 (Arab Standard Time)
5 Tue Aug 27 2013 05:30:00 GMT+0300 (Arab Standard Time)
6 Tue Aug 27 2013 06:00:00 GMT+0300 (Arab Standard Time)
7 Tue Aug 27 2013 06:30:00 GMT+0300 (Arab Standard Time)
8 Tue Aug 27 2013 07:00:00 GMT+0300 (Arab Standard Time)
9 Tue Aug 27 2013 07:30:00 GMT+0300 (Arab Standard Time)
10 Tue Aug 27 2013 08:00:00 GMT+0300 (Arab Standard Time)

but i need that

1 Tue Aug 27 2013 03:00:00 GMT+0300 (Arab Standard Time)
2 Tue Aug 27 2013 03:30:00 GMT+0300 (Arab Standard Time)

3 Tue Aug 28 2013 03:00:00 GMT+0300 (Arab Standard Time)
4 Tue Aug 28 2013 03:30:00 GMT+0300 (Arab Standard Time)

5 Tue Aug 29 2013 03:00:00 GMT+0300 (Arab Standard Time)
6 Tue Aug 29 2013 03:30:00 GMT+0300 (Arab Standard Time)

7 Tue Aug 30 2013 03:00:00 GMT+0300 (Arab Standard Time)
8 Tue Aug 30 2013 03:30:00 GMT+0300 (Arab Standard Time)

9 Tue Aug 31 2013 03:00:00 GMT+0300 (Arab Standard Time)
10 Tue Aug 31 2013 03:30:00 GMT+0300 (Arab Standard Time)

from rrule.

khaledpro2012 avatar khaledpro2012 commented on June 5, 2024

i make update in code and now work fine

but i will test now all cases

string formula

FREQ=MINUTELY;timefrom=03:00;timeto=04:00;isparttime=1,DTSTART=20130828T000000Z;INTERVAL=30;WKST=MO;COUNT=10

and add to option parameter
timefrom ----> 03:00
timeto ----> 04:00
isparttime ---> 0 or 1

code update line 1252

add this code

.... code

if (freq < RRule.HOURLY) {
if (!iterResult.accept(res)) {
return iterResult.getValue();
}
}
else {

                                if (this.options.isparttime == 1) {
                                    var cutime = res.getHours().toString() + ":" + res.getMinutes().toString();

                                    var timefrom = this.options.timefrom;

                                    var timeto = this.options.timeto;


                                    if (dateCompare(cutime, timefrom) >= 0 && dateCompare(timeto, cutime) > 0) {

                                        if (!iterResult.accept(res)) {
                                            return iterResult.getValue();
                                        }

                                    }
                                    else {
                                        continue;
                                    }
                                }
                                else {

                                    if (!iterResult.accept(res)) {
                                        return iterResult.getValue();
                                    }


                                }
                            }

......code

add this method for compare time

function dateCompare(time1,time2) {
var t1 = new Date();
var parts = time1.split(":");
t1.setHours(parts[0],parts[1],0,0);
var t2 = new Date();
parts = time2.split(":");
t2.setHours(parts[0],parts[1],0,0);

// returns 1 if greater, -1 if less and 0 if the same
if (t1.getTime()>t2.getTime()) return 1;
if (t1.getTime()<t2.getTime()) return -1;
return 0;

}

from rrule.

jkbrzt avatar jkbrzt commented on June 5, 2024

There is no need for adding new options. You can achieve what you need already with the current API, and also adding new options would make it incompatible with the iCalendar standard. If you need extra filtering, you can either use the approach I showed above, or in your case it might be more suitable to use the iterator argument to rule.all():

// Create a rule with no COUNT
var rule = RRule.fromString('FREQ=MINUTELY;DTSTART=20130827T003000Z;INTERVAL=30;WKST=MO;UNTIL=20131227T023000Z');

var dates = [];
var limit = 10;

rule.all(function(date){
    // The iterator function allows for custom filtering 
    // and limiting the number of dates manually.
    // It's called for each date matched by the rule.

    // Does the date match our custom filter?
    if (date.getHours() == 3 || (date.getHours() == 4 && date.getMinutes() == 0)) {
        dates.push(date);  // Yup
        if (dates.length == limit) {
            return false;  // Stop iteration, we have enough dates
        }
    }
    return true;  // Continue iteration
});

console.log(dates);

from rrule.

khaledpro2012 avatar khaledpro2012 commented on June 5, 2024

Thank you I will use api to achieve this

Sent from my Windows Phone


From: Jakub Roztočilmailto:[email protected]
Sent: ‎8/‎28/‎2013 12:31 PM
To: jkbr/rrulemailto:[email protected]
Subject: Re: [rrule] I want to add features (#23)

There is no need for adding new options. You can achieve what you need already with the current API, and also adding new options would make it incompatible with the iCalendar standard. If you need extra filtering, you can either use the approach I showed above, or in your case it might be more suitable to use the iterator argument to rule.all():

// Create a rule with no COUNT
var rule = RRule.fromString('FREQ=MINUTELY;DTSTART=20130827T003000Z;INTERVAL=30;WKST=MO;UNTIL=20131227T023000Z');

var dates = [];
var limit = 10;

rule.all(function(date){
    // The iterator function allows for custom filtering
    // and limiting the number of dates manually.
    // It's called for each date matched by the rule.

    // Does the date match our custom filter?
    if (date.getHours() == 3 || (date.getHours() == 4 && date.getMinutes() == 0)) {
        dates.push(date);  // Yup
        if (dates.length == limit) {
            return false;  // Stop iteration, we have enough dates
        }
    }
    return true;  // Continue iteration
});

console.log(dates);

Reply to this email directly or view it on GitHub:
#23 (comment)

from 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.