|
@@ -8,13 +8,30 @@ import moment from 'moment'
|
|
|
*/
|
|
|
Vue.filter('date', function(value, formatString = 'YYYY-MM-DD HH:mm:ss') {
|
|
|
if (!value) return '';
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ const iso8601Pattern = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{2}:\d{2}/;
|
|
|
+ const normalPattern = /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/;
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof value === 'string' && iso8601Pattern.test(value)) {
|
|
|
+ return moment(value).format(formatString);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof value === 'string' && normalPattern.test(value)) {
|
|
|
+ return moment(value, 'YYYY-MM-DD HH:mm:ss').format(formatString);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (typeof value === 'string') {
|
|
|
- value = Number(value)
|
|
|
+ value = Number(value);
|
|
|
}
|
|
|
-
|
|
|
- if ( typeof value === 'number' && value.toString().length === 10) {
|
|
|
- value = value * 1000
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof value === 'number' && value.toString().length === 10) {
|
|
|
+ value = value * 1000;
|
|
|
}
|
|
|
+
|
|
|
return moment(value).format(formatString);
|
|
|
-})
|
|
|
+});
|