<commit_before>package io.cloudslang.content.datetime.services;

import io.cloudslang.content.datetime.utils.Constants;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.*;

/**
 * Created by stcu on 28.04.2016.
 */
public class DateTimeService {

    /**
     * Check the current date and time, and returns a java DateAndTime formatted string of it.
     * If locale is specified, it will return the date and time string based on the locale.
     * Otherwise, default locale will be used.
     *
     * @param localeLang    The locale language for date and time string. If localeLang is 'unix' the
     *                      localeCountry input is ignored and the result will be the current UNIX
     *                      timestamp. Examples:  en, ja, unix.
     * @param localeCountry The locale country for date and time string. For example, US or JP.
     *                      If localeLang is not specified, this input will be ignored.
     * @return Current date and time.
     */
    public Map<String, String> getCurrentDateTime(String localeLang, String localeCountry) throws Exception {
        DateTimeFormatter formatter;
        DateTime datetime = DateTime.now();
        Map<String, String> returnResult = new HashMap<>();

        if (StringUtils.isNotEmpty(localeLang)) {
            if (LocaleUtils.isUnix(localeLang)) {
                long timestamp = (long)Math.floor(datetime.getMillis()/ 1000);
                addReturnValues(returnResult, "" + timestamp);

                return returnResult;
            }

            formatter = DateTimeFormat.longDateTime().withLocale(getLocaleByCountry(localeLang, localeCountry));
        } else {
            formatter = DateTimeFormat.longDateTime();
        }
        addReturnValues(returnResult, formatter.print(datetime));

        return returnResult;
    }

    /**
     * This operation converts the date input value from one date/time format (specified by dateFormat)
     * to another date/time format (specified by outFormat) using locale settings (language and country).
     * You can use the flow "Get Current Date and Time" to check upon the default date/time format from
     * the Java environement.
     *
     * @param date the date to parse/convert
     * @param dateFormat the format of the input date
     * @param dateLocaleLang the locale language for input dateFormat string. It will be ignored if
     *                       dateFormat is empty. default locale language from the Java environement
     *                       (which is dependent on the OS locale language)
     * @param dateLocaleCountry the locale country for input dateFormat string. It will be ignored
     *                          if dateFormat is empty or dateLocaleLang is empty. Default locale country
     *                          from the Java environement (which is dependent on the OS locale country)
     * @param outFormat The format of the output date/time. Default date/time format from the Java
     *                  environement (which is dependent on the OS date/time format)
     * @param outLocaleLang The locale language for output string. It will be ignored if outFormat is
     *                      empty.
     * @param outLocaleCountry The locale country for output string. It will be ignored if outFormat
     *                         is empty or outLocaleLang is empty.
     * @return The date in the new format
     */
    public Map<String, String> parseDate(String date, String dateFormat, String dateLocaleLang,
                                         String dateLocaleCountry, String outFormat, String outLocaleLang,
                                         String outLocaleCountry) throws Exception {
        DateTime inputDateTime;
        DateTimeFormatter dateFormatter, outFormatter;
        Map<String, String> returnResult = new HashMap<>();
        DateTimeZone timeZone = DateTimeZone.forID("GMT");

        if (StringUtils.isEmpty(date))
            throw new NullPointerException("Date is either Null or Empty");

        if (StringUtils.isNotEmpty(dateFormat)) {
            if (LocaleUtils.isUnix(dateFormat)) {
                inputDateTime = new DateTime(Long.parseLong(date) * 1000).withZone(timeZone);
            } else if (dateFormat.equals("S")) {
                inputDateTime = new DateTime(new Date(Long.parseLong(date))).withZone(timeZone);
            } else {
                dateFormatter = formatWithPattern(dateFormat, dateLocaleLang, dateLocaleCountry);

                if (LocaleUtils.isUnix(outFormat))
                    dateFormatter.withZone(timeZone);

                inputDateTime = dateFormatter.parseDateTime(date).withZone(timeZone);
            }
        } else {
            dateFormatter = formatWithDefault(dateLocaleLang, dateLocaleCountry);

            if (LocaleUtils.isUnix(dateFormat))
                dateFormatter.withZone(timeZone);

            inputDateTime = getJodaOrJavaDate(dateFormatter, date);
        }<commit_msg>Fixed the test that was failing.<commit_after>package io.cloudslang.content.datetime.services;

import io.cloudslang.content.datetime.utils.Constants;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.*;

/**
 * Created by stcu on 28.04.2016.
 */
public class DateTimeService {

    /**
     * Check the current date and time, and returns a java DateAndTime formatted string of it.
     * If locale is specified, it will return the date and time string based on the locale.
     * Otherwise, default locale will be used.
     *
     * @param localeLang    The locale language for date and time string. If localeLang is 'unix' the
     *                      localeCountry input is ignored and the result will be the current UNIX
     *                      timestamp. Examples:  en, ja, unix.
     * @param localeCountry The locale country for date and time string. For example, US or JP.
     *                      If localeLang is not specified, this input will be ignored.
     * @return Current date and time.
     */
    public Map<String, String> getCurrentDateTime(String localeLang, String localeCountry) throws Exception {
        DateTimeFormatter formatter;
        DateTime datetime = DateTime.now();
        Map<String, String> returnResult = new HashMap<>();

        if (StringUtils.isNotEmpty(localeLang)) {
            if (LocaleUtils.isUnix(localeLang)) {
                long timestamp = (long)Math.floor(datetime.getMillis() / 1000);
                addReturnValues(returnResult, "" + timestamp);

                return returnResult;
            }

            formatter = DateTimeFormat.longDateTime().withLocale(getLocaleByCountry(localeLang, localeCountry));
        } else {
            formatter = DateTimeFormat.longDateTime();
        }
        addReturnValues(returnResult, formatter.print(datetime));

        return returnResult;
    }

    /**
     * This operation converts the date input value from one date/time format (specified by dateFormat)
     * to another date/time format (specified by outFormat) using locale settings (language and country).
     * You can use the flow "Get Current Date and Time" to check upon the default date/time format from
     * the Java environement.
     *
     * @param date the date to parse/convert
     * @param dateFormat the format of the input date
     * @param dateLocaleLang the locale language for input dateFormat string. It will be ignored if
     *                       dateFormat is empty. default locale language from the Java environement
     *                       (which is dependent on the OS locale language)
     * @param dateLocaleCountry the locale country for input dateFormat string. It will be ignored
     *                          if dateFormat is empty or dateLocaleLang is empty. Default locale country
     *                          from the Java environement (which is dependent on the OS locale country)
     * @param outFormat The format of the output date/time. Default date/time format from the Java
     *                  environement (which is dependent on the OS date/time format)
     * @param outLocaleLang The locale language for output string. It will be ignored if outFormat is
     *                      empty.
     * @param outLocaleCountry The locale country for output string. It will be ignored if outFormat
     *                         is empty or outLocaleLang is empty.
     * @return The date in the new format
     */
    public Map<String, String> parseDate(String date, String dateFormat, String dateLocaleLang,
                                         String dateLocaleCountry, String outFormat, String outLocaleLang,
                                         String outLocaleCountry) throws Exception {
        DateTime inputDateTime;
        DateTimeFormatter dateFormatter, outFormatter;
        Map<String, String> returnResult = new HashMap<>();
        DateTimeZone timeZone = DateTimeZone.forID("GMT");

        if (StringUtils.isEmpty(date))
            throw new NullPointerException("Date is either Null or Empty");

        if (StringUtils.isNotEmpty(dateFormat)) {
            if (LocaleUtils.isUnix(dateFormat)) {
                inputDateTime = new DateTime(Long.parseLong(date) * 1000);
            } else if (dateFormat.equals("S")) {
                inputDateTime = new DateTime(new Date(Long.parseLong(date))).withZone(timeZone);
            } else {
                dateFormatter = formatWithPattern(dateFormat, dateLocaleLang, dateLocaleCountry);

                if (LocaleUtils.isUnix(outFormat))
                    dateFormatter.withZone(timeZone);

                inputDateTime = dateFormatter.parseDateTime(date).withZone(timeZone);
            }
        } else {
            dateFormatter = formatWithDefault(dateLocaleLang, dateLocaleCountry);

            if (LocaleUtils.isUnix(dateFormat))
                dateFormatter.withZone(timeZone);

            inputDateTime = getJodaOrJavaDate(dateFormatter, date);
        }
{'fraction_non_alphanumeric': 0.07166810386126282, 'fraction_numerical': 0.003257641084602855, 'mean_word_length': 2.368183284930623, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3407331', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2432, 'n_words': 887}