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

Uncaught DayPilot.Duration(): Invalid start argument, DayPilot.Date expected

Asked by CARLOS MIGUEL LOPEZ DURAÑONA
1 month ago.

I’m getting the error Uncaught DayPilot.Duration(): Invalid start argument, DayPilot.Date expected and my events are not being loaded from the database. I have this:

scheduler.events.load("/api/Tasks");

In my controller class:

// GET: api/Tasks
[HttpGet]
public async Task<ActionResult<IEnumerable<Task>>> GetTasks()
{
  return await _context.Tasks.ToListAsync();
}

And in my model:

public class Task
{
  [Key]
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int Id { get; set; }
  public DateTime Start { get; set; }
  public DateTime End { get; set; }
  [JsonPropertyName("resource")]
  public int ResourceId { get; set; }
  [JsonIgnore, IgnoreDataMember]
  public Machine Machine { get; set; }
  public string Text { get; set; }
  public string Color { get; set; }
  public int JobId { get; set; }
  public int? NextId { get; set; }
}

When I print with console.log() I can see the data:

{id: 1, start: '2024-10-01T09:00:00', end: '2024-10-01T10:00:00', resource: 1, text: 'Carlos',…}

Thanks for any help.

Comment posted by Dan Letecky [DayPilot]
1 month ago.

Could you please post the full stack trace of the JavaScript error?

Comment posted by CARLOS MIGUEL LOPEZ DURAÑONA
1 month ago.

Uncaught DayPilot.Duration(): Invalid start argument, DayPilot.Date expected That is all that I can see in the browser console.

Comment posted by CARLOS MIGUEL LOPEZ DURAÑONA
1 month ago.

The error occur in this section of your code:

if (2 === arguments.length) {
    console.log(arguments);
    var o = arguments[0],
        s = arguments[1];

    if (!(o instanceof DayPilot.Date) && typeof o !== "string") {
        throw "DayPilot.Duration(): Invalid start argument, DayPilot.Date expected";
    }

    if (!(s instanceof DayPilot.Date) && typeof s !== "string") {
        throw "DayPilot.Duration(): Invalid end argument, DayPilot.Date expected";
    }

    if (typeof o === "string") {
        o = new DayPilot.Date(o);
    }

    if (typeof s === "string") {
        s = new DayPilot.Date(s);
    }

    e = s.getTime() - o.getTime();
}

I put the console.log to see the arguments:

0: DayPilot.Date {value: '2024-11-01T09:00:00'}

1: DayPilot.Date {value: '2024-11-01T10:00:00'}

If I comment that section the component works as expected.

Answer posted by Dan Letecky [DayPilot]
25 days ago.

Yes, this is where the exception comes from, but the stack trace points to the code that uses it. That would help identify the problem.

According to your log, both objects are DayPilot.Date but they can be from a different context - e.g. if you import two different versions of the library. That’s why the instanceof check might fail.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.