configure weekends start day

This commit is contained in:
Ronid1
2024-03-04 11:53:47 -08:00
parent 2ac4e08e75
commit b67dee1eed
3 changed files with 31 additions and 1 deletions

View File

@@ -1281,6 +1281,11 @@ export interface GanttDiagramConfig extends BaseDiagramConfig {
* *
*/ */
weekday?: 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'; weekday?: 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday';
/**
* On which day a weekend interval should start
*
*/
weekend?: 'friday' | 'saturday';
} }
/** /**
* The object containing configurations specific for sequence diagrams * The object containing configurations specific for sequence diagrams

View File

@@ -21,6 +21,7 @@ dayjs.extend(dayjsIsoWeek);
dayjs.extend(dayjsCustomParseFormat); dayjs.extend(dayjsCustomParseFormat);
dayjs.extend(dayjsAdvancedFormat); dayjs.extend(dayjsAdvancedFormat);
const WEEKEND_START_DAY = { friday: 5, saturday: 6 };
let dateFormat = ''; let dateFormat = '';
let axisFormat = ''; let axisFormat = '';
let tickInterval = undefined; let tickInterval = undefined;
@@ -37,6 +38,7 @@ let funs = [];
let inclusiveEndDates = false; let inclusiveEndDates = false;
let topAxis = false; let topAxis = false;
let weekday = 'sunday'; let weekday = 'sunday';
let weekend = 'saturday';
// The serial order of the task in the script // The serial order of the task in the script
let lastOrder = 0; let lastOrder = 0;
@@ -63,6 +65,7 @@ export const clear = function () {
links = {}; links = {};
commonClear(); commonClear();
weekday = 'sunday'; weekday = 'sunday';
weekend = 'saturday';
}; };
export const setAxisFormat = function (txt) { export const setAxisFormat = function (txt) {
@@ -167,7 +170,11 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) {
if (includes.includes(date.format(dateFormat.trim()))) { if (includes.includes(date.format(dateFormat.trim()))) {
return false; return false;
} }
if (date.isoWeekday() >= 6 && excludes.includes('weekends')) { if (
excludes.includes('weekends') &&
(date.isoWeekday() == WEEKEND_START_DAY[weekend] ||
date.isoWeekday() == WEEKEND_START_DAY[weekend] + 1)
) {
return true; return true;
} }
if (excludes.includes(date.format('dddd').toLowerCase())) { if (excludes.includes(date.format('dddd').toLowerCase())) {
@@ -184,6 +191,14 @@ export const getWeekday = function () {
return weekday; return weekday;
}; };
export const setWeekend = function (startDay) {
weekend = startDay;
};
export const getWeekend = function () {
return weekend;
};
/** /**
* TODO: fully document what this function does and what types it accepts * TODO: fully document what this function does and what types it accepts
* *
@@ -781,6 +796,8 @@ export default {
isInvalidDate, isInvalidDate,
setWeekday, setWeekday,
getWeekday, getWeekday,
setWeekend,
getWeekend,
}; };
/** /**

View File

@@ -84,6 +84,8 @@ weekday\s+thursday return 'weekday_thursday'
weekday\s+friday return 'weekday_friday' weekday\s+friday return 'weekday_friday'
weekday\s+saturday return 'weekday_saturday' weekday\s+saturday return 'weekday_saturday'
weekday\s+sunday return 'weekday_sunday' weekday\s+sunday return 'weekday_sunday'
weekend\s+friday return 'weekend_friday'
weekend\s+saturday return 'weekend_saturday'
\d\d\d\d"-"\d\d"-"\d\d return 'date'; \d\d\d\d"-"\d\d"-"\d\d return 'date';
"title"\s[^\n]+ return 'title'; "title"\s[^\n]+ return 'title';
"accDescription"\s[^#\n;]+ return 'accDescription' "accDescription"\s[^#\n;]+ return 'accDescription'
@@ -128,6 +130,11 @@ weekday
| weekday_sunday { yy.setWeekday("sunday");} | weekday_sunday { yy.setWeekday("sunday");}
; ;
weekend
: weekend_friday { yy.setWeekend("friday");}
| weekend_saturday { yy.setWeekend("saturday");}
;
statement statement
: dateFormat {yy.setDateFormat($1.substr(11));$$=$1.substr(11);} : dateFormat {yy.setDateFormat($1.substr(11));$$=$1.substr(11);}
| inclusiveEndDates {yy.enableInclusiveEndDates();$$=$1.substr(18);} | inclusiveEndDates {yy.enableInclusiveEndDates();$$=$1.substr(18);}
@@ -138,6 +145,7 @@ statement
| includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);} | includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);}
| todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);} | todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);}
| weekday | weekday
| weekend
| title {yy.setDiagramTitle($1.substr(6));$$=$1.substr(6);} | title {yy.setDiagramTitle($1.substr(6));$$=$1.substr(6);}
| acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); } | acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); } | acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }