hotFix(workerTimeControl): getWeekNumber
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
1bd1506c12
commit
51e7045e8b
|
@ -4,10 +4,11 @@ import './style.scss';
|
||||||
import UserError from 'core/lib/user-error';
|
import UserError from 'core/lib/user-error';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Section {
|
||||||
constructor($element, $, vnWeekDays) {
|
constructor($element, $, vnWeekDays, moment) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.weekDays = [];
|
this.weekDays = [];
|
||||||
this.weekdayNames = vnWeekDays.locales;
|
this.weekdayNames = vnWeekDays.locales;
|
||||||
|
this.moment = moment;
|
||||||
this.entryDirections = [
|
this.entryDirections = [
|
||||||
{code: 'in', description: this.$t('In')},
|
{code: 'in', description: this.$t('In')},
|
||||||
{code: 'middle', description: this.$t('Intermediate')},
|
{code: 'middle', description: this.$t('Intermediate')},
|
||||||
|
@ -364,14 +365,8 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeekNumber(date) {
|
getWeekNumber(date) {
|
||||||
const tempDate = new Date(date);
|
const tempDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||||
let dayOfWeek = tempDate.getDay();
|
return this.moment(tempDate).isoWeek();
|
||||||
dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek;
|
|
||||||
const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1));
|
|
||||||
const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1);
|
|
||||||
const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime();
|
|
||||||
const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1;
|
|
||||||
return weekNumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isSatisfied() {
|
isSatisfied() {
|
||||||
|
@ -499,7 +494,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
|
Controller.$inject = ['$element', '$scope', 'vnWeekDays', 'moment'];
|
||||||
|
|
||||||
ngModule.vnComponent('vnWorkerTimeControl', {
|
ngModule.vnComponent('vnWorkerTimeControl', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
Loading…
Reference in New Issue