<commit_before>package tr.xip.wanikani.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.Date;

import tr.xip.wanikani.R;

/**
 * Created by xihsa_000 on 3/15/14.
 */
public class Utils {
    Context context;

    public Utils(Context context) {
        this.context = context;
    }

    public static String getTimeDifference(Context context, Date date1, Date date2) {

        long differenceInMilliseconds = date1.getTime() - date2.getTime();
        long differenceInMinutes = differenceInMilliseconds / 60000;
        long differenceInHours = differenceInMinutes / 60;
        long differenceInDays = differenceInHours / 24;
        double differenceInMonths = differenceInDays / 30.4368;

        if (differenceInMinutes == 0) {
            return context.getString(R.string.less_than_a_minute)
                    + getAgoIfPastTime(context, differenceInMilliseconds);
        } else if (differenceInMinutes >= 60 || differenceInMinutes <= -60) {
            if (differenceInHours >= 24 || differenceInHours <= -24) {
                if ((double) differenceInDays >= 30.4368 || (double) differenceInDays <= -30.4368) {
                    if (differenceInMonths == 1 || differenceInMonths == -1)
                        return context.getString(R.string.a_month)
                                + getAgoIfPastTime(context, differenceInMonths);
                    else
                        return (long) removeMinusFromLong(differenceInMonths) + " "
                                + context.getString(R.string.months)
                                + getAgoIfPastTime(context, differenceInMonths);
                } else {
                    if (differenceInDays == 1 || differenceInDays == -1)
                        return context.getString(R.string.a_day)
                                + getAgoIfPastTime(context, differenceInDays);
                    else
                        return (long) removeMinusFromLong(differenceInDays) + " "
                                + context.getString(R.string.days)
                                + getAgoIfPastTime(context, differenceInDays);
                }
            } else {
                if (differenceInHours == 1 || differenceInHours == -1)
                    return context.getString(R.string.an_hour)
                            + getAgoIfPastTime(context, differenceInDays);
                else<commit_msg>Improve time difference calculation<commit_after>package tr.xip.wanikani.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.Date;

import tr.xip.wanikani.R;

/**
 * Created by xihsa_000 on 3/15/14.
 */
public class Utils {
    Context context;

    public Utils(Context context) {
        this.context = context;
    }

    public static String getTimeDifference(Context context, Date date1, Date date2) {

        long differenceInMilliseconds = date1.getTime() - date2.getTime();
        long differenceInMinutes = differenceInMilliseconds / 60000;
        long differenceInHours = differenceInMinutes / 60;
        long differenceInDays = differenceInHours / 24;
        double differenceInMonths = differenceInDays / 30.4368;

        if (differenceInMinutes == 0) {
            return context.getString(R.string.less_than_a_minute)
                    + getAgoIfPastTime(context, differenceInMilliseconds);
        } else if (differenceInMinutes >= 60 || differenceInMinutes <= -60) {
            if (differenceInHours >= 24 || differenceInHours <= -24) {
                if (differenceInDays >= 30 || differenceInDays <= -30) {
                    if ((differenceInDays >= 30 && differenceInDays < 46)
                            || (differenceInDays <= -30 && differenceInDays > -46))
                        return "~ " + context.getString(R.string.a_month)
                                + getAgoIfPastTime(context, differenceInMonths);
                    else
                        return Math.round(removeMinusFromLong(differenceInMonths)) + " "
                                + context.getString(R.string.months)
                                + getAgoIfPastTime(context, differenceInMonths);
                } else {
                    if (differenceInDays == 1 || differenceInDays == -1)
                        return context.getString(R.string.a_day)
                                + getAgoIfPastTime(context, differenceInDays);
                    else
                        return (long) removeMinusFromLong(differenceInDays) + " "
                                + context.getString(R.string.days)
                                + getAgoIfPastTime(context, differenceInDays);
                }
            } else {
                if (differenceInHours == 1 || differenceInHours == -1)
                    return context.getString(R.string.an_hour)
                            + getAgoIfPastTime(context, differenceInDays);
                else
{'fraction_non_alphanumeric': 0.0888623231719466, 'fraction_numerical': 0.021119744969117355, 'mean_word_length': 1.785793562708102, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2880736', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1261, 'n_words': 253}