Our pure JavaScript Scheduler component


Post by burnit »

Hi,

how can i calculate the end Date, based on duration and startDate?
I found this in the Gantt Product aread, but i doesn't works on the scheduler.

calendar.calculateEndDate(eventRecord.getStartDate(), 13, "idOfTheEvent");

Many thanks!


Post by mats »

Do you need working time calendars? Then you'd need Scheduler Pro. If not you can simply use: https://bryntum.com/products/scheduler/docs/api/Core/helper/DateHelper#function-add-static


Post by burnit »

Hi Mats,

yes we need working time caldendars, and we would license Scheduler Pro.
But how can i calculate it then?


Post by marcio »

Hey burnit,

You can use DateHelper for that purpose, you can write something like this:

DateHelper.add(currentStartDate, currentDuration, 'days');

https://bryntum.com/products/schedulerpro/docs/api/Core/helper/DateHelper#function-add-static

Best regards,
Márcio


Post by arcady »

The EventModel has calculateProjectedXDateWithDuration (https://www.bryntum.com/products/schedulerpro/docs/engine/classes/_lib_engine_quark_model_scheduler_pro_schedulerproevent_.schedulerproevent.html#calculateprojectedxdatewithduration) method that can calculate start or end date:

const endDate = yield* task.calculateProjectedXDateWithDuration(startDate, true, duration)

Post by burnit »

Thanks! But how can i access this method?
It is not working with

schedulerPro.current.instance.calculateProjectedXDateWithDuration

Post by mats »

It's a method on the EventModel class, so you'd call it as

const scheduler = schedulerPro.current.instance,
task = scheduler.eventStore.getById(123) // your task;
const endDate = yield* task.calculateProjectedXDateWithDuration(startDate, true, duration);

Post by burnit »

Thanks Mats.

That's my code now:

function* calculateEndDate(task, startDate, isForward, duration) {
  const endDate = yield* task.calculateProjectedXDateWithDuration(startDate, isForward, duration);
  return endDate
}
const endDate = calculateEndDate(eventRecord, eventRecord.startDate, true, 12);
console.log(endDate)
console.log(endDate.next())

The console logs show me: [[GeneratorState]]: "suspended"

Any ideas?


Post by arcady »

A generator is supposed to be called like this:

const endDate = yield* calculateEndDate(eventRecord, eventRecord.startDate, true, 12);

Post by burnit »

When i try to use this, i get following error message from the compiler : "Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode."

const endDate = yield* eventRecord.calculateProjectedXDateWithDuration(eventRecord.startDate, true, eventRecord.duration);

If i put it in a function

  function* calculateEndDate2(event) {
    yield* event.calculateProjectedXDateWithDuration(event.startDate, true, 4);
  }
  const endDate = calculateEndDate2(eventRecord);
  console.log(endDate.next());

My result is:

{
done: false
value: k {
DATA: undefined
context: e {originalData: {…}, meta: {…}, _internalId: 42, stores: Array(1), segmentModelClass: ƒ, …} name:  "e-e6caae03-28f7-4b84-b4fa-e71570ba1d5e.$.durationUnit"
self:  e {originalData: {…}, meta: {…}, _internalId: 42, stores: Array(1), segmentModelClass: ƒ, …}
}}

Post Reply