chore: use dayjs
parent
c0ae4a6b3a
commit
f4140b9c63
|
@ -80,7 +80,6 @@ function getWebpackConfig(modules) {
|
|||
},
|
||||
|
||||
module: {
|
||||
noParse: [/moment.js/],
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
// https://github.com/moment/moment/issues/3650
|
||||
export default function interopDefault(m) {
|
||||
return m.default || m;
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
import interopDefault from './interopDefault';
|
||||
import moment from 'moment';
|
||||
import warning from './warning';
|
||||
import isNil from 'lodash-es/isNil';
|
||||
|
||||
export const TimeType = {
|
||||
validator(value) {
|
||||
return typeof value === 'string' || isNil(value) || moment.isMoment(value);
|
||||
},
|
||||
};
|
||||
|
||||
export const TimesType = {
|
||||
validator(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return (
|
||||
value.length === 0 ||
|
||||
value.findIndex(val => typeof val !== 'string') === -1 ||
|
||||
value.findIndex(val => !isNil(val) && !moment.isMoment(val)) === -1
|
||||
);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
export const TimeOrTimesType = {
|
||||
validator(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return (
|
||||
value.length === 0 ||
|
||||
value.findIndex(val => typeof val !== 'string') === -1 ||
|
||||
value.findIndex(val => !isNil(val) && !moment.isMoment(val)) === -1
|
||||
);
|
||||
} else {
|
||||
return typeof value === 'string' || isNil(value) || moment.isMoment(value);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export function checkValidate(componentName, value, propName, valueFormat) {
|
||||
const values = Array.isArray(value) ? value : [value];
|
||||
values.forEach(val => {
|
||||
if (!val) return;
|
||||
valueFormat &&
|
||||
warning(
|
||||
interopDefault(moment)(val, valueFormat).isValid(),
|
||||
componentName,
|
||||
`When set \`valueFormat\`, \`${propName}\` should provides invalidate string time. `,
|
||||
);
|
||||
!valueFormat &&
|
||||
warning(
|
||||
interopDefault(moment).isMoment(val) && val.isValid(),
|
||||
componentName,
|
||||
`\`${propName}\` provides invalidate moment time. If you want to set empty value, use \`null\` instead.`,
|
||||
);
|
||||
});
|
||||
}
|
||||
export const stringToMoment = (value, valueFormat) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(val =>
|
||||
typeof val === 'string' && val ? interopDefault(moment)(val, valueFormat) : val || null,
|
||||
);
|
||||
} else {
|
||||
return typeof value === 'string' && value
|
||||
? interopDefault(moment)(value, valueFormat)
|
||||
: value || null;
|
||||
}
|
||||
};
|
||||
|
||||
export const momentToString = (value, valueFormat) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(val => (interopDefault(moment).isMoment(val) ? val.format(valueFormat) : val));
|
||||
} else {
|
||||
return interopDefault(moment).isMoment(value) ? value.format(valueFormat) : value;
|
||||
}
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
import glob from 'glob';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import MockDate from 'mockdate';
|
||||
import moment from 'moment';
|
||||
import dayjs from 'dayjs';
|
||||
import antd from 'ant-design-vue';
|
||||
import { sleep } from '../utils';
|
||||
|
||||
|
@ -15,7 +15,7 @@ export default function demoTest(component, options = {}) {
|
|||
testMethod = test.skip;
|
||||
}
|
||||
testMethod(`renders ${file} correctly`, async () => {
|
||||
MockDate.set(moment('2016-11-22'));
|
||||
MockDate.set(dayjs('2016-11-22'));
|
||||
const demo = require(`../.${file}`).default || require(`../.${file}`);
|
||||
document.body.innerHTML = '';
|
||||
const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body });
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import moment from 'moment';
|
||||
import dayjs from 'dayjs';
|
||||
import MockDate from 'mockdate';
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
export function setMockDate(dateString = '2017-09-18T03:30:07.795') {
|
||||
MockDate.set(moment(dateString));
|
||||
MockDate.set(dayjs(dateString));
|
||||
}
|
||||
|
||||
export function resetMockDate() {
|
||||
|
|
|
@ -2,14 +2,6 @@
|
|||
const getWebpackConfig = require('./antd-tools/getWebpackConfig');
|
||||
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin');
|
||||
const darkVars = require('./scripts/dark-vars');
|
||||
const { webpack } = getWebpackConfig;
|
||||
// noParse still leave `require('./locale' + name)` in dist files
|
||||
// ignore is better
|
||||
// http://stackoverflow.com/q/25384360
|
||||
function ignoreMomentLocale(webpackConfig) {
|
||||
delete webpackConfig.module.noParse;
|
||||
webpackConfig.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
|
||||
}
|
||||
|
||||
function addLocales(webpackConfig) {
|
||||
let packageName = 'antd-with-locales';
|
||||
|
@ -20,20 +12,19 @@ function addLocales(webpackConfig) {
|
|||
webpackConfig.output.filename = '[name].js';
|
||||
}
|
||||
|
||||
function externalMoment(config) {
|
||||
config.externals.moment = {
|
||||
root: 'moment',
|
||||
commonjs2: 'moment',
|
||||
commonjs: 'moment',
|
||||
amd: 'moment',
|
||||
function externalDayjs(config) {
|
||||
config.externals.dayjs = {
|
||||
root: 'dayjs',
|
||||
commonjs2: 'dayjs',
|
||||
commonjs: 'dayjs',
|
||||
amd: 'dayjs',
|
||||
};
|
||||
}
|
||||
|
||||
const webpackConfig = getWebpackConfig(false);
|
||||
if (process.env.RUN_ENV === 'PRODUCTION') {
|
||||
webpackConfig.forEach(config => {
|
||||
ignoreMomentLocale(config);
|
||||
externalMoment(config);
|
||||
externalDayjs(config);
|
||||
addLocales(config);
|
||||
});
|
||||
}
|
||||
|
@ -41,8 +32,7 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
|
|||
const webpackDarkConfig = getWebpackConfig(false);
|
||||
|
||||
webpackDarkConfig.forEach(config => {
|
||||
ignoreMomentLocale(config);
|
||||
externalMoment(config);
|
||||
externalDayjs(config);
|
||||
|
||||
// rename default entry to ${theme} entry
|
||||
Object.keys(config.entry).forEach(entryName => {
|
||||
|
|
Loading…
Reference in New Issue