-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
moment-format.js
39 lines (30 loc) · 1.06 KB
/
moment-format.js
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
import { isEmpty } from '@ember/utils';
import { get, observer } from '@ember/object';
import computeFn from '../utils/helper-compute';
import BaseHelper from './-base';
export default BaseHelper.extend({
defaultFormatDidChange: observer('moment.defaultFormat', function() {
this.recompute();
}),
compute: computeFn(function(params, { locale, timeZone }) {
this._super(...arguments);
const moment = get(this, 'moment');
const { length } = params;
if (length > 3) {
throw new TypeError('ember-moment: Invalid number of arguments, expected at most 3');
}
const args = [];
const formatArgs = [];
const defaultFormat = get(this, 'moment.defaultFormat');
args.push(params[0]);
if (length === 1 && !isEmpty(defaultFormat)) {
formatArgs.push(defaultFormat);
} else if (length === 2) {
formatArgs.push(params[1]);
} else if (length > 2) {
args.push(params[2]);
formatArgs.push(params[1]);
}
return this.morphMoment(moment.moment(...args), { locale, timeZone }).format(...formatArgs);
})
});