Skip to content

GetOccurrences ignores occurrences that should replace generated occurrences #4

@ditchcode

Description

@ditchcode
using System;
using System.Collections.Generic;
using DHTMLX.Scheduler;
using DHTMLX.Scheduler.RecurringEvents;

public class Program
{
	public static void Main()
	{
		var timestampForOccurrenceJanuary3 = Convert.ToInt32(((new DateTime(2019, 1, 3, 13, 0, 0)) - (new DateTime(1970, 1, 1))).TotalSeconds);
		
		var schEvents = new[]{
			new SchedulerEvent {
				id = "1",
				text = "birthday",
				start_date = new DateTime(2019, 1, 2, 13, 0, 0),
				end_date = new DateTime(2019, 1, 5, 13, 0, 0),
				rec_type = "day_1___",
				event_length = 1800,				
			},
			new SchedulerEvent {
				id = "1#January3",
				text = "reschedule Jan 3 to Jan 10",
				start_date = new DateTime(2019, 1, 10, 12, 0, 0),
				end_date = new DateTime(2019, 1, 10, 12, 30, 0),
				rec_type = "",
				event_length = timestampForOccurrenceJanuary3,	
				event_pid = "1"
			},
		};
		
		//because event id 2 falls outside the From-To of 1/1 to 1/9, the event is bypassed and never replaces the occurrence generated for 1/3
		var occurrences = new RecurringEventsHelper().GetOccurrences(schEvents, new DateTime(2019, 1, 1), new DateTime(2019, 1, 9));
		foreach(var o in occurrences)
		{
			Console.WriteLine(o);
			/*
			id = 1
			text = birthday
			start_date = 2019-01-02 13:00
			end_date = 2019-01-02 13:30
			rec_type = 
			event_length = 0
			event_pid = 

			id = 1
			text = birthday
			start_date = 2019-01-03 13:00 <=========== SHOULD HAVE BEEN RESCHEDULED TO 1/10
			                                           AND NOT RETURNED IN THE RESULTS
					                           BECAUSE IT FALLS OUTSIDE OUR FROM-TO OF 1/1 to 1/9
			end_date = 2019-01-03 13:30
			rec_type = 
			event_length = 0
			event_pid = 

			id = 1
			text = birthday
			start_date = 2019-01-04 13:00
			end_date = 2019-01-04 13:30
			rec_type = 
			event_length = 0
			event_pid = 
			*/
		}
		
		//because event id 2 falls within the From-To of 1/1 to 1/15, the event correctly replaces the occurrence generated for 1/3
		occurrences = new RecurringEventsHelper().GetOccurrences(schEvents, new DateTime(2019, 1, 1), new DateTime(2019, 1, 15));
		foreach(var o in occurrences)
		{
			Console.WriteLine(o);
			/*
			id = 1
			text = birthday
			start_date = 2019-01-02 13:00
			end_date = 2019-01-02 13:30
			rec_type = 
			event_length = 0
			event_pid = 

			id = 1
			text = birthday
			start_date = 2019-01-04 13:00
			end_date = 2019-01-04 13:30
			rec_type = 
			event_length = 0
			event_pid = 

			id = 1#January3
			text = reschedule Jan 3 to Jan 10
			start_date = 2019-01-10 12:00
			end_date = 2019-01-10 12:30
			rec_type = 
			event_length = 1546520400
			event_pid = 1
			*/
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions