0

first of all please forgive my broken English. I'm facing a issue.

Currently my project is a announcement system project. Then user can add new announcement in my calendar. So my calendar can have many options.

Now problem is, let say my calendar announcement have four record:

  1. Title: Announcement Adhoc 1 StartDate: 2017-09-26 StartTime: 00:00 RecurrencePattern: Adhoc EndDate: 2017-09-26 EndTime: 00:03

  2. Title: Announcement Daily 1 StartDate: 2017-09-26 StartTime: 01:00 RecurrencePattern: Daily EndDate: 2017-09-26 EndTime: 01:03

  3. Title: Announcement Weekly StartDate: 2017-09-26 StartTime: 02:00 RecurrencePattern: Weekly Days: ["1","3","4"] //This is getDate() and store EndDate: 2017-09-26 EndTime: 02:03

  4. Title: Announcement Monthly StartDate: 2017-09-26 StartTime: 03:00 RecurrencePattern: Monthly EndDate: 2017-09-26 EndTime: 03:03

and now i would like to add a new Announcement record which is cannot match in between the StartDate StartTime and EndDate EndTime in those records. What should i do?

Note:

  1. Adhoc only play one time.

  2. Daily will play everyday based on the Start Time until the End Time.

  3. Weekly will play based on the days, Start Time and End Time.

  4. Monthly will play based on the Date of the Month, Start Time and End Time.

Hope you all understand what I'm asking and your help would save my life.

Thanks you so much.

Here is my code:

var NewAddStartDateTime = "2016-09-27T13:11:00";
var NewAddEndDateTime = "2016-09-27T13:20:00";

var jsonObj = [{
  "id": 1,
  "type": "Adhoc",
  "days": [],
  "startDateTime": "2016-09-28T13:11:00",
  "endDateTime": "2016-09-28T13:19:00"
}, {
  "id": 2,
  "type": "Weekly",
  "days": ["1", "3", "4"],
  "startDateTime": "2016-09-28T13:11:00",
  "endDateTime": "2016-09-28T13:19:00"
}]

//jsonObj[i].startDateTime = "2016-09-27T13:11:00"
//jsonObj[i].endDateTime = "2016-09-27T13:19:00"

for (var i = 0; i < jsonObj.length; i++) {
  if ((NewAddStartDateTime > jsonObj[i].startDateTime && NewAddStartDateTime < jsonObj[i].endDateTime) || NewAddStartDateTime == jsonObj[i].startDateTime || (NewAddEndDateTime > jsonObj[i].startDateTime && NewAddEndDateTime < jsonObj[i].endDateTime)) {
    console.log("cannot add because in between the date match Adhoc");
    CannotAdd = true;
    QuitLoop = true;
    break;
  }
}
RobG
  • 142,382
  • 31
  • 172
  • 209
  • Welcome to StackOverflow! Have you tried anything so far? StackOverflow isn't a free code-writing service, and expects you to [try to solve your own problem first](http://meta.stackoverflow.com/questions/261592). Please update your question to show what you have already tried, showing the specific problem you are facing in a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). For further information, please see [how to ask a good question](http://stackoverflow.com/help/how-to-ask), and take the [tour of the site](http://stackoverflow.com/tour) – Jaromanda X Sep 28 '17 at 04:05
  • Ya im already tried but seem like not working. Okay i try to update and show the code in my post. – New Developer 2017 Sep 28 '17 at 04:11
  • @NewDeveloper2017—please note the "minimal" part. ;-) – RobG Sep 28 '17 at 04:18
  • Alright updated, hopefully you all understand my code. :) – New Developer 2017 Sep 28 '17 at 04:23
  • Are you just trying to see if each new "announcement" overlaps, or is contained within, another announcement? If so, it may be a duplicate of [*Accept date from user within particular range*](https://stackoverflow.com/questions/42508026/accept-date-from-user-within-particular-range). BTW, "jsonObj" is a misnomer, you have an array of objects. – RobG Sep 28 '17 at 06:31
  • @RobG yup, im trying to add a new announcement, but before that, i have to loop all the object array record to check the new announcement start date and end date is have overlaps or contained within another announcement or not. If yes, then i cant add the new announcement. I was tried 3 days but still cant get a good solution. So i no choice have to post this question at here. – New Developer 2017 Sep 28 '17 at 07:05

0 Answers0