Import from dhtmlxGantt#

Load a dhtmlxGantt project into Planning Engine and get the same task dates the gantt auto-scheduler would give you.

Planning Engine's scheduling step is a port of the dhtmlxGantt v2 auto-scheduling engine, and its input uses gantt's field names (start_date, duration, parent, constraint_type, auto_scheduling). Most of the import copies fields one to one. The steps below cover the places where a straight copy gives different dates or fails validation.

Prerequisites#

  • Your gantt tasks, links, resources and assignments are parsed into your own Rust records. plen-core has no JSON input. For typed JSON input, use the plen-wire crate or the plen CLI.
  • You know each task's effective calendar, as gantt resolves it.
  • The example parses dates with chrono (cargo add chrono).

Steps#

  1. Set the scheduling config to gantt's model. Use CalendarMode::Task for task calendars only, or CalendarMode::TaskInherited if gantt has inherit_calendar: true. Copy gantt's work_time into use_calendars explicitly. If you leave use_calendars out, Planning Engine schedules on calendars:

    use plen_core::{CalendarMode, SchedulingConfig};
    
    let gantt_work_time = true; // gantt `config.work_time`
    
    let config = SchedulingConfig {
        calendar_mode: CalendarMode::Task,
        use_calendars: gantt_work_time,
        ..Default::default()
    };
    

    Set root_id only when gantt's virtual root isn't 0. The other auto-scheduling options (apply_constraints, gap_behavior, move_projects, schedule_from_end, project_start, use_progress) keep their gantt names.

  2. Add one CalendarData per calendar your tasks use, and set each task's calendar_id to its effective calendar. gantt picks that calendar in its adapter: the task's own, else its resource's, else a calendar merged from all its resources, else the parent's. Send the result, not the rules. A merged resource calendar goes in once, under its synthetic id. Don't repeat gantt's precedence or merging in your import code.

  3. Map each task to a TaskData:

    • gantt type: "project" becomes TaskType::Summary. A summary takes both start_date and end_date, or neither. Drop its duration, or strict validation rejects the task.
    • A parent equal to root_id means "no parent". You can copy it as is.
    • A leaf task needs two of start_date, end_date and duration. If you send all three, they must agree.
    • If your gantt event handlers cancel auto-scheduling for a task, set auto_scheduling: false on it. The planner never moves it.
  4. Map gantt link type values "0", "1", "2" and "3" to LinkType::Fs, Ss, Ff and Sf. Copy lag and leave lag_unit as None, because gantt measures lag in config.duration_unit.

  5. Convert each assignment to a slice of its task's work. Don't send gantt's mode.

    • default and fixedDuration: delay becomes offset and duration stays duration. Leave both None to book the whole task.
    • fixedDates: set offset and duration to the worked time its dates cover, measured from the task start.

    A slice ends at the task end. gantt's fixedDuration can run past it.

  6. Solve the data with Project::solve and write the changed fields from result.updates back into gantt. The updates include summaries, which the gantt JS adapter leaves to gantt core. Apply those too, or your summary spans go stale.

The full example below imports a summary with two tasks, a milestone, two links, a part-time calendar and one default-mode assignment:

use chrono::NaiveDateTime;
use plen_core::{
    AssignmentData, CalendarData, CalendarMode, DateTime, Id, LinkData, LinkType, Project,
    ProjectData, ResourceData, SchedulingConfig, SolveOptions, TaskData, TaskType, Worktime,
};

// Records as your server holds them after parsing gantt's JSON.
struct GanttTask {
    id: i32,
    parent: i32,
    kind: &'static str, // gantt `type`
    start_date: &'static str,
    end_date: Option<&'static str>,
    duration: f64,
    calendar_id: &'static str, // effective calendar, already resolved by gantt
}

struct GanttLink {
    id: i32,
    source: i32,
    target: i32,
    kind: &'static str, // gantt `type`: "0".."3"
    lag: f64,
}

struct GanttAssignment {
    id: i32,
    task_id: i32,
    resource_id: &'static str,
    value: f64,
    delay: Option<f64>,    // `default` and `fixedDuration` modes
    duration: Option<f64>, // `default` and `fixedDuration` modes
}

fn date(s: &str) -> Result<DateTime, chrono::ParseError> {
    // Use the format your gantt `date_format` produces.
    Ok(NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M")?.into())
}

fn link_type(kind: &str) -> Option<LinkType> {
    match kind {
        "0" => Some(LinkType::Fs),
        "1" => Some(LinkType::Ss),
        "2" => Some(LinkType::Ff),
        "3" => Some(LinkType::Sf),
        _ => None,
    }
}

fn task(g: &GanttTask) -> Result<TaskData, chrono::ParseError> {
    let mut t = TaskData::new(g.id);
    t.parent = Some(Id::from(g.parent)); // gantt's root (0) becomes "no parent"
    t.start_date = Some(date(g.start_date)?);
    t.calendar_id = Some(g.calendar_id.into());
    match g.kind {
        "project" => {
            // A summary takes both dates or neither, never a duration.
            t.task_type = TaskType::Summary;
            t.end_date = g.end_date.map(date).transpose()?;
            if t.end_date.is_none() {
                t.start_date = None;
            }
        }
        "milestone" => {
            t.task_type = TaskType::Milestone;
            t.duration = Some(0.0);
        }
        _ => t.duration = Some(g.duration),
    }
    Ok(t)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let gantt_tasks = [
        GanttTask { id: 1, parent: 0, kind: "project", start_date: "2026-03-02 00:00", end_date: Some("2026-03-07 00:00"), duration: 5.0, calendar_id: "global" },
        GanttTask { id: 2, parent: 1, kind: "task", start_date: "2026-03-02 00:00", end_date: None, duration: 3.0, calendar_id: "global" },
        GanttTask { id: 3, parent: 1, kind: "task", start_date: "2026-03-02 00:00", end_date: None, duration: 4.0, calendar_id: "part-time" },
        GanttTask { id: 4, parent: 0, kind: "milestone", start_date: "2026-03-02 00:00", end_date: None, duration: 0.0, calendar_id: "global" },
    ];
    let gantt_links = [
        GanttLink { id: 1, source: 2, target: 3, kind: "0", lag: 0.0 },
        GanttLink { id: 2, source: 1, target: 4, kind: "0", lag: 0.0 },
    ];
    let gantt_assignments = [GanttAssignment {
        id: 1, task_id: 3, resource_id: "dev", value: 1.0, delay: Some(1.0), duration: Some(2.0),
    }];

    let config = SchedulingConfig {
        calendar_mode: CalendarMode::Task, // gantt's calendar model
        use_calendars: true,               // gantt `config.work_time`
        ..Default::default()
    };

    let calendars = vec![
        CalendarData { id: "global".into(), worktime: None },
        CalendarData {
            id: "part-time".into(),
            worktime: Some(Worktime {
                days: Some([false, true, true, true, true, false, false]), // Mon-Thu
                ..Default::default()
            }),
        },
    ];

    let tasks = gantt_tasks.iter().map(task).collect::<Result<Vec<_>, _>>()?;

    let mut links = Vec::new();
    for g in &gantt_links {
        links.push(LinkData {
            id: g.id.into(),
            source: g.source.into(),
            target: g.target.into(),
            link_type: link_type(g.kind).ok_or("unknown link type")?,
            lag: g.lag,
            lag_unit: None,
        });
    }

    let assignments = gantt_assignments
        .iter()
        .map(|g| AssignmentData {
            id: Some(g.id.into()),
            task: g.task_id.into(),
            resource: g.resource_id.into(),
            value: g.value,
            offset: g.delay,
            duration: g.duration,
        })
        .collect();

    let data = ProjectData {
        config,
        calendars,
        tasks,
        links,
        resources: vec![ResourceData { id: "dev".into(), capacity: None, calendar_id: None }],
        assignments,
    };

    let mut project = Project::default();
    let result = project.solve(Some(data), &SolveOptions::default())?;

    for m in &result.updates {
        // Only changed fields are set. Summaries are included: write them back too.
        if let Some(start) = m.start_date {
            println!("{} start_date = {}", m.id, start);
        }
        if let Some(end) = m.end_date {
            println!("{} end_date = {}", m.id, end);
        }
    }
    Ok(())
}

Keep gantt's triggers on your side#

Planning Engine has no UI triggers and no events. Your code decides when to schedule.

  • Call apply and then solve(None, ...) wherever gantt would run auto-scheduling: after the user adds a link, drags a task, or saves the lightbox. See Data Updates.
  • gantt.autoSchedule(id, inclusive) is SolveOptions::subtree. See Reschedule a branch.
  • Change sets can't add or edit calendars. If an assignment change gives a task a new merged calendar, send the whole project again with solve(Some(data), ...).
  • gantt core rewrites descendant dates when inherited calendars or effort change. Forward those date and duration edits as ordinary TaskUpdate changes. Planning Engine doesn't recreate gantt's effort rules.

Differences to expect#

  • Strict validation rejects input that gantt coerces: duplicate ids, a dated constraint with no constraint_date, a leaf task with fewer than two of start, end and duration, a dateless summary with no dated children. To get gantt's coercions with a report of each fix, see Accept messy input.
  • week, month and year duration units and calendars with customWeeks are rejected. A gantt merged calendar can contain customWeeks, so such projects can't be imported yet.
  • Dates are naive local date-times with no timezone and no DST. gantt's JS engine uses the host time zone, so its arithmetic follows DST. Convert dates to naive local time before you build the data.
  • result.notes lists the links, tasks and assignments the engine dropped. gantt drops them silently.
  • Three cases give different dates on purpose. With project_constraint: true, children inherit the parent's constraint. gantt's engine ignores it. With use_progress, a completed child of a moving summary stays in place. gantt drags it along. With descendant_links: true in block mode, gantt fails with a cycle error and Planning Engine schedules the project. See Links, constraints and summaries.
  • Summary-to-summary links in block mode, combined with leaf links between the same summaries, can give different dates. On very large generated graphs the call can panic. See Error handling.

Result#

The example prints the changed fields:

3 start_date = 2026-03-05 00:00
3 end_date = 2026-03-12 00:00
1 end_date = 2026-03-12 00:00
4 start_date = 2026-03-12 00:00
4 end_date = 2026-03-12 00:00

Task 3 starts when task 2 finishes and works Monday to Thursday only, so it ends a week later. The summary 1 grows to cover it. Task 2 didn't move, so it isn't listed. To get every date on the first load, see Load all task dates.