0

I was told to use the MPXJ to generate a project file with task that spans no more than several hours, or even minutes only. Everything seems to work when the duration of a task is specified in days, or if the task doesn't have resources assigned. But if the task has resources assigned and has to start or finish at a specified time (for example, at 14:35), despite I'm specifying the time in the code, when I load the generated file in MS Project, time is ignored. We can show the effect using this file included with MPXJ source code. Let's change the start date of the task3 to include time:

//
// Create the second sub task
//
Task task3 = task1.addTask();
task3.setName("Second Sub Task");
task3.setStart(df.parse("11/01/2003 14:00"));
task3.setDuration(Duration.getInstance(10, TimeUnit.DAYS));

But when I load the generated file using MS Project, this is what happens:

Wrong time

How can I specify the start and end time of a task so MS Project respects it?

amedina
  • 2,838
  • 3
  • 19
  • 40

1 Answers1

0

I think the date format you are working with in the sample code is not set up to parse the time component of the string you are passing:

SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

You probably need something like this:

SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");

Jon Iles
  • 2,519
  • 1
  • 20
  • 30
  • I updated it before trying to specify the time. No, it doesn't work. – amedina Dec 21 '16 at 12:00
  • I'll try to get an example working for you if I get some time today. On a related note, it looks like the version of MPXJ you are working with (based on the link to the sample file) is very out of date. – Jon Iles Dec 21 '16 at 12:08
  • It's the code I found online. In reality I have the lastest version installed on my machine (I downloaded it a week ago). I have tried many things, even different file formats. Now I'm using `MSPDIWriter`, because it's the one that produces the best results (for what my boss wants me to do). Thank you very much for your help. – amedina Dec 21 '16 at 12:14