Java Code Examples for net.sf.mpxj.TimeUnit#MINUTES

The following examples show how to use net.sf.mpxj.TimeUnit#MINUTES . 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: RecurrenceUtility.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Convert an MPXJ Duration instance into an integer duration in minutes
 * ready to be written to an MPX file.
 *
 * @param properties project properties, used for duration units conversion
 * @param duration Duration instance
 * @return integer duration in minutes
 */
public static Integer getDurationValue(ProjectProperties properties, Duration duration)
{
   Integer result;
   if (duration == null)
   {
      result = null;
   }
   else
   {
      if (duration.getUnits() != TimeUnit.MINUTES)
      {
         duration = duration.convertUnits(TimeUnit.MINUTES, properties);
      }
      result = Integer.valueOf((int) duration.getDuration());
   }
   return (result);
}
 
Example 2
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Parse work units.
 *
 * @param value work units value
 * @return TimeUnit instance
 */
public static final TimeUnit parseWorkUnits(BigInteger value)
{
   TimeUnit result = TimeUnit.HOURS;

   if (value != null)
   {
      switch (value.intValue())
      {
         case 1:
         {
            result = TimeUnit.MINUTES;
            break;
         }

         case 3:
         {
            result = TimeUnit.DAYS;
            break;
         }

         case 4:
         {
            result = TimeUnit.WEEKS;
            break;
         }

         case 5:
         {
            result = TimeUnit.MONTHS;
            break;
         }

         case 7:
         {
            result = TimeUnit.YEARS;
            break;
         }

         default:
         case 2:
         {
            result = TimeUnit.HOURS;
            break;
         }
      }
   }

   return (result);
}
 
Example 3
Source File: MapRow.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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 4
Source File: MPDUtility.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method converts between the duration units representation
 * used in the MPP file, and the standard MPX duration units.
 * If the supplied units are unrecognised, the units default to days.
 *
 * @param type MPP units
 * @return MPX units
 */
public static final TimeUnit getDurationTimeUnits(int type)
{
   TimeUnit units;

   switch (type & DURATION_UNITS_MASK)
   {
      case 3:
      {
         units = TimeUnit.MINUTES;
         break;
      }

      case 4:
      {
         units = TimeUnit.ELAPSED_MINUTES;
         break;
      }

      case 5:
      {
         units = TimeUnit.HOURS;
         break;
      }

      case 6:
      {
         units = TimeUnit.ELAPSED_HOURS;
         break;
      }

      case 8:
      {
         units = TimeUnit.ELAPSED_DAYS;
         break;
      }

      case 9:
      {
         units = TimeUnit.WEEKS;
         break;
      }

      case 10:
      {
         units = TimeUnit.ELAPSED_WEEKS;
         break;
      }

      case 11:
      {
         units = TimeUnit.MONTHS;
         break;
      }

      case 12:
      {
         units = TimeUnit.ELAPSED_MONTHS;
         break;
      }

      default:
      case 7:
      {
         units = TimeUnit.DAYS;
         break;
      }
   }

   return (units);
}