<commit_before>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.util.convert.converters;

import java.text.DateFormat;
import java.util.Locale;

/**
 * Converts from Date to String.
 *
 * @author <NAME>
 */
public final class DateToStringConverter extends AbstractConverter
{
	/** The date format to use */
    private DateFormat dateFormat;
    
    /**
	 * @see wicket.util.convert.converters.AbstractConverter#setLocale(java.util.Locale)
	 */
	public void setLocale(Locale locale)
	{
		super.setLocale(locale);
        dateFormat = null;
	}
    
    /**
     * @return Returns the dateFormat.
     */
    public final DateFormat getDateFormat()
    {
        if (dateFormat == null && locale != null)
        {
            dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
            dateFormat.setLenient(true);
        }
        return dateFormat;
    }
    
    /**
     * @param dateFormat The numberFormat to set.
     */
    public final void setDateFormat(final DateFormat dateFormat)
    {
        this.dateFormat = dateFormat;
    }

	/**
	 * @see wicket.util.convert.ITypeConverter#convert(java.lang.Object)
	 */
	public Object convert(final Object value)
	{
        final DateFormat dateFormat = getDateFormat();
        if (dateFormat != null)
        {
            return dateFormat.format(value);
        }
        return value.toString();
	}
}<commit_msg>allways use a dateformat instead of toString (which is not a sensible default in 99% of webapps) default pattern is SHORT instead of MEDIUM<commit_after>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.util.convert.converters;

import java.text.DateFormat;
import java.util.Locale;

/**
 * Converts from Date to String.
 * 
 * @author <NAME>
 */
public final class DateToStringConverter extends AbstractConverter
{
	/** The date format to use */
	private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

	/**
	 * @see wicket.util.convert.converters.AbstractConverter#setLocale(java.util.Locale)
	 */
	public void setLocale(Locale locale)
	{
		super.setLocale(locale);
		dateFormat = null;
	}

	/**
	 * @return Returns the dateFormat.
	 */
	public final DateFormat getDateFormat()
	{
		if (dateFormat == null && locale != null)
		{
			dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
			dateFormat.setLenient(true);
		}
		return dateFormat;
	}

	/**
	 * @param dateFormat The numberFormat to set.
	 */
	public final void setDateFormat(final DateFormat dateFormat)
	{
		if (dateFormat == null)
		{
			throw new IllegalArgumentException("a non null date format must be provided");
		}
		this.dateFormat = dateFormat;
	}

	/**
	 * @see wicket.util.convert.ITypeConverter#convert(java.lang.Object)
	 */
	public Object convert(final Object value)
	{
		final DateFormat dateFormat = getDateFormat();
		if (dateFormat != null)
		{
			return dateFormat.format(value);
		}
		return value.toString();
	}
}
{'fraction_non_alphanumeric': 0.13004056311142925, 'fraction_numerical': 0.0023860653781913625, 'mean_word_length': 3.3987408184679957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '984353', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1147, 'n_words': 375}