Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless date clone in dayjs adapter #615

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions packages/dayjs/src/dayjs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
};

public startOfDay = (date: TDate) => {
return date.clone().startOf("day") as TDate;
return date.startOf("day") as TDate;
};

public endOfDay = (date: TDate) => {
return date.clone().endOf("day") as TDate;
return date.endOf("day") as TDate;
};

public format = (date: Dayjs, formatKey: keyof DateIOFormats) => {
Expand Down Expand Up @@ -234,15 +234,15 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
};

public setMinutes = (date: Dayjs, count: number) => {
return date.clone().set("minute", count) as TDate;
return date.set("minute", count) as TDate;
};

public getSeconds = (date: Dayjs) => {
return date.second();
};

public setSeconds = (date: Dayjs, count: number) => {
return date.clone().set("second", count) as TDate;
return date.set("second", count) as TDate;
};

public getMonth = (date: Dayjs) => {
Expand Down Expand Up @@ -282,31 +282,31 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
};

public startOfMonth = (date: Dayjs) => {
return date.clone().startOf("month") as TDate;
return date.startOf("month") as TDate;
};

public endOfMonth = (date: Dayjs) => {
return date.clone().endOf("month") as TDate;
return date.endOf("month") as TDate;
};

public startOfWeek = (date: Dayjs) => {
return date.clone().startOf("week") as TDate;
return date.startOf("week") as TDate;
};

public endOfWeek = (date: Dayjs) => {
return date.clone().endOf("week") as TDate;
return date.endOf("week") as TDate;
};

public getNextMonth = (date: Dayjs) => {
return date.clone().add(1, "month") as TDate;
return date.add(1, "month") as TDate;
};

public getPreviousMonth = (date: Dayjs) => {
return date.clone().subtract(1, "month") as TDate;
return date.subtract(1, "month") as TDate;
};

public getMonthArray = (date: TDate) => {
const firstMonth = date.clone().startOf("year") as TDate;
const firstMonth = date.startOf("year") as TDate;
const monthArray = [firstMonth];

while (monthArray.length < 12) {
Expand All @@ -322,7 +322,7 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
};

public setYear = (date: Dayjs, year: number) => {
return date.clone().set("year", year) as TDate;
return date.set("year", year) as TDate;
};

public mergeDateAndTime = (date: TDate, time: TDate) => {
Expand All @@ -345,8 +345,8 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
};

public getWeekArray = (date: TDate) => {
const start = this.dayjs(date).clone().startOf("month").startOf("week") as TDate;
const end = this.dayjs(date).clone().endOf("month").endOf("week") as TDate;
const start = this.dayjs(date).startOf("month").startOf("week") as TDate;
const end = this.dayjs(date).endOf("month").endOf("week") as TDate;

let count = 0;
let current = start;
Expand All @@ -357,7 +357,7 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
nestedWeeks[weekNumber].push(current);

current = current.clone().add(1, "day") as TDate;
current = current.add(1, "day") as TDate;
count += 1;
}

Expand All @@ -372,7 +372,7 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
let current = startDate;
while (current.isBefore(endDate)) {
years.push(current as TDate);
current = current.clone().add(1, "year");
current = current.add(1, "year");
}

return years;
Expand Down