<commit_before>import Helper from '@ember/component/helper';
import moment from 'moment';
import {assert} from '@ember/debug';
import {inject as service} from '@ember/service';

export default Helper.extend({
    settings: service(),

    compute([timeago], {draft, scheduled, published}) {
        assert('You must pass a time to the gh-format-post-time helper', timeago);

        if (draft) {
            // No special handling for drafts, just use moment.from
            return moment(timeago).from(moment.utc());
        }

        let timezone = this.get('settings.timezone');
        let time = moment.tz(timeago, timezone);
        let now = moment.tz(moment.utc(), timezone);

        // If not a draft and post was published <= 15 minutes ago
        // or scheduled to be published <= 15 minutes from now, use moment.from
        if (Math.abs(now.diff(time, 'minutes')) <= 15) {
            return time.from(now);
        }

        // If scheduled for or published on the same day, render the time + Today
        if (time.isSame(now, 'day')) {
            let formatted = time.format('HH:mm [Today]');
            return scheduled ? `at ${formatted}` : formatted;
        }

        // if published yesterday, render time + yesterday
        // This check comes before scheduled, because there are likely to be more published
        // posts than scheduled posts.
        if (published && time.isSame(now.clone().subtract(1, 'days').startOf('day'), 'day')) {
            return time.format('HH:mm [Yesterday]');
        }

        // if scheduled for tomorrow, render the time + Tomorrow
        if (scheduled && time.isSame(now.clone().add(1, 'days').startOf('day'), 'day')) {
            return time.format('[at] HH:mm [Tomorrow]');
        }

        // Else, render just the date if published, or the time & date if scheduled
        let format = scheduled ? '[at] HH:mm [on] DD MMM YYYY' : 'DD MMM YYYY';
        return time.format(format);
    }
});<commit_msg>Fixed gh-format-post-time not showing hours when time is <12 hours away<commit_after>import Helper from '@ember/component/helper';
import moment from 'moment';
import {assert} from '@ember/debug';
import {inject as service} from '@ember/service';

export function formatPostTime(timeago, {timezone = 'ect/UTC', draft, scheduled, published}) {
    if (draft) {
        // No special handling for drafts, just use moment.from
        return moment(timeago).from(moment.utc());
    }

    let time = moment.tz(timeago, timezone);
    let now = moment.tz(moment.utc(), timezone);

    // If not a draft and post was published <= 12 hours ago
    // or scheduled to be published <= 12 hours from now, use moment.from
    if (Math.abs(now.diff(time, 'hours')) <= 12) {
        return time.from(now);
    }

    // If scheduled for or published on the same day, render the time + Today
    if (time.isSame(now, 'day')) {
        let formatted = time.format('HH:mm [Today]');
        return scheduled ? `at ${formatted}` : formatted;
    }

    // if published yesterday, render time + yesterday
    // This check comes before scheduled, because there are likely to be more published
    // posts than scheduled posts.
    if (published && time.isSame(now.clone().subtract(1, 'days').startOf('day'), 'day')) {
        return time.format('HH:mm [Yesterday]');
    }

    // if scheduled for tomorrow, render the time + Tomorrow
    if (scheduled && time.isSame(now.clone().add(1, 'days').startOf('day'), 'day')) {
        return time.format('[at] HH:mm [Tomorrow]');
    }

    // Else, render just the date if published, or the time & date if scheduled
    let format = scheduled ? '[at] HH:mm [on] DD MMM YYYY' : 'DD MMM YYYY';
    return time.format(format);
}

export default class GhFormatPostTimeHelper extends Helper {
    @service settings;

    compute([timeago], options) {
        assert('You must pass a time to the gh-format-post-time helper', timeago);

        return formatPostTime(timeago, Object.assign({}, options, {timezone: this.settings.get('timezone')}));
    }
}
{'fraction_non_alphanumeric': 0.13550135501355012, 'fraction_numerical': 0.004434589800443459, 'mean_word_length': 2.8050609184629804, 'pattern_counts': {'":': 0, '<': 10, '<?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': '3203239', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1139, 'n_words': 398}