<commit_before>import datetime

from django.utils.translation import ungettext as _
from django.utils.timezone import utc, get_current_timezone, now


def timesince(d):
    """
    Takes a datetime object and returns the time between d and now
    as a nicely formatted string, e.g. "10 minutes".

    Adapted from django.utils.timesince.timesince.
    """
    current_timezone = get_current_timezone()
    _date = d.astimezone(current_timezone)
    _now = now()

    today = datetime.datetime(_now.year, _now.month, _now.day, tzinfo=utc)
    delta = _now - _date
    delta_midnight = today - _date
    days = delta.days
    hours = int(round(delta.seconds / 3600., 0))
    minutes = int(round(delta.seconds / 60., 0))
    chunks = (
        (365.0, lambda n: _('year', 'years', n)),
        (30.0, lambda n: _('month', 'months', n)),
        (7.0, lambda n: _('week', 'weeks', n)),
        (1.0, lambda n: _('day', 'days', n)),
    )

    if days == 0:
        if hours == 0:
            if minutes > 0:
                return _('1 minute ago',
                         '{} minutes ago'.format(minutes), minutes)
            else:
                return 'less than 1 minute ago'
        else:
            return _('1 hour ago', '{} hours ago', hours).format(hours)

    if delta_midnight.days == 0:
        return 'yesterday at {}'.format(_date.strftime('%I:%M%p'))

    count = 0

    for i, (chunk, name) in enumerate(chunks):
        if days >= chunk:
            count = round((delta_midnight.days + 1) / chunk, 0)
            break

    return '{} {} ago'.format(count, name(count))<commit_msg>Fix timesince formatting<commit_after>import datetime

from django.utils.translation import ungettext as _
from django.utils.timezone import utc, get_current_timezone, now


def timesince(d):
    """
    Takes a datetime object and returns the time between d and now
    as a nicely formatted string, e.g. "10 minutes".

    Adapted from django.utils.timesince.timesince.
    """
    current_timezone = get_current_timezone()
    _date = d.astimezone(current_timezone)
    _now = now()

    today = datetime.datetime(_now.year, _now.month, _now.day, tzinfo=utc)
    delta = _now - _date
    delta_midnight = today - _date
    days = delta.days
    hours = int(round(delta.seconds / 3600., 0))
    minutes = int(round(delta.seconds / 60., 0))
    chunks = (
        (365.0, lambda n: _('year', 'years', n)),
        (30.0, lambda n: _('month', 'months', n)),
        (7.0, lambda n: _('week', 'weeks', n)),
        (1.0, lambda n: _('day', 'days', n)),
    )

    if days == 0:
        if hours == 0:
            if minutes > 0:
                return _('1 minute ago',
                         '{} minutes ago'.format(minutes), minutes)
            else:
                return 'less than 1 minute ago'
        else:
            return _('1 hour ago', '{} hours ago', hours).format(hours)

    if delta_midnight.days == 0:
        return 'yesterday at {}'.format(_date.strftime('%I:%M%p'))

    count = 0

    for i, (chunk, name) in enumerate(chunks):
        if days >= chunk:
            count = round((delta_midnight.days + 1) / chunk, 0)
            break

    return '{} {} ago'.format(int(count), name(count))
{'fraction_non_alphanumeric': 0.138681592039801, 'fraction_numerical': 0.01927860696517413, 'mean_word_length': 2.265989847715736, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3595502', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1003, 'n_words': 297}