27 }, |
28 }, |
28 shortDateDate: Ember.computed('value', function () { |
29 shortDateDate: Ember.computed('value', function () { |
29 return this.formatDate(this.get('value')); |
30 return this.formatDate(this.get('value')); |
30 }), |
31 }), |
31 periodMatches: Ember.computed('value', function () { |
32 periodMatches: Ember.computed('value', function () { |
32 let dateStr = this.get('value'); |
33 const dateStr = this.get('value'); |
33 |
34 |
34 if (!dateStr) { |
35 return utils.getPeriodMatches(dateStr); |
35 return null; |
|
36 } |
|
37 dateStr = dateStr.trim(); |
|
38 |
|
39 const m = dateStr.match(/^(\d{4})-(\d{4})$/) || |
|
40 dateStr.match(/^start\s*=\s*([^\s]+)\s*;\s*end\s*=\s*([^\s]+)$/) || |
|
41 dateStr.match(/^end\s*=\s*([^\s]+)\s*;\s*start\s*=\s*([^\s]+)$/); |
|
42 |
|
43 if (!m) { |
|
44 return null; |
|
45 } |
|
46 |
|
47 const [, dateStr1, dateStr2] = m; |
|
48 let date1 = new Date(dateStr1); |
|
49 let date2 = new Date(dateStr2); |
|
50 |
|
51 if (isNaN(date1.getTime()) || isNaN(date2.getTime())) { |
|
52 return null; |
|
53 } |
|
54 if (date2 < date1) { |
|
55 [date1, date2] = [date2, date1]; |
|
56 } |
|
57 |
|
58 return { |
|
59 start: {str: dateStr1, date: date1}, |
|
60 end: {str: dateStr2, date: date2} |
|
61 }; |
|
62 |
|
63 }), |
36 }), |
64 isPeriod: Ember.computed('periodMatches', function () { |
37 isPeriod: Ember.computed('periodMatches', function () { |
65 const periodMatches = this.get('periodMatches'); |
38 const periodMatches = this.get('periodMatches'); |
66 |
39 |
67 return Boolean(periodMatches); |
40 return Boolean(periodMatches); |