deno.land / x / prayers@v1.6.0 / src / Formatter.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { FormatterConfig } from './types/FormatterConfig'import type { FormattedTimeObject, TimeObject } from './types/TimeObject'export class Formatter { private _formatter!: Intl.DateTimeFormat private _config!: FormatterConfig
constructor(config?: FormatterConfig) { // date formatter initialization if (config) { // TODO: pull the timezone from coordinates this._config = config const { locale, ...options } = config this._formatter = new Intl.DateTimeFormat( locale || 'en-US', options || { // timeZone, hour: 'numeric', minute: '2-digit', hour12: true, } ) } else { this._config = { locale: 'en-US', // timeZone, hour: 'numeric', minute: '2-digit', hour12: true, } const { locale, ...options } = this._config this._formatter = new Intl.DateTimeFormat(locale, options) } }
public formatDate(date: Date): string { return this._formatter.format(date) }
public formatPrayers(prayerTimes: TimeObject[]): FormattedTimeObject[] { return prayerTimes.map((v) => { return { name: v.name, time: this.formatDate(v.time), } }) }
public setFormatterOptions(newConfig: Partial<FormatterConfig>) { // TODO: pull the timezone from coordinates const { locale, ...options } = newConfig this._formatter = new Intl.DateTimeFormat( locale || 'en-US', options || { // timeZone, hour: 'numeric', minute: '2-digit', hour12: true, } ) }}
prayers

Version Info

Tagged at
7 months ago