Java Code Examples for net.sf.mpxj.Duration#getInstance()
The following examples show how to use
net.sf.mpxj.Duration#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlannerReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts the string representation of a Planner duration into * an MPXJ Duration instance. * * Planner represents durations as a number of seconds in its * file format, however it displays durations as days and hours, * and seems to assume that a working day is 8 hours. * * @param value string representation of a duration * @return Duration instance */ private Duration getDuration(String value) { Duration result = null; if (value != null && value.length() != 0) { double seconds = getLong(value); double hours = seconds / (60 * 60); double days = hours / 8; if (days < 1) { result = Duration.getInstance(hours, TimeUnit.HOURS); } else { double durationDays = hours / 8; result = Duration.getInstance(durationDays, TimeUnit.DAYS); } } return (result); }
Example 2
Source File: DatatypeConverter.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Parse duration represented as an arbitrary fraction of minutes. * * @param properties project properties * @param value duration value * @param targetTimeUnit required output time units * @param factor required fraction of a minute * @return Duration instance */ private static final Duration parseDurationInFractionsOfMinutes(ProjectProperties properties, Number value, TimeUnit targetTimeUnit, int factor) { Duration result = null; if (value != null) { result = Duration.getInstance(value.intValue() / factor, TimeUnit.MINUTES); if (targetTimeUnit != result.getUnits()) { result = result.convertUnits(targetTimeUnit, properties); } } return (result); }
Example 3
Source File: MPPAbstractTimephasedWorkNormaliser.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Retrieves the pro-rata work carried out on a given day. * * @param calendar current calendar * @param assignment current assignment. * @return assignment work duration */ private Duration getAssignmentWork(ProjectCalendar calendar, TimephasedWork assignment) { Date assignmentStart = assignment.getStart(); Date splitStart = assignmentStart; Date splitFinishTime = calendar.getFinishTime(splitStart); Date splitFinish = DateHelper.setTime(splitStart, splitFinishTime); Duration calendarSplitWork = calendar.getWork(splitStart, splitFinish, TimeUnit.MINUTES); Duration assignmentWorkPerDay = assignment.getAmountPerDay(); Duration splitWork; double splitMinutes = assignmentWorkPerDay.getDuration(); splitMinutes *= calendarSplitWork.getDuration(); splitMinutes /= (8 * 60); // this appears to be a fixed value splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES); return splitWork; }
Example 4
Source File: DatatypeConverter.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Convert the Phoenix representation of a duration into a Duration instance. * * @param value Phoenix duration * @return Duration instance */ public static final Duration parseDuration(String value) { Duration result = null; if (value != null) { int split = value.indexOf(' '); if (split != -1) { double durationValue = Double.parseDouble(value.substring(0, split)); TimeUnit durationUnits = parseTimeUnits(value.substring(split + 1)); result = Duration.getInstance(durationValue, durationUnits); } } return result; }
Example 5
Source File: AbstractTimephasedWorkNormaliser.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Converts assignment duration values from minutes to hours. * * @param list assignment data */ protected void convertToHours(List<TimephasedWork> list) { for (TimephasedWork assignment : list) { Duration totalWork = assignment.getTotalAmount(); Duration workPerDay = assignment.getAmountPerDay(); totalWork = Duration.getInstance(totalWork.getDuration() / 60, TimeUnit.HOURS); workPerDay = Duration.getInstance(workPerDay.getDuration() / 60, TimeUnit.HOURS); assignment.setTotalAmount(totalWork); assignment.setAmountPerDay(workPerDay); } }
Example 6
Source File: SageReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Parse a duration value from a record. * * @param columns record * @param index field index * @return duration value */ private Duration parseDuration(String[] columns, int index) { Duration result = null; String duration = getText(columns, index); if (duration != null && !duration.isEmpty()) { result = Duration.getInstance(Integer.parseInt(duration), TimeUnit.DAYS); } return result; }
Example 7
Source File: GanttProjectReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read the relationships for an individual GanttProject task. * * @param gpTask GanttProject task */ private void readRelationships(net.sf.mpxj.ganttproject.schema.Task gpTask) { for (Depend depend : gpTask.getDepend()) { Task task1 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(gpTask.getId()) + 1)); Task task2 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(depend.getId()) + 1)); if (task1 != null && task2 != null) { Duration lag = Duration.getInstance(NumberHelper.getInt(depend.getDifference()), TimeUnit.DAYS); Relation relation = task2.addPredecessor(task1, getRelationType(depend.getType()), lag); m_eventManager.fireRelationReadEvent(relation); } } }
Example 8
Source File: SqliteResultSetRow.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public Duration getDuration(String name) { String value = getString(name); if (value == null || value.isEmpty()) { throw new IllegalArgumentException("Unexpected duration value"); } String[] items = value.split(","); if (items.length != 3) { throw new IllegalArgumentException("Unexpected duration value: " + value); } String item = DatatypeConverter.parseString(items[2]); Number durationValue; try { durationValue = DatatypeConverter.parseDouble(item); } catch (ParseException ex) { throw new IllegalArgumentException("Unexpected duration value", ex); } return Duration.getInstance(NumberHelper.getDouble(durationValue), TimeUnit.HOURS); }
Example 9
Source File: ProgressRecord.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void process(Context context) { Double totalCost = getDouble(4); Double costToDate = getDouble(5); Double remainingCost = Double.valueOf(NumberHelper.getDouble(totalCost) - NumberHelper.getDouble(costToDate)); Duration totalFloat = getDuration(12); if ("-".equals(getString(11))) { totalFloat = Duration.getInstance(-totalFloat.getDuration(), TimeUnit.DAYS); } Task task = context.getTask(getString(0)); task.setActualStart(getDate(1)); task.setActualFinish(getDate(2)); task.setRemainingDuration(getDuration(3)); task.setCost(getDouble(4)); task.setRemainingCost(remainingCost); task.setCost(1, getDouble(6)); task.setEarlyStart(getDate(7)); task.setEarlyFinish(getDate(8)); task.setLateStart(getDate(9)); task.setLateFinish(getDate(10)); task.setTotalSlack(totalFloat); Date start = task.getActualStart() == null ? task.getEarlyStart() : task.getActualStart(); Date finish = task.getActualFinish() == null ? task.getEarlyFinish() : task.getActualFinish(); double percentComplete = 0; if (task.getActualFinish() == null) { Duration duration = task.getDuration(); Duration remainingDuration = task.getRemainingDuration(); if (duration != null && remainingDuration != null) { double durationValue = duration.getDuration(); double remainingDurationValue = remainingDuration.getDuration(); if (durationValue != 0 && remainingDurationValue < durationValue) { percentComplete = ((durationValue - remainingDurationValue) * 100.0) / durationValue; } } } else { percentComplete = 100.0; } task.setStart(start); task.setFinish(finish); task.setPercentageComplete(Double.valueOf(percentComplete)); }
Example 10
Source File: MPPUtility.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Reads a duration value. This method relies on the fact that * the units of the duration have been specified elsewhere. * * @param value Duration value * @param type type of units of the duration * @return Duration instance */ public static final Duration getDuration(double value, TimeUnit type) { double duration; // Value is given in 1/10 of minute switch (type) { case MINUTES: case ELAPSED_MINUTES: { duration = value / 10; break; } case HOURS: case ELAPSED_HOURS: { duration = value / 600; // 60 * 10 break; } case DAYS: { duration = value / 4800; // 8 * 60 * 10 break; } case ELAPSED_DAYS: { duration = value / 14400; // 24 * 60 * 10 break; } case WEEKS: { duration = value / 24000; // 5 * 8 * 60 * 10 break; } case ELAPSED_WEEKS: { duration = value / 100800; // 7 * 24 * 60 * 10 break; } case MONTHS: { duration = value / 96000; // break; } case ELAPSED_MONTHS: { duration = value / 432000; // 30 * 24 * 60 * 10 break; } default: { duration = value; break; } } return (Duration.getInstance(duration, type)); }
Example 11
Source File: MapRow.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public Duration getWork(String name) { return (Duration.getInstance(NumberHelper.getDouble(getDouble(name)) / 3600, TimeUnit.HOURS)); }
Example 12
Source File: MapRow.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public Duration getDuration(String name) { return (Duration.getInstance(NumberHelper.getDouble(getDouble(name)), TimeUnit.HOURS)); }
Example 13
Source File: MPPTimephasedBaselineWorkNormaliser.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * This method merges together assignment data for the same day. * * @param calendar current calendar * @param list assignment data */ @Override protected void mergeSameDay(ProjectCalendar calendar, List<TimephasedWork> list) { List<TimephasedWork> result = new ArrayList<>(); TimephasedWork previousAssignment = null; for (TimephasedWork assignment : list) { if (previousAssignment == null) { assignment.setAmountPerDay(assignment.getTotalAmount()); result.add(assignment); } else { Date previousAssignmentStart = previousAssignment.getStart(); Date previousAssignmentStartDay = DateHelper.getDayStartDate(previousAssignmentStart); Date assignmentStart = assignment.getStart(); Date assignmentStartDay = DateHelper.getDayStartDate(assignmentStart); if (previousAssignmentStartDay.getTime() == assignmentStartDay.getTime()) { result.remove(result.size() - 1); double work = previousAssignment.getTotalAmount().getDuration(); work += assignment.getTotalAmount().getDuration(); Duration totalWork = Duration.getInstance(work, TimeUnit.MINUTES); TimephasedWork merged = new TimephasedWork(); merged.setStart(previousAssignment.getStart()); merged.setFinish(assignment.getFinish()); merged.setTotalAmount(totalWork); assignment = merged; } assignment.setAmountPerDay(assignment.getTotalAmount()); result.add(assignment); } previousAssignment = assignment; } list.clear(); list.addAll(result); }
Example 14
Source File: MapRow.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Convert the string representation of a duration to a Duration instance. * * @param value string representation of a duration * @return Duration instance */ private Duration parseDuration(String value) { // // Let's assume that we always receive well-formed values. // int unitsLength = 1; char unitsChar = value.charAt(value.length() - unitsLength); // // Handle an estimated duration // if (unitsChar == '?') { unitsLength = 2; unitsChar = value.charAt(value.length() - unitsLength); } double durationValue = Double.parseDouble(value.substring(0, value.length() - unitsLength)); // // Note that we don't handle 'u' the material type here // TimeUnit durationUnits; switch (unitsChar) { case 's': { durationUnits = TimeUnit.MINUTES; durationValue /= 60; break; } case 'm': { durationUnits = TimeUnit.MINUTES; break; } case 'h': { durationUnits = TimeUnit.HOURS; break; } case 'w': { durationUnits = TimeUnit.WEEKS; break; } case 'M': { durationUnits = TimeUnit.MONTHS; break; } case 'q': { durationUnits = TimeUnit.MONTHS; durationValue *= 3; break; } case 'y': { durationUnits = TimeUnit.YEARS; break; } case 'f': { durationUnits = TimeUnit.PERCENT; break; } case 'd': default: { durationUnits = TimeUnit.DAYS; break; } } return Duration.getInstance(durationValue, durationUnits); }
Example 15
Source File: DurationColumn.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Duration read(int offset, byte[] data) { return Duration.getInstance(readShort(offset, data), TimeUnit.DAYS); }
Example 16
Source File: MPPAbstractTimephasedWorkNormaliser.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * This method breaks down spans of time into individual days. * * @param calendar current project calendar * @param list list of assignment data */ private void splitDays(ProjectCalendar calendar, List<TimephasedWork> list) { List<TimephasedWork> result = new ArrayList<>(); boolean remainderInserted = false; for (TimephasedWork assignment : list) { if (remainderInserted) { assignment.setStart(DateHelper.addDays(assignment.getStart(), 1)); remainderInserted = false; } while (assignment != null) { Date startDay = DateHelper.getDayStartDate(assignment.getStart()); Date finishDay = DateHelper.getDayStartDate(assignment.getFinish()); // special case - when the finishday time is midnight, it's really the previous day... if (assignment.getFinish().getTime() == finishDay.getTime()) { finishDay = DateHelper.addDays(finishDay, -1); } if (startDay.getTime() == finishDay.getTime()) { Duration totalWork = assignment.getTotalAmount(); Duration assignmentWork = getAssignmentWork(calendar, assignment); if ((totalWork.getDuration() - assignmentWork.getDuration()) > EQUALITY_DELTA) { assignment.setTotalAmount(assignmentWork); result.add(assignment); Duration remainingWork = Duration.getInstance(totalWork.getDuration() - assignmentWork.getDuration(), TimeUnit.MINUTES); Date remainderStart = DateHelper.addDays(finishDay, 1); Date remainderFinish = DateHelper.addDays(remainderStart, 1); TimephasedWork remainder = new TimephasedWork(); remainder.setStart(remainderStart); remainder.setFinish(remainderFinish); remainder.setTotalAmount(remainingWork); result.add(remainder); remainderInserted = true; } else { result.add(assignment); } break; } TimephasedWork[] split = splitFirstDay(calendar, assignment); if (split[0] != null) { result.add(split[0]); } if (assignment.equals(split[1])) { break; } assignment = split[1]; } } list.clear(); list.addAll(result); }
Example 17
Source File: FastTrackReader.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Process task dependencies. */ private void processDependencies() { Set<Task> tasksWithBars = new HashSet<>(); FastTrackTable table = m_data.getTable(FastTrackTableType.ACTBARS); for (MapRow row : table) { Task task = m_project.getTaskByUniqueID(row.getInteger(ActBarField._ACTIVITY)); if (task == null || tasksWithBars.contains(task)) { continue; } tasksWithBars.add(task); String predecessors = row.getString(ActBarField.PREDECESSORS); if (predecessors == null || predecessors.isEmpty()) { continue; } for (String predecessor : predecessors.split(", ")) { Matcher matcher = RELATION_REGEX.matcher(predecessor); matcher.matches(); Integer id = Integer.valueOf(matcher.group(1)); RelationType type = RELATION_TYPE_MAP.getOrDefault(matcher.group(3), RelationType.FINISH_START); String sign = matcher.group(4); double lag = NumberHelper.getDouble(matcher.group(5)); if ("-".equals(sign)) { lag = -lag; } Task targetTask = m_project.getTaskByID(id); if (targetTask != null) { Duration lagDuration = Duration.getInstance(lag, m_data.getDurationTimeUnit()); Relation relation = task.addPredecessor(targetTask, type, lagDuration); m_eventManager.fireRelationReadEvent(relation); } } } }
Example 18
Source File: DurationColumn.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Duration read(int offset, byte[] data) { return Duration.getInstance(readShort(offset, data), TimeUnit.HOURS); }
Example 19
Source File: DatatypeConverter.java From mpxj with GNU Lesser General Public License v2.1 | 2 votes |
/** * Retrieve a duration in hours from the byte array. * * @param data byte array * @param offset offset into byte array * @return duration value */ public static final Duration getDuration(byte[] data, int offset) { int durationInMinutes = getInt(data, offset, 0); return Duration.getInstance(durationInMinutes / 60, TimeUnit.HOURS); }
Example 20
Source File: MapRow.java From mpxj with GNU Lesser General Public License v2.1 | 2 votes |
/** * Retrieve a duration field. * * @param type field type * @return Duration instance */ public Duration getDuration(FastTrackField type) { Double value = (Double) getObject(type); return value == null ? null : Duration.getInstance(value.doubleValue(), m_table.getDurationTimeUnit()); }