Parses a date restriction of 'range' type.<p>

@param dateRestriction the location of the date restriction

@return the date restriction or null if it could not be parsed
967962
private I_CmsListDateRestriction parseRange(CmsXmlContentValueLocation dateRestriction) {

        CmsXmlContentValueLocation location = dateRestriction.getSubValue(N_RANGE);
        if (location == null) {
            return null;
        }
        CmsXmlContentValueLocation fromLoc = location.getSubValue(N_FROM);
        CmsXmlContentValueLocation toLoc = location.getSubValue(N_TO);
        Date fromDate = parseDate(fromLoc);
        Date toDate = parseDate(toLoc);
        if ((fromDate != null) || (toDate != null)) {
            return new CmsListDateRangeRestriction(fromDate, toDate);
        } else {
            return null;
        }
    }
1192066
static DateFiller parseDateParameter(String wrappedParameter, String trimmedParameter) {
    if (trimmedParameter.startsWith(PARAMETER_DATE + " ")
        && trimmedParameter.length() > PARAMETER_DATE.length() + 1) {
      String dateFormat = trimmedParameter.substring(PARAMETER_DATE.length() + 1);
      return new DateFiller(wrappedParameter, trimmedParameter, dateFormat);
    } else if (trimmedParameter.equals(PARAMETER_DATE)) {
      return new DateFiller(wrappedParameter, trimmedParameter, DEFAULT_DATE_FORMAT);
    }
    return null;
  }
813248
public Date getObjectLockRetainUntilDate() {
        String dateStr = (String) metadata.get(Headers.OBJECT_LOCK_RETAIN_UNTIL_DATE);
        if (dateStr != null) {
            return DateUtils.parseISO8601Date(dateStr);
        }
        return null;
    }
627983
public static DateTime resolve(String expr)
	{
		for (WebQueryDateAnchor anchor : WebQueryDateAnchor.values())
		{
			if (StringUtils.startsWithIgnoreCase(expr, anchor.name()))
			{
				final DateTime baseDate = anchor.resolve();

				if (expr.equalsIgnoreCase(anchor.name()))
				{
					return baseDate;
				}
				else
				{
					// Consider + and -
					final String maths = expr.substring(anchor.name().length());

					final boolean plus;
					if (maths.charAt(0) == '+' || maths.charAt(0) == ' ')
					{
						plus = true;
					}
					else if (maths.charAt(0) == '-')
						plus = false;
					else
					{
						throw new IllegalArgumentException("Expected [+- ] but got char " +
						                                   maths.charAt(0) +
						                                   " while processing " +
						                                   expr);
					}

					final String period = maths.substring(1);

					final Period timePeriod = Period.parse(period);

					if (plus)
						return baseDate.plus(timePeriod);
					else
						return baseDate.minus(timePeriod);
				}
			}
		}

		// Not a special string
		return ISO_FORMAT.parseDateTime(expr);
	}
563303
private I_CmsListDateRestriction parsePastFuture(CmsXmlContentValueLocation dateRestriction) {

        CmsXmlContentValueLocation location = dateRestriction.getSubValue(N_PAST_FUTURE);
        if (location == null) {
            return null;
        }
        CmsXmlContentValueLocation directionLoc = location.getSubValue(N_DIRECTION);
        TimeDirection direction = parseDirection(directionLoc);
        return new CmsListDatePastFutureRestriction(direction);
    }
240163
public static String getFormattedDate(final Long lastQueryDate, final String datePattern) {
        return formatDate(lastQueryDate, null, datePattern);
    }
1176838
public void setRevokedEnd(Date revokedEnd) throws InvalidArgumentException {
        if (revokedEnd == null) {
            throw new InvalidArgumentException("Date can't be null");
        }
        queryParms.put("revoked_end", Util.dateToString(revokedEnd));
    }
1261766
String getFilterQuery() {

        String result = m_config.getFilterQuery();
        if (result == null) {
            result = "";
        }
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(result) && !result.startsWith("&")) {
            result = "&" + result;
        }
        if (!result.contains(CommonParams.FL + "=")) {
            result += "&" + CommonParams.FL + "=" + getDefaultReturnFields();
        }
        I_CmsListDateRestriction dateRestriction = m_config.getDateRestriction();
        if (dateRestriction != null) {
            result += "&fq="
                + CmsSearchField.FIELD_INSTANCEDATE_CURRENT_TILL
                + "_"
                + getSearchLocale().toString()
                + "_dt:"
                + dateRestriction.getRange();

        }
        return result;
    }
131847
private long getAllowedDate() {
        if (mSharedPreferences == null) {
            mSharedPreferences = mContext
                    .getSharedPreferences(PREFERENCES_GEOCODER, Context.MODE_PRIVATE);
            mAllowedDate = mSharedPreferences.getLong(KEY_ALLOW, 0);
        }
        return mAllowedDate;
    }
1344205
private static Date parse(String dateStr, DateFormat dateFormat) {
		try {
			return dateFormat.parse(dateStr);
		} catch (Exception e) {
			String pattern;
			if (dateFormat instanceof SimpleDateFormat) {
				pattern = ((SimpleDateFormat) dateFormat).toPattern();
			} else {
				pattern = dateFormat.toString();
			}
			throw new DateException(StrUtil.format("Parse [{}] with format [{}] error!", dateStr, pattern), e);
		}
	}
516584
private static Date getDateOrNull(JSONObject obj, String field)
			throws JSONException {
		String dateStr = JsonInput.getStringOrNull(obj, field);
		if (dateStr == null)
			return null;
		try {
			if (dateStr.length() >= 5 && dateStr.charAt(4) == '/') {
				return RedmineDateUtils.FULL_DATE_FORMAT.get().parse(dateStr);
			}
			if (dateStr.endsWith("Z")) {
				dateStr = dateStr.substring(0, dateStr.length() - 1)
						+ "GMT-00:00";
			} else {
				final int inset = 6;
				if (dateStr.length() <= inset)
					throw new JSONException("Bad date value " + dateStr);
				String s0 = dateStr.substring(0, dateStr.length() - inset);
				String s1 = dateStr.substring(dateStr.length() - inset,
						dateStr.length());
				dateStr = s0 + "GMT" + s1;
			}
			return RedmineDateUtils.FULL_DATE_FORMAT_V2.get().parse(dateStr);
		} catch (ParseException e) {
			throw new JSONException("Bad date value " + dateStr);
		}
	}
1064430
private Date parseDate(CmsXmlContentValueLocation dateLoc) {

        if (dateLoc == null) {
            return null;
        }
        String dateStr = dateLoc.getValue().getStringValue(m_cms);
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(dateStr)) {
            return null;
        }
        try {
            return new Date(Long.parseLong(dateStr));
        } catch (Exception e) {
            LOG.info(e.getLocalizedMessage() + " date = " + dateStr, e);
            return null;
        }
    }
910527
public Availability getEntryByDate(Date date)
   {
      Availability result = null;

      for (Availability entry : this)
      {
         DateRange range = entry.getRange();
         int comparisonResult = range.compareTo(date);
         if (comparisonResult >= 0)
         {
            if (comparisonResult == 0)
            {
               result = entry;
               break;
            }
         }
         else
         {
            break;
         }
      }

      return result;
   }
862670
public static ListConfigurationBean parseListConfiguration(CmsObject cms, CmsResource res) {

        ListConfigurationBean result = new ListConfigurationBean();
        try {
            CmsFile configFile = cms.readFile(res);
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, configFile);
            Locale locale = CmsLocaleManager.MASTER_LOCALE;

            if (!content.hasLocale(locale)) {
                locale = content.getLocales().get(0);
            }
            for (String field : PARAMETER_FIELDS) {
                String val = content.getStringValue(cms, field, locale);
                if (N_CATEGORY.equals(field)) {
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(val)) {
                        result.setCategories(Arrays.asList(val.split(",")));
                    } else {
                        result.setCategories(Collections.<String> emptyList());
                    }
                } else {
                    result.setParameterValue(field, val);
                }
            }

            I_CmsXmlContentValue restrictValue = content.getValue(N_DATE_RESTRICTION, locale);
            if (restrictValue != null) {
                CmsDateRestrictionParser parser = new CmsDateRestrictionParser(cms);
                I_CmsListDateRestriction restriction = parser.parse(new CmsXmlContentValueLocation(restrictValue));
                if (restriction == null) {
                    LOG.warn(
                        "Improper date restriction configuration in content "
                            + content.getFile().getRootPath()
                            + ", online="
                            + cms.getRequestContext().getCurrentProject().isOnlineProject());
                }
                result.setDateRestriction(restriction);
            }

            I_CmsXmlContentValue categoryModeVal = content.getValue(N_CATEGORY_MODE, locale);
            CategoryMode categoryMode = CategoryMode.OR;
            if (categoryModeVal != null) {
                try {
                    categoryMode = CategoryMode.valueOf(categoryModeVal.getStringValue(cms));
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
            result.setCategoryMode(categoryMode);

            LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
            for (I_CmsXmlContentValue parameter : content.getValues(N_PARAMETER, locale)) {
                I_CmsXmlContentValue keyVal = content.getValue(parameter.getPath() + "/" + N_KEY, locale);
                I_CmsXmlContentValue valueVal = content.getValue(parameter.getPath() + "/" + N_VALUE, locale);
                if ((keyVal != null)
                    && CmsStringUtil.isNotEmptyOrWhitespaceOnly(keyVal.getStringValue(cms))
                    && (valueVal != null)) {
                    parameters.put(keyVal.getStringValue(cms), valueVal.getStringValue(cms));
                }
            }
            result.setAdditionalParameters(parameters);
            List<String> displayTypes = new ArrayList<String>();
            List<I_CmsXmlContentValue> typeValues = content.getValues(N_DISPLAY_TYPE, locale);
            if (!typeValues.isEmpty()) {
                for (I_CmsXmlContentValue value : typeValues) {
                    displayTypes.add(value.getStringValue(cms));
                }
            }
            result.setDisplayTypes(displayTypes);
            List<String> folders = new ArrayList<String>();
            List<I_CmsXmlContentValue> folderValues = content.getValues(N_SEARCH_FOLDER, locale);
            if (!folderValues.isEmpty()) {
                for (I_CmsXmlContentValue value : folderValues) {
                    CmsLink val = ((CmsXmlVfsFileValue)value).getLink(cms);
                    if (val != null) {
                        // we are using root paths
                        folders.add(cms.getRequestContext().addSiteRoot(val.getSitePath(cms)));
                    }
                }
            }
            result.setFolders(folders);
            List<CmsUUID> blackList = new ArrayList<CmsUUID>();
            List<I_CmsXmlContentValue> blacklistValues = content.getValues(N_BLACKLIST, locale);
            if (!blacklistValues.isEmpty()) {
                for (I_CmsXmlContentValue value : blacklistValues) {
                    CmsLink link = ((CmsXmlVfsFileValue)value).getLink(cms);
                    if (link != null) {
                        blackList.add(link.getStructureId());
                    }
                }
            }
            result.setBlacklist(blackList);
        } catch (CmsException e) {
            e.printStackTrace();
        }
        return result;
    }
439487
public Date parse(String dateString)
	throws ParseException
	{
		Date result = null;
		ParseException lastException = null;
		
		for (DateFormat format : inputFormats)
		{
			try
			{
				result = ((DateFormat) format.clone()).parse(dateString);	// DateFormat is not thread safe.
				lastException = null;
				break;
			}
			catch (ParseException e)
			{
				// Keep the first exception that occurred.
				if (lastException == null)
				{
					lastException = e;
				}
				// And just try the next input format.
			}
		}

		if (lastException != null)
		{
			throw lastException;
		}

		return result;
	}
953537
public static @Nullable Date mostRecent(Date @NotNull... dates) {
    Date mostRecentDate = null;
    for (Date date : dates) {
      if (date != null && (mostRecentDate == null || date.after(mostRecentDate))) {
        mostRecentDate = date;
      }
    }
    return mostRecentDate;
  }
369084
@Override
    protected Time parseString(final DateFormat formatter, final String text) throws ParseException {
        Date date = formatter.parse(text);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(1899, 12-1, 31);

        return convertTypeValue(cal.getTime());
    }