Skip to content

Commit

Permalink
Merge pull request #49 from Lohoyo/master
Browse files Browse the repository at this point in the history
fix: 填上最后一个迁移 Day.js 带来的坑
  • Loading branch information
jinzhan authored Mar 24, 2021
2 parents bf9cafa + b823d48 commit a71ac74
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/calendar/docs/customHeader.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
<script>
import dayjs from 'dayjs';
import {Calendar, Grid, Radio, Select} from 'santd';
import localeData from 'dayjs/plugin/localeData';
dayjs.extend(require('dayjs/plugin/localeData'));
dayjs.extend(localeData);
export default {
components: {
Expand Down
7 changes: 5 additions & 2 deletions src/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import Select from '../select';
import Calendar from './src/fullCalendar';
import './style/index.less';
import localeReceiver from '../localeprovider/receiver';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import localeData from 'dayjs/plugin/localeData';

dayjs.extend(weekOfYear);
dayjs.extend(localeData);

dayjs.extend(require('dayjs/plugin/weekOfYear'));
dayjs.extend(require('dayjs/plugin/localeData'));
const prefixCls = classCreator('fullcalendar')();

function getMonthsLocale(value) {
Expand Down
4 changes: 3 additions & 1 deletion src/calendar/src/date/dateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import san, {DataTypes} from 'san';
import dayjs from 'dayjs';
import {formatDate} from '../util/index';
import KeyCode from '../../../core/util/keyCode';
import customParseFormat from 'dayjs/plugin/customParseFormat';

dayjs.extend(customParseFormat);

export default san.defineComponent({
dataTypes: {
Expand Down Expand Up @@ -68,7 +71,6 @@ export default san.defineComponent({
}

// 不合法直接退出
dayjs.extend(require('dayjs/plugin/customParseFormat'));
const parsed = dayjs(showDate, format, true);
if (!parsed.isValid()) {
this.data.set('invalid', true);
Expand Down
4 changes: 3 additions & 1 deletion src/calendar/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @author [email protected]
**/
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

dayjs.extend(utc);

const defaultDisabledTime = {
disabledHours() {
Expand All @@ -19,7 +22,6 @@ const defaultDisabledTime = {
export function getTodayTime(value) {
const locale = value.locale();
require(`dayjs/locale/${locale}.js`);
dayjs.extend(require('dayjs/plugin/utc'));
return dayjs().locale(locale).utcOffset(value.utcOffset());
}

Expand Down
3 changes: 2 additions & 1 deletion src/comment/docs/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
<script>
import dayjs from 'dayjs';
import {Comment, Icon, Avatar, Tooltip} from 'santd';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(require('dayjs/plugin/relativeTime'));
dayjs.extend(relativeTime);
export default {
components: {
Expand Down
4 changes: 3 additions & 1 deletion src/comment/docs/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
<script>
import dayjs from 'dayjs';
import {Comment, Avatar, List} from 'santd';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
dayjs.extend(require('dayjs/plugin/relativeTime'));
const data = [{
author: 'Han Solo',
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
Expand Down
4 changes: 3 additions & 1 deletion src/comment/docs/nested.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import san from 'san';
import dayjs from 'dayjs';
import {Comment, Icon, Avatar} from 'santd';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
dayjs.extend(require('dayjs/plugin/relativeTime'));
const pComment = san.defineComponent({
template: `
<template>
Expand Down
4 changes: 3 additions & 1 deletion src/comment/docs/reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import san from 'san';
import dayjs from 'dayjs';
import {Comment, Icon, Avatar, Form, Button, Input} from 'santd';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
dayjs.extend(require('dayjs/plugin/relativeTime'));
const pComment = san.defineComponent({
template: `
<template>
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/docs/customdisabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import dayjs from 'dayjs';
import {DatePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
function range(start, end) {
const result = [];
for (let i = start; i < end; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/docs/disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import dayjs from 'dayjs';
import {DatePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
const dateFormat = 'YYYY-MM-DD';
export default {
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/docs/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import dayjs from 'dayjs';
import {DatePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
const dateFormat = 'YYYY/MM/DD';
const monthFormat = 'YYYY/MM';
const dateFormatList = ['DD/MM/YYYY', 'DD/MM/YY'];
Expand Down
6 changes: 4 additions & 2 deletions src/date-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import createPicker from './CreatePicker';
import wrapPicker from './wrapPicker';
import WeekPicker from './WeekPicker';
import dayjs from 'dayjs';
import weekYear from 'dayjs/plugin/weekYear';
import advancedFormat from 'dayjs/plugin/advancedFormat';

dayjs.extend(require('dayjs/plugin/weekYear'));
dayjs.extend(require('dayjs/plugin/advancedFormat'));
dayjs.extend(weekYear);
dayjs.extend(advancedFormat);

const DatePicker = wrapPicker(createPicker(Calendar), 'date');

Expand Down
4 changes: 3 additions & 1 deletion src/timepicker/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import san, {DataTypes} from 'san';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';

dayjs.extend(customParseFormat);

export default san.defineComponent({
dataTypes: {
Expand Down Expand Up @@ -64,7 +67,6 @@ export default san.defineComponent({
if (inputValue) {
const originalValue = this.data.get('value');
let value = this.data.get('value') || this.data.get('defaultOpenValue');
dayjs.extend(require('dayjs/plugin/customParseFormat'));
const parsed = dayjs(inputValue, format, true);
if (!parsed.isValid()) {
this.data.set('invalid', true);
Expand Down
1 change: 1 addition & 0 deletions src/timepicker/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function toNearestValidTime(time, hourOptions, minuteOptions, secondOptions) {
const second = secondOptions
.slice()
.sort((a, b) => Math.abs(time.second() - a) - Math.abs(time.second() - b))[0];
dayjs.extend(require('dayjs/plugin/customParseFormat'));
return dayjs(`${hour}:${minute}:${second}`, 'HH:mm:ss');
}

Expand Down
2 changes: 2 additions & 0 deletions src/timepicker/docs/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import dayjs from 'dayjs';
import {TimePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
export default {
components: {
's-timepicker': TimePicker
Expand Down
2 changes: 2 additions & 0 deletions src/timepicker/docs/disable.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import dayjs from 'dayjs';
import {TimePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
export default {
components: {
's-timepicker': TimePicker
Expand Down
3 changes: 3 additions & 0 deletions src/timepicker/docs/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ TimePicker 浮层中的列会随着 `format` 变化,当略去 `format` 中的
<script>
import dayjs from 'dayjs';
import {TimePicker} from 'santd';
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs.extend(customParseFormat);
export default {
components: {
Expand Down
2 changes: 2 additions & 0 deletions src/timepicker/docs/size.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import dayjs from 'dayjs';
import {TimePicker} from 'santd';
dayjs.extend(require('dayjs/plugin/customParseFormat'));
export default {
components: {
's-timepicker': TimePicker
Expand Down

0 comments on commit a71ac74

Please sign in to comment.