|
1 | 1 | import Helper from '@ember/component/helper'; |
2 | 2 | import moment from 'moment'; |
3 | 3 |
|
| 4 | +const dateFormats = { |
| 5 | + 'date-time-long' : 'dddd, D MMMM, YYYY h:mm A', |
| 6 | + 'date-time-tz-long' : 'dddd, D MMMM, YYYY h:mm A (z)', |
| 7 | + 'date-time-short' : 'D MMM, YYYY h:mm A', |
| 8 | + 'date-time-tz-short' : 'D MMM, YYYY h:mm A (z)', |
| 9 | + 'date-short' : 'D MMM, YYYY', |
| 10 | + 'time-tz-short' : 'h:mm A (z)' |
| 11 | +}; |
| 12 | + |
4 | 13 | const locales12Hours = new Set(['en', 'bn', 'hi', 'id', 'ja', 'run', 'th', 'vi', 'ko']); |
5 | 14 |
|
6 | 15 | export function generalDate(params, { tz }) { |
7 | 16 | const timezone = tz || moment.tz.guess(); |
8 | 17 |
|
9 | 18 | const local = moment(params[0]).tz(timezone).locale(); |
10 | 19 |
|
11 | | - let format = params[1] || 'h:mm A, MMMM Do YYYY (z)'; |
| 20 | + let format = (dateFormats[params[1]] || params[1]) || 'h:mm A, MMMM Do YYYY (z)'; |
12 | 21 |
|
13 | 22 | if (!locales12Hours.has(local)) { |
14 | | - format = format.replaceAll('h', 'H'); |
| 23 | + format = format.replace(/h/g, 'H'); |
15 | 24 | format = format.replace(' A', ''); |
16 | 25 | format = format.replace(' a', ''); |
17 | 26 | } |
|
0 commit comments