File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
packages/core/useTimeAgoIntl Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ export interface FormatTimeAgoIntlOptions {
3434 * If provided, it will be used instead of the default join logic.
3535 */
3636 joinParts ?: ( parts : Intl . RelativeTimeFormatPart [ ] , locale ?: Intl . UnicodeBCP47LocaleIdentifier | Intl . Locale ) => string
37+
38+ /**
39+ * Custom units
40+ */
41+ units ?: TimeAgoUnit [ ]
3742}
3843
3944export interface UseTimeAgoIntlOptions < Controls extends boolean > extends FormatTimeAgoIntlOptions {
@@ -136,7 +141,8 @@ function getTimeAgoIntlResult(
136141 const diff = + from - + now
137142 const absDiff = Math . abs ( diff )
138143
139- for ( const { name, ms } of UNITS ) {
144+ const units = options . units ?? UNITS
145+ for ( const { name, ms } of units ) {
140146 if ( absDiff >= ms ) {
141147 return {
142148 resolvedLocale,
@@ -147,7 +153,7 @@ function getTimeAgoIntlResult(
147153
148154 return {
149155 resolvedLocale,
150- parts : rtf . formatToParts ( 0 , 'second' ) ,
156+ parts : rtf . formatToParts ( 0 , units [ units . length - 1 ] . name ) ,
151157 }
152158}
153159
You can’t perform that action at this time.
0 commit comments