fix: hotFix getStartDateOfWeekNumber
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a713ef64e8
commit
5ab06ef6e4
|
@ -45,7 +45,7 @@ module.exports = Self => {
|
|||
const from = Date.vnNew();
|
||||
const to = Date.vnNew();
|
||||
|
||||
const time = await models.Time.findOne({
|
||||
const [time] = await models.Time.find({
|
||||
where: {
|
||||
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
|
||||
},
|
||||
|
@ -55,8 +55,7 @@ module.exports = Self => {
|
|||
args.week = time.week;
|
||||
args.year = time.year;
|
||||
}
|
||||
|
||||
const started = getStartDateOfWeekNumber(args.week, args.year);
|
||||
const started = Self.getStartDateOfWeekNumber(args.week, args.year);
|
||||
started.setHours(0, 0, 0, 0);
|
||||
|
||||
const ended = new Date(started);
|
||||
|
@ -388,17 +387,6 @@ module.exports = Self => {
|
|||
return true;
|
||||
};
|
||||
|
||||
function getStartDateOfWeekNumber(week, year) {
|
||||
const simple = new Date(year, 0, 1 + (week - 1) * 7);
|
||||
const dow = simple.getDay();
|
||||
const weekStart = simple;
|
||||
if (dow <= 4)
|
||||
weekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
||||
else
|
||||
weekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
||||
return weekStart;
|
||||
}
|
||||
|
||||
function getTime(timeString) {
|
||||
const [hours, minutes, seconds] = timeString.split(':');
|
||||
return [parseInt(hours), parseInt(minutes), parseInt(seconds)];
|
||||
|
|
|
@ -55,7 +55,7 @@ module.exports = Self => {
|
|||
}
|
||||
}, myOptions);
|
||||
|
||||
const dated = getMondayDateFromYearWeek(args.year, args.week);
|
||||
const dated = Self.getStartDateOfWeekNumber(args.week, args.year);
|
||||
const timestamp = dated.getTime() / 1000;
|
||||
|
||||
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||
|
@ -64,23 +64,4 @@ module.exports = Self => {
|
|||
await models.WorkerTimeControl.updateMailState(ctx, ctx.args.workerId, myOptions);
|
||||
return Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||
};
|
||||
|
||||
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||
const yearStart = new Date(yearNumber, 0, 1);
|
||||
const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000);
|
||||
const firstMondayWeekNumber = getWeekNumber(firstMonday);
|
||||
|
||||
if (firstMondayWeekNumber > 1)
|
||||
firstMonday.setDate(firstMonday.getDate() + 7);
|
||||
|
||||
firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7);
|
||||
|
||||
return firstMonday;
|
||||
}
|
||||
|
||||
function getWeekNumber(date) {
|
||||
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
|
||||
const daysPassed = (date - firstDayOfYear) / 86400000;
|
||||
return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,4 +19,15 @@ module.exports = Self => {
|
|||
return new UserError(`The introduced hour already exists`);
|
||||
return err;
|
||||
});
|
||||
|
||||
Self.getStartDateOfWeekNumber = (week, year) => {
|
||||
const simple = new Date(year, 0, 1 + (week - 1) * 7);
|
||||
const dow = simple.getDay();
|
||||
const weekStart = simple;
|
||||
if (dow <= 4)
|
||||
weekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
||||
else
|
||||
weekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
||||
return weekStart;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue