<commit_before>package chrono

import (
	"strconv"
	"time"
)

// FormatEpochSecondString takes a string, parses to to an epoch second and formats it according to the following rules:
// A simple time HH:MM:SS is displayed if the parsed date is today.
// Day, month and time is returned if the parsed date is the current year.
// Year, day, month and time is returned in all other cases.
func FormatEpochSecondString(epoch string, ref time.Time) string {
	i, err := strconv.ParseInt(epoch, 10, 64)
	if err != nil {
		return ""
	}
	return FormatEpochSecondI64(i, ref)
}

// FormatEpochSecondI64 follows the same conventions as FormatEpochSecondString.
func FormatEpochSecondI64(epoch int64, ref time.Time) string {
	t := time.Unix(epoch, 0)
	if ref.Day() == t.Day() {
		return t.Format("15:04:05")
	}
	if ref.Year() == t.Year() {
		return t.Format("Mon Jan 2 15:04:05")
	}
	return t.Format("Mon Jan 2 15:04:05 2006")
}<commit_msg>Refactor and fix some problems in chrono.*<commit_after>package chrono

import (
	"strconv"
	"time"
)

// FormatEpochSecondString takes a string, parses to to an epoch second and formats it according to FormatCompact.
func FormatEpochSecondString(epoch string, ref time.Time) string {
	t, err := Unix(epoch)
	if err != nil {
		return ""
	}
	return FormatCompact(t, ref)
}

// Unix is equivalent to time.Unix with zero nanoseconds, where the string argument passed to this function is parsed
// as a base-10, 64-bit integer. It returns an error iff the argument could not be parsed.
func Unix(epoch string) (time.Time, error) {
	i, err := strconv.ParseInt(epoch, 10, 64)
	return time.Unix(i, 0), err
}

// FormatCompact formats a given time t to a short form, given a reference time ref. It particular:
// A simple time HH:MM:SS is displayed if t is in the same day as ref.
// Day, month and time is returned if t is in the same year as ref.
// Year, day, month and time is returned in all other cases.
func FormatCompact(t, ref time.Time) string {
	refYear, refMonth, refDay := ref.Date()
	tYear, tMonth, tDay := t.Date()
	if refYear != tYear {
		return t.Format("Mon Jan 2 15:04:05 2006")
	}
	if refMonth != tMonth || refDay != tDay {
		return t.Format("Mon Jan 2 15:04:05")
	}
	return t.Format("15:04:05")
}
{'fraction_non_alphanumeric': 0.10952168082253018, 'fraction_numerical': 0.031291908806437195, 'mean_word_length': 3.9186813186813185, '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': '2527064', 'n_tokens_mistral': 799, 'n_tokens_neox': 740, 'n_words': 296}