fix: hotFix getMondayWeekYear
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2025-01-08 11:25:07 +01:00
parent 71006797af
commit 60933216f7
3 changed files with 15 additions and 25 deletions

View File

@ -41,21 +41,10 @@ module.exports = Self => {
const stmts = []; const stmts = [];
let stmt; let stmt;
if (!args.week || !args.year) { const {date: started, week, year} = Self.getMondayWeekYear(args.week, args.year);
const from = Date.vnNew(); args.week = week;
const to = Date.vnNew(); args.year = year;
const [time] = await models.Time.find({
where: {
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
},
order: 'week ASC'
}, myOptions);
args.week = time.week;
args.year = time.year;
}
const started = Self.getStartDateOfWeekNumber(args.week, args.year);
started.setHours(0, 0, 0, 0); started.setHours(0, 0, 0, 0);
const ended = new Date(started); const ended = new Date(started);

View File

@ -55,8 +55,8 @@ module.exports = Self => {
} }
}, myOptions); }, myOptions);
const dated = Self.getStartDateOfWeekNumber(args.week, args.year); const {date} = Self.getMondayWeekYear(args.week, args.year);
const timestamp = dated.getTime() / 1000; const timestamp = date.getTime() / 1000;
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
ctx.args.url = url; ctx.args.url = url;

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
module.exports = Self => { module.exports = Self => {
require('../methods/worker-time-control/filter')(Self); require('../methods/worker-time-control/filter')(Self);
@ -20,14 +21,14 @@ module.exports = Self => {
return err; return err;
}); });
Self.getStartDateOfWeekNumber = (week, year) => { Self.getMondayWeekYear = (week, year) => {
const simple = new Date(year, 0, 1 + (week - 1) * 7); if (!week || !year) {
const dow = simple.getDay(); const today = Date.vnNew();
const weekStart = simple; today.setDate(today.getDate() - 7);
if (dow <= 4) week = moment(today).isoWeek();
weekStart.setDate(simple.getDate() - simple.getDay() + 1); year = moment(today).isoWeekYear();
else }
weekStart.setDate(simple.getDate() + 8 - simple.getDay()); const date = moment(year, 'YYYY').week(week).startOf('isoweek').toDate();
return weekStart; return {date, year, week};
}; };
}; };