<commit_before>package com.armandgray.taap.utils;

import com.armandgray.taap.models.SessionLog;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import static com.armandgray.taap.models.SessionLog.REST_TIME;
import static com.armandgray.taap.models.SessionLog.SESSION_LENGTH;
import static com.armandgray.taap.utils.DateTimeHelper.ONE_DAY;
import static com.armandgray.taap.utils.DateTimeHelper.ONE_HOUR;
import static com.armandgray.taap.utils.DateTimeHelper.getDateFormattedAsString;
import static com.armandgray.taap.utils.DateTimeHelper.getTimeElapsedAsDate;
import static com.armandgray.taap.utils.DateTimeHelper.getTotalTimeAsDate;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

public class DateTimeHelperTest {

    @Test
    public void canGetTimeElapsed() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        long dummyTime = System.currentTimeMillis();
        calendar.setTimeInMillis(dummyTime);
        assertNotNull(getTimeElapsedAsDate(dummyTime));
        assertEquals(calendar.getTime(), getTimeElapsedAsDate(dummyTime));
    }

    @Test
    public void canGetTimeElapsed_Telescope_NumHours() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        long dummyTime = System.currentTimeMillis();
        calendar.setTimeInMillis(dummyTime - (ONE_HOUR * 16) + ONE_DAY);
        assertNotNull(getTimeElapsedAsDate(dummyTime, 16));
        assertEquals(calendar.getTime(), getTimeElapsedAsDate(dummyTime, 16));
    }

    @Test
    public void doesZeroOutHoursForTimesLessThanOneHour_CanGetTimeElapsed() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);

        assertNotNull(getTimeElapsedAsDate(calendar.getTimeInMillis()));
        assertEquals(calendar.getTime().toString(), getTimeElapsedAsDate(calendar.getTimeInMillis()).toString());
    }

    @Test
    public void canGetTotalTimeAsDate() throws Exception {
        ArrayList<SessionLog> logs = new ArrayList<>();
        logs.add(new SessionLog.Builder().activeWork(new Date(133353535L)).create());
        logs.add(new SessionLog.Builder().activeWork(new Date(1991991291L)).create());<commit_msg>refactored code in canGetTimeElapsed_Telescope_NumHours<commit_after>package com.armandgray.taap.utils;

import com.armandgray.taap.models.SessionLog;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import static com.armandgray.taap.models.SessionLog.REST_TIME;
import static com.armandgray.taap.models.SessionLog.SESSION_LENGTH;
import static com.armandgray.taap.utils.DateTimeHelper.ONE_DAY;
import static com.armandgray.taap.utils.DateTimeHelper.ONE_HOUR;
import static com.armandgray.taap.utils.DateTimeHelper.getDateFormattedAsString;
import static com.armandgray.taap.utils.DateTimeHelper.getTimeElapsedAsDate;
import static com.armandgray.taap.utils.DateTimeHelper.getTotalTimeAsDate;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

public class DateTimeHelperTest {

    @Test
    public void canGetTimeElapsed() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        long dummyTime = System.currentTimeMillis();
        calendar.setTimeInMillis(dummyTime);
        assertNotNull(getTimeElapsedAsDate(dummyTime));
        assertEquals(calendar.getTime(), getTimeElapsedAsDate(dummyTime));
    }

    @Test
    public void canGetTimeElapsed_Telescope_NumHours() throws Exception {
        int hoursToSubtract = 16;
        long dummyTime = System.currentTimeMillis();

        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        calendar.setTimeInMillis(dummyTime - (ONE_HOUR * hoursToSubtract) + ONE_DAY);

        assertNotNull(getTimeElapsedAsDate(dummyTime, hoursToSubtract));
        assertEquals(calendar.getTime(), getTimeElapsedAsDate(dummyTime, hoursToSubtract));
    }

    @Test
    public void doesZeroOutHoursForTimesLessThanOneHour_CanGetTimeElapsed() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);

        assertNotNull(getTimeElapsedAsDate(calendar.getTimeInMillis()));
        assertEquals(calendar.getTime().toString(), getTimeElapsedAsDate(calendar.getTimeInMillis()).toString());
    }

    @Test
    public void canGetTotalTimeAsDate() throws Exception {
        ArrayList<SessionLog> logs = new ArrayList<>();
        logs.add(new SessionLog.Builder().activeWork(new Date(133353535L)).create());
        logs.add(new SessionLog.Builder().activeWork(new Date(1991991291L)).create());
{'fraction_non_alphanumeric': 0.10427110487266894, 'fraction_numerical': 0.016442751152997793, 'mean_word_length': 4.591928251121076, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2771109', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1452, 'n_words': 263}