Skip to content

Commit 9e60dc0

Browse files
refactor: replace momentJS with dayJS
1 parent d09ebc3 commit 9e60dc0

File tree

23 files changed

+137
-116
lines changed

23 files changed

+137
-116
lines changed

client/packages/lowcoder-comps/src/comps/calendarComp/calendarComp.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
viewClassNames,
5050
FormWrapper,
5151
} from "./calendarConstants";
52-
import moment from "moment";
52+
import dayjs from "dayjs";
5353

5454
const childrenMap = {
5555
events: jsonValueExposingStateControl("events", defaultData),
@@ -79,8 +79,8 @@ let CalendarBasicComp = (function () {
7979
return {
8080
title: item.title,
8181
id: item.id,
82-
start: moment(item.start, DateParser).format(),
83-
end: moment(item.end, DateParser).format(),
82+
start: dayjs(item.start, DateParser).format(),
83+
end: dayjs(item.end, DateParser).format(),
8484
allDay: item.allDay,
8585
color: isValidColor(item.color || "") ? item.color : theme?.theme?.primary,
8686
...(item.groupId ? { groupId: item.groupId } : null),
@@ -104,7 +104,7 @@ let CalendarBasicComp = (function () {
104104
const isList = eventInfo.view.type === "listWeek";
105105
let sizeClass = "";
106106
if ([ViewType.WEEK, ViewType.DAY].includes(eventInfo.view.type as ViewType)) {
107-
const duration = moment(eventInfo.event.end).diff(moment(eventInfo.event.start), "minutes");
107+
const duration = dayjs(eventInfo.event.end).diff(dayjs(eventInfo.event.start), "minutes");
108108
if (duration <= 30 || eventInfo.event.allDay) {
109109
sizeClass = "small";
110110
} else if (duration <= 60) {
@@ -114,7 +114,7 @@ let CalendarBasicComp = (function () {
114114
}
115115
}
116116
const stateClass =
117-
moment().isAfter(moment(eventInfo.event.end)) &&
117+
dayjs().isAfter(dayjs(eventInfo.event.end)) &&
118118
(eventInfo.view.type as ViewType) !== ViewType.MONTH
119119
? "past"
120120
: "";
@@ -177,7 +177,7 @@ let CalendarBasicComp = (function () {
177177
end: info.endStr,
178178
};
179179
const view = info.view.type as ViewType;
180-
const duration = moment(info.end).diff(moment(info.start), "minutes");
180+
const duration = dayjs(info.end).diff(dayjs(info.start), "minutes");
181181
const singleClick =
182182
(view === ViewType.MONTH && duration === 1440) ||
183183
([ViewType.WEEK, ViewType.DAY].includes(view) && duration === 30) ||
@@ -355,8 +355,8 @@ let CalendarBasicComp = (function () {
355355
let changeEvents: EventType[] = [];
356356
info.forEach((item) => {
357357
const event = events.find((i: EventType) => i.id === item.id);
358-
const start = moment(item.start, DateParser).format();
359-
const end = moment(item.end, DateParser).format();
358+
const start = dayjs(item.start, DateParser).format();
359+
const end = dayjs(item.end, DateParser).format();
360360
if (
361361
start !== event?.start ||
362362
end !== event?.end ||

client/packages/lowcoder-comps/src/comps/calendarComp/calendarConstants.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
UnderlineCss,
1818
} from "lowcoder-sdk";
1919
import styled from "styled-components";
20-
import moment from "moment";
20+
import dayjs from "dayjs";
2121
import {
2222
DayHeaderContentArg,
2323
FormatterInput,
@@ -813,15 +813,15 @@ export const defaultData = [
813813
{
814814
id: "1",
815815
title: "Coding",
816-
start: moment().hours(10).minutes(0).second(0).format(DATE_TIME_FORMAT),
817-
end: moment().hours(11).minutes(30).second(0).format(DATE_TIME_FORMAT),
816+
start: dayjs().hour(10).minute(0).second(0).format(DATE_TIME_FORMAT),
817+
end: dayjs().hour(11).minute(30).second(0).format(DATE_TIME_FORMAT),
818818
color: "#079968",
819819
},
820820
{
821821
id: "2",
822822
title: "Rest",
823-
start: moment().hours(24).format(DATE_FORMAT),
824-
end: moment().hours(48).format(DATE_FORMAT),
823+
start: dayjs().hour(24).format(DATE_FORMAT),
824+
end: dayjs().hour(48).format(DATE_FORMAT),
825825
allDay: true,
826826
},
827827
];
@@ -852,10 +852,10 @@ const weekHeadContent = (info: DayHeaderContentArg) => {
852852
const leftTimeContent = (info: SlotLabelContentArg) => {
853853
let isPast = false;
854854
if (info.view.type === ViewType.WEEK) {
855-
isPast = moment().isAfter(moment(moment().format("YYYY MM DD " + info.text)));
855+
isPast = dayjs().isAfter(dayjs(dayjs().format("YYYY MM DD " + info.text)));
856856
} else if (info.view.type === ViewType.DAY) {
857-
isPast = moment().isAfter(
858-
moment(moment(info.view.activeStart).format("YYYY MM DD " + info.text))
857+
isPast = dayjs().isAfter(
858+
dayjs(dayjs(info.view.activeStart).format("YYYY MM DD " + info.text))
859859
);
860860
}
861861
return {
@@ -887,9 +887,9 @@ export const slotLabelFormat = [
887887
export const viewClassNames = (info: ViewContentArg) => {
888888
let className = "";
889889
if ([ViewType.WEEK, ViewType.DAY].includes(info.view.type as ViewType)) {
890-
if (moment().isAfter(info.view.activeEnd)) {
890+
if (dayjs().isAfter(info.view.activeEnd)) {
891891
className = "past";
892-
} else if (moment().isBefore(info.view.activeStart)) {
892+
} else if (dayjs().isBefore(info.view.activeStart)) {
893893
className = "future";
894894
}
895895
}

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _, { noop } from "lodash";
2-
import moment from "moment";
2+
import dayjs from "dayjs";
33
import { RecordConstructorToComp, RecordConstructorToView } from "lowcoder-core";
44
import {
55
BoolCodeControl,
@@ -118,7 +118,7 @@ function validate(
118118
return { validateStatus: "error", help: props.customRule };
119119
}
120120

121-
const currentDateTime = moment(props.value.value, DATE_TIME_FORMAT);
121+
const currentDateTime = dayjs(props.value.value, DATE_TIME_FORMAT);
122122

123123
if (props.required && !currentDateTime.isValid()) {
124124
return { validateStatus: "error", help: trans("prop.required") };
@@ -154,7 +154,7 @@ export type DateCompViewProps = Pick<
154154
};
155155

156156
export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
157-
const time = moment(props.value.value, DateParser);
157+
const time = dayjs(props.value.value, DateParser);
158158

159159
return props.label({
160160
required: props.required,
@@ -242,8 +242,8 @@ export const dateRangeControl = (function () {
242242
};
243243

244244
return new UICompBuilder(childrenMap, (props) => {
245-
const start = moment(props.start.value, DateParser);
246-
const end = moment(props.end.value, DateParser);
245+
const start = dayjs(props.start.value, DateParser);
246+
const end = dayjs(props.end.value, DateParser);
247247

248248
const children = (
249249
<DateRangeUIView
@@ -344,7 +344,7 @@ export const DatePickerComp = withExposingConfigs(datePickerControl, [
344344
desc: trans("export.datePickerValueDesc"),
345345
depKeys: ["value", "showTime"],
346346
func: (input) => {
347-
const mom = moment(input.value, DateParser);
347+
const mom = dayjs(input.value, DateParser);
348348
return mom.isValid() ? mom.format(input.showTime ? DATE_TIME_FORMAT : DATE_FORMAT) : "";
349349
},
350350
}),
@@ -353,7 +353,7 @@ export const DatePickerComp = withExposingConfigs(datePickerControl, [
353353
desc: trans("export.datePickerFormattedValueDesc"),
354354
depKeys: ["value", "format"],
355355
func: (input) => {
356-
const mom = moment(input.value, DateParser);
356+
const mom = dayjs(input.value, DateParser);
357357
return mom.isValid() ? mom.format(input.format) : "";
358358
},
359359
}),
@@ -362,7 +362,7 @@ export const DatePickerComp = withExposingConfigs(datePickerControl, [
362362
desc: trans("export.datePickerTimestampDesc"),
363363
depKeys: ["value"],
364364
func: (input) => {
365-
const mom = moment(input.value, DateParser);
365+
const mom = dayjs(input.value, DateParser);
366366
return mom.isValid() ? mom.unix() : "";
367367
},
368368
}),
@@ -385,7 +385,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
385385
desc: trans("export.dateRangeStartDesc"),
386386
depKeys: ["start", "showTime"],
387387
func: (input) => {
388-
const mom = moment(input.start, DateParser);
388+
const mom = dayjs(input.start, DateParser);
389389
return mom.isValid() ? mom.format(input.showTime ? DATE_TIME_FORMAT : DATE_FORMAT) : "";
390390
},
391391
}),
@@ -394,7 +394,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
394394
desc: trans("export.dateRangeEndDesc"),
395395
depKeys: ["end", "showTime"],
396396
func: (input) => {
397-
const mom = moment(input.end, DateParser);
397+
const mom = dayjs(input.end, DateParser);
398398
return mom.isValid() ? mom.format(input.showTime ? DATE_TIME_FORMAT : DATE_FORMAT) : "";
399399
},
400400
}),
@@ -403,7 +403,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
403403
desc: trans("export.dateRangeStartTimestampDesc"),
404404
depKeys: ["start"],
405405
func: (input) => {
406-
const mom = moment(input.start, DateParser);
406+
const mom = dayjs(input.start, DateParser);
407407
return mom.isValid() ? mom.unix() : "";
408408
},
409409
}),
@@ -412,7 +412,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
412412
desc: trans("export.dateRangeEndTimestampDesc"),
413413
depKeys: ["end"],
414414
func: (input) => {
415-
const mom = moment(input.end, DateParser);
415+
const mom = dayjs(input.end, DateParser);
416416
return mom.isValid() ? mom.unix() : "";
417417
},
418418
}),
@@ -421,8 +421,8 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
421421
desc: trans("export.dateRangeFormattedValueDesc"),
422422
depKeys: ["start", "end", "format"],
423423
func: (input) => {
424-
const start = moment(input.start, DateParser);
425-
const end = moment(input.end, DateParser);
424+
const start = dayjs(input.start, DateParser);
425+
const end = dayjs(input.end, DateParser);
426426
return [
427427
start.isValid() && start.format(input.format),
428428
end.isValid() && end.format(input.format),
@@ -436,7 +436,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
436436
desc: trans("export.dateRangeFormattedStartValueDesc"),
437437
depKeys: ["start", "format"],
438438
func: (input) => {
439-
const start = moment(input.start, DateParser);
439+
const start = dayjs(input.start, DateParser);
440440
return start.isValid() && start.format(input.format);
441441
},
442442
}),
@@ -445,7 +445,7 @@ export let DateRangeComp = withExposingConfigs(dateRangeControl, [
445445
desc: trans("export.dateRangeFormattedEndValueDesc"),
446446
depKeys: ["end", "format"],
447447
func: (input) => {
448-
const end = moment(input.end, DateParser);
448+
const end = dayjs(input.end, DateParser);
449449
return end.isValid() && end.format(input.format);
450450
},
451451
}),

client/packages/lowcoder/src/comps/comps/dateComp/dateCompUtil.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import moment, { Moment } from "moment/moment";
1+
import dayjs from "dayjs";
22
import { DateParser, TimeParser } from "util/dateTimeUtils";
33
import { range } from "lodash";
44
import { DateTimeStyleType } from "../../controls/styleControlConstants";
@@ -16,9 +16,9 @@ export const handleDateChange = (
1616
onChange(time).then(() => onEvent("change"));
1717
};
1818

19-
export const disabledDate = (current: Moment, min: string, max: string) => {
20-
const maxDate = moment(max, DateParser);
21-
const minDate = moment(min, DateParser);
19+
export const disabledDate = (current: dayjs.Dayjs, min: string, max: string) => {
20+
const maxDate = dayjs(max, DateParser);
21+
const minDate = dayjs(min, DateParser);
2222
return (
2323
current &&
2424
current.isValid() &&
@@ -27,34 +27,34 @@ export const disabledDate = (current: Moment, min: string, max: string) => {
2727
};
2828

2929
export const disabledTime = (min: string, max: string) => {
30-
const maxTime = moment(max, TimeParser);
31-
const minTime = moment(min, TimeParser);
30+
const maxTime = dayjs(max, TimeParser);
31+
const minTime = dayjs(min, TimeParser);
3232
return {
3333
disabledHours: () => {
3434
let disabledHours: number[] = [];
3535
if (minTime.isValid()) {
36-
disabledHours = [...disabledHours, ...range(0, minTime.hours())];
36+
disabledHours = [...disabledHours, ...range(0, minTime.hour())];
3737
}
3838
if (maxTime.isValid()) {
39-
disabledHours = [...disabledHours, ...range(maxTime.hours() + 1, 24)];
39+
disabledHours = [...disabledHours, ...range(maxTime.hour() + 1, 24)];
4040
}
4141
return disabledHours;
4242
},
4343
disabledMinutes: (hour: number) => {
4444
if (minTime.isValid() && minTime.hour() === hour) {
45-
return range(0, minTime.minutes());
45+
return range(0, minTime.minute());
4646
}
4747
if (maxTime.isValid() && maxTime.hour() === hour) {
48-
return range(maxTime.minutes() + 1, 60);
48+
return range(maxTime.minute() + 1, 60);
4949
}
5050
return [];
5151
},
5252
disabledSeconds: (hour: number, minute: number) => {
5353
if (minTime.isValid() && minTime.hour() === hour && minTime.minute() === minute) {
54-
return range(0, minTime.seconds());
54+
return range(0, minTime.second());
5555
}
56-
if (maxTime.isValid() && maxTime.hours() === hour && maxTime.minute() === minute) {
57-
return range(maxTime.seconds() + 1, 60);
56+
if (maxTime.isValid() && maxTime.hour() === hour && maxTime.minute() === minute) {
57+
return range(maxTime.second() + 1, 60);
5858
}
5959
return [];
6060
},

client/packages/lowcoder/src/comps/comps/dateComp/dateMobileUIView.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from "styled-components";
22
import { DateTimeStyleType } from "comps/controls/styleControlConstants";
33
import { getMobileStyle } from "comps/comps/dateComp/dateCompUtil";
4-
import moment from "moment";
4+
import dayjs from "dayjs";
55
import { DATE_FORMAT, DATE_TIME_FORMAT, DateParser } from "util/dateTimeUtils";
66
import { CanvasContainerID } from "constants/domLocators";
77
import { trans } from "i18n";
@@ -16,14 +16,14 @@ const handleClick = async (
1616
DateCompViewProps,
1717
"showTime" | "minDate" | "maxDate" | "disabledTime" | "onFocus" | "onBlur"
1818
> & {
19-
value: moment.Moment | null;
20-
onChange: (value: moment.Moment | null) => void;
19+
value: dayjs.Dayjs | null;
20+
onChange: (value: dayjs.Dayjs | null) => void;
2121
}
2222
) => {
2323
const MobileDatePicker = (await import("antd-mobile/es/components/date-picker")).default;
2424

25-
const min = moment(params.minDate, DateParser);
26-
const max = moment(params.maxDate, DateParser);
25+
const min = dayjs(params.minDate, DateParser);
26+
const max = dayjs(params.maxDate, DateParser);
2727

2828
const { disabledHours, disabledMinutes, disabledSeconds } = params.disabledTime();
2929

@@ -42,7 +42,7 @@ const handleClick = async (
4242
second: (val, { date }) => !disabledSeconds(date.getHours(), date.getMinutes()).includes(val),
4343
},
4444
onConfirm: (value) => {
45-
const time = moment(value);
45+
const time = dayjs(value);
4646
params.onChange(time);
4747
},
4848
onClose: params.onBlur,

client/packages/lowcoder/src/comps/comps/dateComp/dateRangeUIView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import moment from "moment/moment";
1+
import dayjs from "dayjs";
22
import type { DateCompViewProps } from "./dateComp";
33
import { disabledDate, getStyle } from "comps/comps/dateComp/dateCompUtil";
44
import { useUIView } from "../../utils/useUIView";
@@ -21,9 +21,9 @@ const DateRangeMobileUIView = React.lazy(() =>
2121
);
2222

2323
export interface DateRangeUIViewProps extends DateCompViewProps {
24-
start: moment.Moment | null;
25-
end: moment.Moment | null;
26-
onChange: (start?: moment.Moment | null, end?: moment.Moment | null) => void;
24+
start: dayjs.Dayjs | null;
25+
end: dayjs.Dayjs | null;
26+
onChange: (start?: dayjs.Dayjs | null, end?: dayjs.Dayjs | null) => void;
2727
onPanelChange: (value: any, mode: [string, string]) => void;
2828
}
2929

client/packages/lowcoder/src/comps/comps/dateComp/dateUIView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import moment from "moment/moment";
1+
import dayjs from "dayjs";
22
import type { DateCompViewProps } from "./dateComp";
33
import { disabledDate, getStyle } from "comps/comps/dateComp/dateCompUtil";
44
import { useUIView } from "../../utils/useUIView";
@@ -15,8 +15,8 @@ const DatePickerStyled = styled(DatePicker)<{ $style: DateTimeStyleType }>`
1515
`;
1616

1717
export interface DataUIViewProps extends DateCompViewProps {
18-
value: moment.Moment | null;
19-
onChange: (value: moment.Moment | null) => void;
18+
value: dayjs.Dayjs | null;
19+
onChange: (value: dayjs.Dayjs | null) => void;
2020
onPanelChange: () => void;
2121
}
2222

0 commit comments

Comments
 (0)