search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Error constructing DayPilot.Date()

Asked by Wouter
19 hours ago.

Hi,

I’m trying to convert a date (or date string) to a DayPilot.Date. This to assign the daypilot.date to the start of an event. However i am not capable of creating a new DayPilot.Date.

I’ve tried everything:

let newDate = new DayPilot.Date() => TypeError: Date is not a constructor
let newDate = new DayPilot.Date(angularDateType) => TypeError: Right-hand side of 'instanceof' is not callable
let newDate = new DayPilot.Date("2025-01-01") => Error: DayPilot.Date - Unable to parse ISO8601 date/time string: 2025-01-01

So i’m wondering what’s the correct way of creating a new DayPilot.Date object?

Kind regards,

Wouter

Comment posted by Wouter
19 hours ago.

Small update after testing some more scenarios:

let dateje = new DayPilot.Date("2025-03-01T00:00:00"); => This works without throwing errors
let dateje = new DayPilot.Date("2025-03-01T11:00:00"); => This throws DayPilot.Date - Unable to parse ISO8601 date/time string: 2025-03-01T11:00:00

Only difference is i changed 00:00:00 to 11:00:00

Answer posted by Dan Letecky [DayPilot]
17 hours ago.

Have you modified the source code? Or maybe you have overwritten the DayPilot.Date object?

Because all this should work fine - you can also test it in the JavaScript console in the online demo.

Comment posted by Wouter
17 hours ago.

I haven’t modified any source code. Seems that the issue is related to angular and it’s execution context rather than daypilot.

showEditEventDialog(event: DayPilot.Event) {
  let someDate = new DayPilot.Date();
  console.log(someDate);

  this.ref = this.openDialog(EditOrderDialog, header, {
    event: event,
  });

  this.ref.onClose.subscribe((result: { newStart: Date }) => {
    if (result) {
      let oldDate = new DayPilot.Date();
      console.log(oldDate);
      // this.eventService.handleOnEventEditAngular(event, result.newStart, this.scheduler);
    }
  });
}

it works perfectly fine in the beginning of the method. Yet in .onClose.Subscribe i’m getting the “Date is not a constructor error”. Seems like the callback is probably executed in a different context, where i have no access to DayPilot.

Unless you can see a different reason for this issue? :)

Comment posted by Dan Letecky [DayPilot]
16 hours ago.

It looks like the DayPilot object is not what you expect inside the callback. But that is not normal behavior, it should remain the same.

You can try the following to debug the issue:

1. Try printing the DayPilot object to console and inspect it:

  this.ref.onClose.subscribe((result: { newStart: Date }) => {
    if (result) {
      console.log("DayPilot", DayPilot);
      let oldDate = new DayPilot.Date();
      console.log(oldDate);
      // this.eventService.handleOnEventEditAngular(event, result.newStart, this.scheduler);
    }
  });

If you see the actual object, you may be able to find the problem. You could see this exception if you override the DayPilot object somewhere:

DayPilot = {};

2. Store the DayPilot object in a special variable. This doesn’t fix the source of the problem but it may be a workaround.

showEditEventDialog(event: DayPilot.Event) {
  let someDate = new DayPilot.Date();
  const DayPilotRef = DayPilot;
  console.log(someDate);

  this.ref = this.openDialog(EditOrderDialog, header, {
    event: event,
  });

  this.ref.onClose.subscribe((result: { newStart: Date }) => {
    if (result) {
      let oldDate = new DayPilotRef.Date();
      console.log(oldDate);
      // this.eventService.handleOnEventEditAngular(event, result.newStart, this.scheduler);
    }
  });
}
Comment posted by Wouter
14 hours ago.

Hi Dan,

I’ve recreated the angular component and started from scratch. Everything seems to be working as intended now! Thank you for your quick replies.

I’ll reassemble the component piece by piece until i find out where it went wrong. If it could be relevant for DayPilot i’ll update you with what exactly caused the issue.

Kind regards,

Wouter

Comment posted by Dan Letecky [DayPilot]
11 hours ago.

Hi Wouter,

Great, thanks!

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):