Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properties.setStartDate and task.setStart are not working #796

Open
djjty opened this issue Jan 22, 2025 · 0 comments
Open

properties.setStartDate and task.setStart are not working #796

djjty opened this issue Jan 22, 2025 · 0 comments

Comments

@djjty
Copy link

djjty commented Jan 22, 2025

I'm not sure if there are any other factors that haven't been considered, but I used official examples to test and it seems that mpxj doesn't work on setting project time, task start time, and finish time. There is no time data in the generated xer file. Is there any other way?

example:

import jpype
import mpxj

jpype.startJVM()
from java.lang import Double
from java.time import LocalDate, LocalDateTime
from net.sf.mpxj import ProjectFile, TaskField, Duration, TimeUnit, RelationType, Availability, Relation
from net.sf.mpxj.common import LocalDateTimeHelper
from net.sf.mpxj.writer import UniversalProjectWriter, FileFormat

file_name = "test.xer"
file_format = FileFormat.XER

file = ProjectFile()

calendar = file.addDefaultBaseCalendar()

calendar.addCalendarException(LocalDate.of(2006, 3, 13), LocalDate.of(2006, 3, 13))

properties = file.getProjectProperties()
properties.setStartDate(LocalDateTime.of(2003, 1, 1, 8, 0))

properties.setProjectTitle("Created by MPXJ")
properties.setAuthor("Jon Iles")

customFields = file.getCustomFields()
field = customFields.getOrCreate(TaskField.TEXT1)
field.setAlias("My Custom Field")

resource1 = file.addResource()
resource1.setName("Resource1")

resource2 = file.addResource()
resource2.setName("Resource2")
resource2.getAvailability().add(Availability(LocalDateTimeHelper.START_DATE_NA, LocalDateTimeHelper.END_DATE_NA, Double.valueOf(50.0)));

task1 = file.addTask()
task1.setName("Summary Task")

task2 = task1.addTask()
task2.setName("First Sub Task")
task2.setDuration(Duration.getInstance(10.5, TimeUnit.DAYS))
task2.setActualDuration(Duration.getInstance(10.5, TimeUnit.DAYS))
task2.setStart(LocalDateTime.of(2015, 1, 1, 8, 0))
task2.setFinish(LocalDateTime.of(2015, 1, 1, 8, 0))
task2.setActualFinish(LocalDateTime.of(2015, 1, 1, 8, 0))
task2.setText(1, "My Custom Value 1")

task2.setPercentageComplete(Double.valueOf(50.0))
task2.setActualStart(LocalDateTime.of(2003, 1, 1, 8, 0))

task3 = task1.addTask()
task3.setName("Second Sub Task")
task3.setStart(LocalDateTime.of(2003, 1, 11, 8, 0))
task3.setDuration(Duration.getInstance(10, TimeUnit.DAYS))
task3.setText(1, "My Custom Value 2")

task3.addPredecessor(Relation.Builder().targetTask(task2))

milestone1 = task1.addTask()
milestone1.setName("Milestone")
milestone1.setStart(LocalDateTime.of(2003, 1, 21, 8, 0))
milestone1.setDuration(Duration.getInstance(0, TimeUnit.DAYS))
milestone1.addPredecessor(Relation.Builder().targetTask(task3))

task4 = file.addTask()
task4.setName("Next Task")
task4.setDuration(Duration.getInstance(8, TimeUnit.DAYS))
task4.setStart(LocalDateTime.of(2003, 1, 1, 8, 0))
task4.setPercentageComplete(Double.valueOf(70.0))
task4.setActualStart(LocalDateTime.of(2003, 1, 1, 8, 0))

assignment1 = task2.addResourceAssignment(resource1)
assignment2 = task3.addResourceAssignment(resource2)

assignment1.setWork(Duration.getInstance(80, TimeUnit.HOURS))
assignment1.setActualWork(Duration.getInstance(40, TimeUnit.HOURS))

assignment1.setRemainingWork(Duration.getInstance(40, TimeUnit.HOURS))
assignment2.setRemainingWork(Duration.getInstance(80, TimeUnit.HOURS))
assignment1.setStart(LocalDateTime.of(2003, 1, 1, 8, 0))
assignment2.setStart(LocalDateTime.of(2003, 1, 11, 8, 0))

task5 = file.addTask()
task5.setName("Last Task")
task5.setDuration(Duration.getInstance(3, TimeUnit.DAYS))
task5.setStart(LocalDateTime.of(2003, 1, 1, 8, 0))
task5.setPercentageComplete(Double.valueOf(100.0))
task5.setActualStart(LocalDateTime.of(2003, 1, 1, 8, 0))

task6 = file.addTask()
task6.setName("Last Milestone")
task6.setDuration(Duration.getInstance(0, TimeUnit.DAYS))
task6.setStart(LocalDateTime.of(2003, 1, 1, 8, 0))
task6.setPercentageComplete(Double.valueOf(100.0))
task6.setActualStart(LocalDateTime.of(2003, 1, 1, 8, 0))

writer = UniversalProjectWriter(file_format).write(file, file_name)

jpype.shutdownJVM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant