2023-09-21 12:30:14 +02:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import { inject as service } from '@ember/service';
|
2023-10-29 19:16:33 +01:00
|
|
|
import type IntlService from 'ember-intl/services/intl';
|
|
|
|
|
|
|
|
type Positional = [date: Date | string];
|
|
|
|
|
|
|
|
export interface FormatDateRelativeHelperSignature {
|
|
|
|
Args: {
|
|
|
|
Positional: Positional;
|
|
|
|
};
|
|
|
|
}
|
2023-09-21 12:30:14 +02:00
|
|
|
|
|
|
|
export default class FormatDateRelativeHelper extends Helper {
|
2023-10-29 19:16:33 +01:00
|
|
|
@service declare intl: IntlService;
|
2023-09-21 12:30:14 +02:00
|
|
|
|
2023-10-29 19:16:33 +01:00
|
|
|
compute([date]: Positional) {
|
2023-09-21 12:30:14 +02:00
|
|
|
if (date instanceof Date) {
|
|
|
|
date = date.toISOString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return DateTime.fromISO(date).toRelative({
|
|
|
|
locale: this.intl.primaryLocale,
|
|
|
|
padding: 1000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|