<commit_before>package com.sam_chordas.android.stockhawk.rest;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;

import com.sam_chordas.android.stockhawk.R;
import com.sam_chordas.android.stockhawk.service.StockTaskService;

import org.threeten.bp.Instant;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by sam_chordas on 10/8/15.
 */
public class Utils {
    public static boolean showPercent = true;

    public static String truncateBidPrice(String bidPrice) {
        bidPrice = String.format(Locale.ENGLISH, "%.2f", Float.parseFloat(bidPrice));
        return bidPrice;
    }

    public static String truncateChange(String change, boolean isPercentChange) {
        String weight = change.substring(0, 1);
        String ampersand = "";
        if (isPercentChange) {
            ampersand = change.substring(change.length() - 1, change.length());
            change = change.substring(0, change.length() - 1);
        }
        change = change.substring(1, change.length());
        double round = (double) Math.round(Double.parseDouble(change) * 100) / 100;
        change = String.format(Locale.ENGLISH, "%.2f", round);
        StringBuffer changeBuffer = new StringBuffer(change);
        changeBuffer.insert(0, weight);
        changeBuffer.append(ampersand);
        change = changeBuffer.toString();
        return change;
    }

    /**
     * Returns true if the network is available or about to become available.
     *
     * @param c Context used to get the ConnectivityManager
     * @return true if the network is available
     */
     public static boolean isNetworkAvailable(Context c) {
        ConnectivityManager cm =
                (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        return activeNetwork != null &&
                activeNetwork.isConnectedOrConnecting();
    }

    /**
     * Retrieves application status from shared preference.
     *
     * @param context Context used to get the SharedPreferences
     * @return hawk status integer type
     */
    @SuppressWarnings("ResourceType")
    static public @StockTaskService.HawkStatus
    int getHawkStatus(Context context){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getInt(context.getString(R.string.pref_hawk_status_key), StockTaskService.HAWK_STATUS_UNKNOWN);
    }

    /**
     * Resets stock hawk status to HAWK_STATUS_UNKNOWN
     *
     * @param context Context used to get the SharedPreferences
     */
    static public void resetHawkStatus(Context context){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor spe = sp.edit();
        spe.putInt(context.getString(R.string.pref_hawk_status_key), StockTaskService.HAWK_STATUS_UNKNOWN);
        spe.apply();
    }

    static public String formatGraphDateLabels(String date) {
        String currentDate = Instant.now().toString();
        SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT);
        // Removes year from formatted date
        String pattern = df.toLocalizedPattern().replaceAll(".?[Yy].?", "");
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.getDefault());
        String formattedDate;

        if (currentDate.substring(0, 9).equals(date.substring(0, 9))) {
            if (Integer.parseInt(currentDate.substring(9, 10)) == Integer.parseInt(date.substring(9, 10))
                || Integer.parseInt(currentDate.substring(9, 10)) - 1 == Integer.parseInt(date.substring(9, 10)))
            {
                df = new SimpleDateFormat("HH:mm", Locale.getDefault());
                formattedDate = df.format(new Date(Instant.parse(date).toEpochMilli()));
            } else {

                formattedDate = sdf.format(new Date(Instant.parse(date).toEpochMilli()));
            }
        } else {
            formattedDate = sdf.format(new Date(Instant.parse(date).toEpochMilli()));
        }

        return formattedDate;
    }

    /** Returns relative time since update time */
    static public String formatLastUpdateTime(Context context, String updateTime) {
        String formattedUpdateTime = context.getString(R.string.last_updated_never);
        if (updateTime.equals(context.getString(R.string.last_updated_never_key))) {
            formattedUpdateTime = DateUtils.getRelativeTimeSpanString(Instant.parse(updateTime).toEpochMilli(),
                    Instant.now().toEpochMilli(), DateUtils.MINUTE_IN_MILLIS).toString();
        }
        return formattedUpdateTime.charAt(0) == '0' ? context.getString(R.string.last_updated_minute)<commit_msg>fix: Show update time correctly<commit_after>package com.sam_chordas.android.stockhawk.rest;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;

import com.sam_chordas.android.stockhawk.R;
import com.sam_chordas.android.stockhawk.service.StockTaskService;

import org.threeten.bp.Instant;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by sam_chordas on 10/8/15.
 */
public class Utils {
    public static boolean showPercent = true;

    public static String truncateBidPrice(String bidPrice) {
        bidPrice = String.format(Locale.ENGLISH, "%.2f", Float.parseFloat(bidPrice));
        return bidPrice;
    }

    public static String truncateChange(String change, boolean isPercentChange) {
        String weight = change.substring(0, 1);
        String ampersand = "";
        if (isPercentChange) {
            ampersand = change.substring(change.length() - 1, change.length());
            change = change.substring(0, change.length() - 1);
        }
        change = change.substring(1, change.length());
        double round = (double) Math.round(Double.parseDouble(change) * 100) / 100;
        change = String.format(Locale.ENGLISH, "%.2f", round);
        StringBuffer changeBuffer = new StringBuffer(change);
        changeBuffer.insert(0, weight);
        changeBuffer.append(ampersand);
        change = changeBuffer.toString();
        return change;
    }

    /**
     * Returns true if the network is available or about to become available.
     *
     * @param c Context used to get the ConnectivityManager
     * @return true if the network is available
     */
     public static boolean isNetworkAvailable(Context c) {
        ConnectivityManager cm =
                (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        return activeNetwork != null &&
                activeNetwork.isConnectedOrConnecting();
    }

    /**
     * Retrieves application status from shared preference.
     *
     * @param context Context used to get the SharedPreferences
     * @return hawk status integer type
     */
    @SuppressWarnings("ResourceType")
    static public @StockTaskService.HawkStatus
    int getHawkStatus(Context context){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getInt(context.getString(R.string.pref_hawk_status_key), StockTaskService.HAWK_STATUS_UNKNOWN);
    }

    /**
     * Resets stock hawk status to HAWK_STATUS_UNKNOWN
     *
     * @param context Context used to get the SharedPreferences
     */
    static public void resetHawkStatus(Context context){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor spe = sp.edit();
        spe.putInt(context.getString(R.string.pref_hawk_status_key), StockTaskService.HAWK_STATUS_UNKNOWN);
        spe.apply();
    }

    static public String formatGraphDateLabels(String date) {
        String currentDate = Instant.now().toString();
        SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT);
        // Removes year from formatted date
        String pattern = df.toLocalizedPattern().replaceAll(".?[Yy].?", "");
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.getDefault());
        String formattedDate;

        if (currentDate.substring(0, 9).equals(date.substring(0, 9))) {
            if (Integer.parseInt(currentDate.substring(9, 10)) == Integer.parseInt(date.substring(9, 10))
                || Integer.parseInt(currentDate.substring(9, 10)) - 1 == Integer.parseInt(date.substring(9, 10)))
            {
                df = new SimpleDateFormat("HH:mm", Locale.getDefault());
                formattedDate = df.format(new Date(Instant.parse(date).toEpochMilli()));
            } else {

                formattedDate = sdf.format(new Date(Instant.parse(date).toEpochMilli()));
            }
        } else {
            formattedDate = sdf.format(new Date(Instant.parse(date).toEpochMilli()));
        }

        return formattedDate;
    }

    /** Returns relative time since update time */
    static public String formatLastUpdateTime(Context context, String updateTime) {
        String formattedUpdateTime = context.getString(R.string.last_updated_never);
        if (!updateTime.equals(context.getString(R.string.last_updated_never_key))) {
            formattedUpdateTime = DateUtils.getRelativeTimeSpanString(Instant.parse(updateTime).toEpochMilli(),
                    Instant.now().toEpochMilli(), DateUtils.MINUTE_IN_MILLIS).toString();
        }
        return formattedUpdateTime.charAt(0) == '0' ? context.getString(R.string.last_updated_minute)
{'fraction_non_alphanumeric': 0.10401514396732091, 'fraction_numerical': 0.007771246388363057, 'mean_word_length': 3.177278401997503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3228299', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2718, 'n_words': 579}