<commit_before>import Vue from 'vue';

import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import format from 'date-fns/format'
import isSameDay from 'date-fns/is_same_day'
import getTime from 'date-fns/get_time'

let locale = null;
let localeName = 'en';

const getOptions = function () {
    let options = {};
    if (locale) {
        options.locale = locale;
    }
    return options;
};

const getFormatDate = function (value) {
    if (value) {
        if (localeName === 'de') {
            return format(value * 1000, 'D. MMM YYYY', getOptions())
        } else if (localeName === 'en') {
            return format(value * 1000, 'MMM D, YYYY', getOptions())
        }
    }
};

const getFormatDateShort = function (value) {
    if (value) {
        let valueToConvert = value;
        if (typeof valueToConvert === 'string') {
            valueToConvert = getTime(value) / 1000;
        }
        if (localeName === 'de') {
            return format(valueToConvert * 1000, 'DD.MM.YYYY', getOptions())
        } else if (localeName === 'en') {
            return format(valueToConvert * 1000, 'MM/DD/YYYY', getOptions())
        }
    }
};

Vue.filter('formatRelativeTimesAgo', function (value) {
    if (value) {
        return distanceInWordsToNow(value * 1000, getOptions());
    }
});

Vue.filter('formatDateOnly', function (value) {
    return getFormatDate(value);
});

Vue.filter('getFormatDateOnlyShort', function (value) {
    return getFormatDateShort(value);
});


Vue.filter('formatFromToDate', function (startDate, endDate, atTranslation) {
    if (isSameDay(startDate * 1000, endDate * 1000)) {
        return `${getFormatDate(startDate)} ${atTranslation} 
                ${format(startDate * 1000, 'h:mm', getOptions())} - ${format(endDate * 1000, 'h:mm', getOptions())}`
    }
    return `${getFormatDate(startDate)} ${atTranslation} ${format(startDate * 1000, 'h:mm', getOptions())} 
              - ${getFormatDate(endDate)} ${atTranslation} ${format(startDate * 1000, 'h:mm', getOptions())} `
});

export default ({store}) => {
    if (store.state.i18n.language === 'de') {
        locale = require('date-fns/locale/de');
        localeName = 'de';<commit_msg>Bugfix: Wrong time.<commit_after>import Vue from 'vue';

import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import format from 'date-fns/format'
import isSameDay from 'date-fns/is_same_day'
import getTime from 'date-fns/get_time'

let locale = null;
let localeName = 'en';

const getOptions = function () {
    let options = {};
    if (locale) {
        options.locale = locale;
    }
    return options;
};

const getFormatDate = function (value) {
    if (value) {
        if (localeName === 'de') {
            return format(value * 1000, 'D. MMM YYYY', getOptions())
        } else if (localeName === 'en') {
            return format(value * 1000, 'MMM D, YYYY', getOptions())
        }
    }
};

const getFormatDateShort = function (value) {
    if (value) {
        let valueToConvert = value;
        if (typeof valueToConvert === 'string') {
            valueToConvert = getTime(value) / 1000;
        }
        if (localeName === 'de') {
            return format(valueToConvert * 1000, 'DD.MM.YYYY', getOptions())
        } else if (localeName === 'en') {
            return format(valueToConvert * 1000, 'MM/DD/YYYY', getOptions())
        }
    }
};

Vue.filter('formatRelativeTimesAgo', function (value) {
    if (value) {
        return distanceInWordsToNow(value * 1000, getOptions());
    }
});

Vue.filter('formatDateOnly', function (value) {
    return getFormatDate(value);
});

Vue.filter('getFormatDateOnlyShort', function (value) {
    return getFormatDateShort(value);
});


Vue.filter('formatFromToDate', function (startDate, endDate, atTranslation) {
    if (isSameDay(startDate * 1000, endDate * 1000)) {
        return `${getFormatDate(startDate)} ${atTranslation} 
                ${format(startDate * 1000, 'H:mm', getOptions())} - ${format(endDate * 1000, 'H:mm', getOptions())}`
    }
    return `${getFormatDate(startDate)} ${atTranslation} ${format(startDate * 1000, 'H:mm', getOptions())} 
              - ${getFormatDate(endDate)} ${atTranslation} ${format(startDate * 1000, 'H:mm', getOptions())} `
});

export default ({store}) => {
    if (store.state.i18n.language === 'de') {
        locale = require('date-fns/locale/de');
        localeName = 'de';
{'fraction_non_alphanumeric': 0.15715579710144928, 'fraction_numerical': 0.022644927536231884, 'mean_word_length': 3.1050185873605947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3682769', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1382, 'n_words': 321}