Skip to content

Commit

Permalink
Calendar exception dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
joniles committed Jan 3, 2018
1 parent e0847be commit 034818b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion maven/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<body>
<release date="git master" version="7.1.0">
<action dev="joniles" type="add">Added support for reading GanttProject files.</action>
<action dev="joniles" type="update">Correctly read working day calendar exceptions from XER files and P6 database.</action>
<action dev="joniles" type="fix">Ensure that calendar exception dates are read correctly from XER files and P6 databases regardless of the user's timezone.</action>
<action dev="joniles" type="update">Read working day calendar exceptions from XER files and P6 database.</action>
<action dev="joniles" type="update">Mark some ProjectFile methods as deprecated.</action>
</release>
<release date="21/12/2017" version="7.0.3">
Expand Down
10 changes: 10 additions & 0 deletions src/net/sf/mpxj/common/DateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@ public static Date getTimeFromMinutesPastMidnight(Integer time)
*/
public static final Date LAST_DATE = DateHelper.getTimestampFromLong(2524607946000L);

/**
* Number of milliseconds per minute.
*/
public static final long MS_PER_MINUTE = 60 * 1000;

/**
* Number of milliseconds per day.
*/
public static final long MS_PER_DAY = 24 * 60 * MS_PER_MINUTE;

/**
* Default value to use for DST savings if we are using a version
* of Java < 1.4.
Expand Down
16 changes: 3 additions & 13 deletions src/net/sf/mpxj/mpp/MPPUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static final Date getDate(byte[] data, int offset)
}
else
{
result = DateHelper.getDateFromLong(EPOCH + (days * MS_PER_DAY));
result = DateHelper.getDateFromLong(EPOCH + (days * DateHelper.MS_PER_DAY));
}

return (result);
Expand Down Expand Up @@ -356,7 +356,7 @@ public static final Date getTime(byte[] data, int offset)
*/
public static final long getDuration(byte[] data, int offset)
{
return ((getShort(data, offset) * MS_PER_MINUTE) / 10);
return ((getShort(data, offset) * DateHelper.MS_PER_MINUTE) / 10);
}

/**
Expand Down Expand Up @@ -390,7 +390,7 @@ public static final Date getTimestamp(byte[] data, int offset)
{
time = 0;
}
result = DateHelper.getTimestampFromLong((EPOCH + (days * MS_PER_DAY) + ((time * MS_PER_MINUTE) / 10)));
result = DateHelper.getTimestampFromLong((EPOCH + (days * DateHelper.MS_PER_DAY) + ((time * DateHelper.MS_PER_MINUTE) / 10)));
}

return (result);
Expand Down Expand Up @@ -1438,16 +1438,6 @@ public static Date getEpochDate()
*/
private static Date EPOCH_DATE = DateHelper.getTimestampFromLong(EPOCH);

/**
* Number of milliseconds per day.
*/
private static final long MS_PER_DAY = 24 * 60 * 60 * 1000;

/**
* Number of milliseconds per minute.
*/
private static final long MS_PER_MINUTE = 60 * 1000;

/**
* Constants used to convert bytes to hex digits.
*/
Expand Down
9 changes: 3 additions & 6 deletions src/net/sf/mpxj/primavera/PrimaveraReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -376,13 +375,11 @@ private void processCalendarExceptions(ProjectCalendar calendar, Record root)
Record exceptions = root.getChild("Exceptions");
if (exceptions != null)
{
Calendar cal = Calendar.getInstance();
for (Record exception : exceptions.getChildren())
{
int daysFromEpoch = Integer.parseInt(exception.getValue().split("\\|")[1]);
cal.setTimeInMillis(EXCEPTION_EPOCH);
cal.add(Calendar.DAY_OF_YEAR, daysFromEpoch);
Date startEx = cal.getTime();
long daysFromEpoch = Integer.parseInt(exception.getValue().split("\\|")[1]);
Date startEx = DateHelper.getDateFromLong(EXCEPTION_EPOCH + (daysFromEpoch * DateHelper.MS_PER_DAY));

ProjectCalendarException pce = calendar.addCalendarException(startEx, startEx);
for (Record exceptionHours : exception.getChildren())
{
Expand Down

0 comments on commit 034818b

Please sign in to comment.