<commit_before>/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * 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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.ui.wicket.util;

import org.apache.wicket.datetime.StyleDateConverter;
import org.efaps.db.Context;
import org.efaps.util.EFapsException;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 * Singelton class for date functions.
 *
 * @author The eFaps Team
 * @version $Id$
 */
public final class DateUtil
{
    /**
     * Singelton.
     */
    private DateUtil()
    {
    }

    /**
     * Convert a date from a parameter into a <code>DateTime</code>.
     *
     * @param _value value to be converted
     * @return DateTime
     * @throws EFapsException on error
     */
    public static DateTime getDateFromParameter(final String _value)
        throws EFapsException
    {
        final StyleDateConverter styledate = new StyleDateConverter(false);
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(styledate.getDatePattern(Context.getThreadContext()
                        .getLocale()));
        fmt.withLocale(Context.getThreadContext().getLocale());
        final DateTime dt = fmt.parseDateTime(_value);
        return dt;
    }
}<commit_msg>- webapp: adding method to DateUtil <commit_after>/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * 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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.ui.wicket.util;

import org.apache.wicket.datetime.StyleDateConverter;
import org.efaps.db.Context;
import org.efaps.util.EFapsException;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 * Singelton class for date functions.
 *
 * @author The eFaps Team
 * @version $Id$
 */
public final class DateUtil
{
    /**
     * Singelton.
     */
    private DateUtil()
    {
    }

    /**
     * Convert a date from a parameter into a <code>DateTime</code>.
     *
     * @param _value value to be converted
     * @return DateTime
     * @throws EFapsException on error
     */
    public static DateTime getDateFromParameter(final String _value)
        throws EFapsException
    {
        final StyleDateConverter styledate = new StyleDateConverter(false);
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(styledate.getDatePattern(Context.getThreadContext()
                        .getLocale()));
        fmt.withLocale(Context.getThreadContext().getLocale());
        final DateTime dt = fmt.parseDateTime(_value);
        return dt;
    }

    /**
     * Convert a <code>DateTime</code> to a String for parameter.
     *
     * @param _value value to be converted
     * @return DateTime
     * @throws EFapsException on error
     */
    public static String getDate4Parameter(final DateTime _value)
        throws EFapsException
    {
        final StyleDateConverter styledate = new StyleDateConverter(false);
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(styledate.getDatePattern(Context.getThreadContext()
                        .getLocale()));
        fmt.withLocale(Context.getThreadContext().getLocale());
        return _value.toString(fmt);
    }
}
{'fraction_non_alphanumeric': 0.09204545454545454, 'fraction_numerical': 0.005681818181818182, 'mean_word_length': 3.0045495905368518, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3103161', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1182, 'n_words': 391}