aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/misc
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/misc')
-rw-r--r--client/src/app/shared/misc/from-now.pipe.ts40
-rw-r--r--client/src/app/shared/misc/number-formatter.pipe.ts19
-rw-r--r--client/src/app/shared/misc/object-length.pipe.ts8
3 files changed, 0 insertions, 67 deletions
diff --git a/client/src/app/shared/misc/from-now.pipe.ts b/client/src/app/shared/misc/from-now.pipe.ts
deleted file mode 100644
index 3a9a76411..000000000
--- a/client/src/app/shared/misc/from-now.pipe.ts
+++ /dev/null
@@ -1,40 +0,0 @@
1import { Pipe, PipeTransform } from '@angular/core'
2import { I18n } from '@ngx-translate/i18n-polyfill'
3
4// Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site
5@Pipe({ name: 'myFromNow' })
6export class FromNowPipe implements PipeTransform {
7
8 constructor (private i18n: I18n) { }
9
10 transform (arg: number | Date | string) {
11 const argDate = new Date(arg)
12 const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000)
13
14 let interval = Math.floor(seconds / 31536000)
15 if (interval > 1) {
16 return this.i18n('{{interval}} years ago', { interval })
17 }
18
19 interval = Math.floor(seconds / 2592000)
20 if (interval > 1) return this.i18n('{{interval}} months ago', { interval })
21 if (interval === 1) return this.i18n('{{interval}} month ago', { interval })
22
23 interval = Math.floor(seconds / 604800)
24 if (interval > 1) return this.i18n('{{interval}} weeks ago', { interval })
25 if (interval === 1) return this.i18n('{{interval}} week ago', { interval })
26
27 interval = Math.floor(seconds / 86400)
28 if (interval > 1) return this.i18n('{{interval}} days ago', { interval })
29 if (interval === 1) return this.i18n('{{interval}} day ago', { interval })
30
31 interval = Math.floor(seconds / 3600)
32 if (interval > 1) return this.i18n('{{interval}} hours ago', { interval })
33 if (interval === 1) return this.i18n('{{interval}} hour ago', { interval })
34
35 interval = Math.floor(seconds / 60)
36 if (interval >= 1) return this.i18n('{{interval}} min ago', { interval })
37
38 return this.i18n('{{interval}} sec ago', { interval: Math.max(0, seconds) })
39 }
40}
diff --git a/client/src/app/shared/misc/number-formatter.pipe.ts b/client/src/app/shared/misc/number-formatter.pipe.ts
deleted file mode 100644
index 8a0756a36..000000000
--- a/client/src/app/shared/misc/number-formatter.pipe.ts
+++ /dev/null
@@ -1,19 +0,0 @@
1import { Pipe, PipeTransform } from '@angular/core'
2
3// Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
4
5@Pipe({ name: 'myNumberFormatter' })
6export class NumberFormatterPipe implements PipeTransform {
7 private dictionary: Array<{max: number, type: string}> = [
8 { max: 1000, type: '' },
9 { max: 1000000, type: 'K' },
10 { max: 1000000000, type: 'M' }
11 ]
12
13 transform (value: number) {
14 const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1]
15 const calc = Math.floor(value / (format.max / 1000))
16
17 return `${calc}${format.type}`
18 }
19}
diff --git a/client/src/app/shared/misc/object-length.pipe.ts b/client/src/app/shared/misc/object-length.pipe.ts
deleted file mode 100644
index 84d182052..000000000
--- a/client/src/app/shared/misc/object-length.pipe.ts
+++ /dev/null
@@ -1,8 +0,0 @@
1import { Pipe, PipeTransform } from '@angular/core'
2
3@Pipe({ name: 'myObjectLength' })
4export class ObjectLengthPipe implements PipeTransform {
5 transform (value: Object) {
6 return Object.keys(value).length
7 }
8}