protected DateRange parseDateRange(String[] words, int code)
			throws MalformedDateException {
		Date date1 = null;
		int flags = 0;
		
		switch (code) {
			case BEFORE:
			case AFTER:
				date1 = parsePlainDate(words, 1, 0);
				flags = (code == BEFORE) ? DateRange.BEFORE : DateRange.AFTER;
				return new DateRange(date1, flags);

			case BETWEEN:
				int andOffset = 0;
				date1 = null;
				Date date2 = null;

				for (int i = 1; i < words.length; i++) {
					if (words[i].equalsIgnoreCase("AND")) {
						andOffset = i;
						break;
					}
				}

				if (andOffset > 0) {
					date1 = parsePlainDate(words, 1, andOffset - 1);
					
					if (date1 == null)
						throw new MalformedDateException("First date in range is invalid");
					
					date2 = parsePlainDate(words, andOffset + 1, 0);
					
					if (date2 == null)
						throw new MalformedDateException("Second date in range is invalid");
					
					return new DateRange(date1, date2);
				} else
					throw new MalformedDateException("AND keyword missing");
		}
		
		return null;
	}