From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 24 Apr 2024 07:22:08 +0000 (-0700)
Subject: Fix: include number placeholder in relative date strings
X-Git-Tag: v2.8.0~3^2~19
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=342e6d4679d475b816b5fe681c1ede157454c0e5;p=thirdparty%2Fpaperless-ngx.git
Fix: include number placeholder in relative date strings
---
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf
index eaa2d7bfef..1349054855 100644
--- a/src-ui/messages.xlf
+++ b/src-ui/messages.xlf
@@ -7388,95 +7388,95 @@
36
-
- Just now
+
+ %s year ago
src/app/pipes/custom-date.pipe.ts
- 39
+ 14
-
- year ago
+
+ %s years ago
src/app/pipes/custom-date.pipe.ts
- 42
+ 15
-
- years ago
+
+ %s month ago
src/app/pipes/custom-date.pipe.ts
- 43
+ 19
-
- month ago
+
+ %s months ago
src/app/pipes/custom-date.pipe.ts
- 47
+ 20
-
- months ago
+
+ %s week ago
src/app/pipes/custom-date.pipe.ts
- 48
+ 24
-
- week ago
+
+ %s weeks ago
src/app/pipes/custom-date.pipe.ts
- 52
+ 25
-
- weeks ago
+
+ %s day ago
src/app/pipes/custom-date.pipe.ts
- 53
+ 29
-
- day ago
+
+ %s days ago
src/app/pipes/custom-date.pipe.ts
- 57
+ 30
-
- days ago
+
+ %s hour ago
src/app/pipes/custom-date.pipe.ts
- 58
+ 34
-
- hour ago
+
+ %s hours ago
src/app/pipes/custom-date.pipe.ts
- 62
+ 35
-
- hours ago
+
+ %s minute ago
src/app/pipes/custom-date.pipe.ts
- 63
+ 39
-
- minute ago
+
+ %s minutes ago
src/app/pipes/custom-date.pipe.ts
- 67
+ 40
-
- minutes ago
+
+ Just now
src/app/pipes/custom-date.pipe.ts
- 68
+ 72
diff --git a/src-ui/src/app/pipes/custom-date.pipe.spec.ts b/src-ui/src/app/pipes/custom-date.pipe.spec.ts
index 87e99212b0..ddc03c773e 100644
--- a/src-ui/src/app/pipes/custom-date.pipe.spec.ts
+++ b/src-ui/src/app/pipes/custom-date.pipe.spec.ts
@@ -1,10 +1,7 @@
import { TestBed } from '@angular/core/testing'
import { CustomDatePipe } from './custom-date.pipe'
import { SettingsService } from '../services/settings.service'
-import {
- HttpClientTestingModule,
- HttpTestingController,
-} from '@angular/common/http/testing'
+import { HttpClientTestingModule } from '@angular/common/http/testing'
import { DatePipe } from '@angular/common'
describe('CustomDatePipe', () => {
diff --git a/src-ui/src/app/pipes/custom-date.pipe.ts b/src-ui/src/app/pipes/custom-date.pipe.ts
index e6034c59bc..a7a31a2ed8 100644
--- a/src-ui/src/app/pipes/custom-date.pipe.ts
+++ b/src-ui/src/app/pipes/custom-date.pipe.ts
@@ -9,6 +9,39 @@ const FORMAT_TO_ISO_FORMAT = {
shortDate: 'y-MM-dd',
}
+const INTERVALS = {
+ year: {
+ label: $localize`%s year ago`,
+ labelPlural: $localize`%s years ago`,
+ interval: 31536000,
+ },
+ month: {
+ label: $localize`%s month ago`,
+ labelPlural: $localize`%s months ago`,
+ interval: 2592000,
+ },
+ week: {
+ label: $localize`%s week ago`,
+ labelPlural: $localize`%s weeks ago`,
+ interval: 604800,
+ },
+ day: {
+ label: $localize`%s day ago`,
+ labelPlural: $localize`%s days ago`,
+ interval: 86400,
+ },
+ hour: {
+ label: $localize`%s hour ago`,
+ labelPlural: $localize`%s hours ago`,
+ interval: 3600,
+ },
+ minute: {
+ label: $localize`%s minute ago`,
+ labelPlural: $localize`%s minutes ago`,
+ interval: 60,
+ },
+}
+
@Pipe({
name: 'customDate',
})
@@ -37,45 +70,13 @@ export class CustomDatePipe implements PipeTransform {
if (format === 'relative') {
const seconds = Math.floor((+new Date() - +new Date(value)) / 1000)
if (seconds < 60) return $localize`Just now`
- const intervals = {
- year: {
- label: $localize`year ago`,
- labelPlural: $localize`years ago`,
- interval: 31536000,
- },
- month: {
- label: $localize`month ago`,
- labelPlural: $localize`months ago`,
- interval: 2592000,
- },
- week: {
- label: $localize`week ago`,
- labelPlural: $localize`weeks ago`,
- interval: 604800,
- },
- day: {
- label: $localize`day ago`,
- labelPlural: $localize`days ago`,
- interval: 86400,
- },
- hour: {
- label: $localize`hour ago`,
- labelPlural: $localize`hours ago`,
- interval: 3600,
- },
- minute: {
- label: $localize`minute ago`,
- labelPlural: $localize`minutes ago`,
- interval: 60,
- },
- }
let counter
- for (const i in intervals) {
- counter = Math.floor(seconds / intervals[i].interval)
+ for (const i in INTERVALS) {
+ counter = Math.floor(seconds / INTERVALS[i].interval)
if (counter > 0) {
const label =
- counter > 1 ? intervals[i].labelPlural : intervals[i].label
- return `${counter} ${label}`
+ counter > 1 ? INTERVALS[i].labelPlural : INTERVALS[i].label
+ return label.replace('%s', counter.toString())
}
}
}