Skip to content

Commit 11b5c12

Browse files
committed
Do not adjust the end date right if it is at 0:00
Fixes issue #2659
1 parent e712e2e commit 11b5c12

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

biz.ganttproject.impex.msproject2/src/main/java/biz/ganttproject/impex/msproject2/ProjectFileImporter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,16 @@ public Pair<TimeDuration, TimeDuration> apply(Task t) {
614614
if (t.getMilestone()) {
615615
return Pair.create(getTaskManager().createLength(1), null);
616616
}
617-
return getDurations(t.getStart(), myNativeProject.getTimeUnitStack().getDefaultTimeUnit().adjustRight(t.getFinish()));
617+
var defaultTimeUnit = myNativeProject.getTimeUnitStack().getDefaultTimeUnit();
618+
var finishDate = t.getFinish();
619+
// If the finish time is at the midnight between the finish date and the next day then
620+
// this if condition will evaluate to false. Otherwise, e.g. when the finish date is at 20:00, we
621+
// will adjust it to the right properly.
622+
// Without this hack we would add one day to such tasks.
623+
if (defaultTimeUnit.adjustLeft(finishDate).before(finishDate)) {
624+
finishDate = defaultTimeUnit.adjustRight(finishDate);
625+
}
626+
return getDurations(t.getStart(), finishDate);
618627
}
619628
};
620629

ganttproject-tester/test/biz/ganttproject/impex/msproject2/ProjectCalendarTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import net.sf.mpxj.ProjectFile
2626
import net.sourceforge.ganttproject.GanttProjectImpl
2727
import net.sourceforge.ganttproject.TestSetupHelper
2828
import net.sourceforge.ganttproject.importer.ImporterFromGanttFile
29+
import org.junit.jupiter.api.BeforeEach
2930
import org.junit.jupiter.api.Test
3031
import java.awt.Color
3132
import java.io.File
@@ -54,6 +55,7 @@ fun initLocale() {
5455
* Tests project calendar export and import.
5556
*/
5657
class ProjectCalendarTest: TestCase() {
58+
@BeforeEach
5759
override fun setUp() {
5860
super.setUp()
5961
initLocale()
@@ -137,5 +139,17 @@ class ProjectCalendarTest: TestCase() {
137139
.build().get(Calendar.WEEK_OF_YEAR))
138140
}
139141

142+
@Test
143+
fun `issue 2659`() {
144+
val project = GanttProjectImpl()
145+
val columns = ImporterFromGanttFile.VisibleFieldsImpl()
146+
val fileUrl = ProjectCalendarTest::class.java.getResource("/issue2659.xml")
147+
assertNotNull(fileUrl)
148+
val importer = ProjectFileImporter(project, columns, File(fileUrl.toURI()))
149+
importer.setPatchMspdi(false)
150+
importer.run()
151+
152+
assertEquals(1, project.taskManager.tasks[0].duration.length)
153+
}
140154
}
141155

0 commit comments

Comments
 (0)