class SPPDecoder implements MALDecoder {

	@Override
	public Duration decodeDuration() throws MALException {
		CCSDSTime tf = getDurationFormatter();
		if (tf.getTimeCode() != CCSDSTime.TimeCode.CUC) {
			throw new MALException(WRONG_TIME_FORMAT);
		}
		byte[] tField = read(tf.getDataLength());
		AbsoluteDate time = tf.getDecodedTime(tField);
		AbsoluteDate epoch = CCSDSTime.createEpoch(Configuration.DURATION_EPOCH, Configuration.DURATION_EPOCH_TIMESCALE);
		double seconds = time.durationFrom(epoch);

		// check sign bit of tField
		if ((tField[0] & 0x80) != 0) {
			// negative duration, undo 2's complement by constructing T field with every bit set
			byte[] minNegativeTimeField = new byte[tf.getDataLength()];
			for (int i = 0; i < minNegativeTimeField.length; i++) {
				minNegativeTimeField[i] = -1;
			}
			AbsoluteDate minNegativeTime = tf.getDecodedTime(minNegativeTimeField);
			double minNegativeSeconds = minNegativeTime.durationFrom(epoch);
			seconds -= minNegativeSeconds + 1;
		}

		// PENDING: Error in MAL Java API Magenta Book, Duration should contain fractional seconds,
		// but contains integer seconds. There is nothing we can do except to wait for an updated
		// book and implementation. As soon as this is available care needs to be taken to check
		// especially the fine time behaviour for negative durations.
//		return new Duration((int) seconds);
		return new Duration(seconds);
	}

	public  SPPDecoder(final InputStream inputStream, final Map properties);

}