I need help figuring out a little bit of a complex check. Of course ill share what ive done, and what my end goal is..
There are quite a few variables to take into account here.
But In essence I have a Start date & End Date Both with Days/Months/Years saved Separately..
Now feel free to at any-point tell me if the whole approach is wrong. What needs to occur is that the person making a entry can only do so once for that specific Date Range then they are on a "Ban timer" That has to be included in the check. I need to check to see whenever someone tries to create a entry that its not in between:
- And already booked range. This means There start date must be <= Day and end date >= endDay this also means months have to be taken into account But im not sure if I check for that exact month E.G
if(01 == 01)but what if they end up booking more then 1 month? These rules are not set out yet. - The "Ban timer" which is
Member.length - 1E.G if there is 5 people you cannot book that exact date for another 4 years. - Look at the person booking it for the next year. E.G Bob gets 01/01/2021 -> 01/08/2021 So everyone but bob can get those dates for the next "Ban" Duration which is relevant to the group. but for my group lets say the group size is 5 So
const ban = 4 - This all needs to be checked against every current entry made
Where im getting lost is ways to go about this. and what to do about the ban duration..
Here is my very poor attempt at this:
for (const element of this.entries) {
if(startDay <= element.startDate.day && endDay >= element.endDate.day && startMonth != element.startDate.month && endMonth != element.endDate.month && startYear != element.startDate.year){
}
if(startDay <= element.startDate.day && endDay >= element.endDate.day){
if(startMonth != element.startDate.month && endMonth != element.endDate.month){
if(startYear != element.startDate.year){
if(this.persist.memberinfo.surname == element.surname && startYear == element.startDate.year + this.persist.ban){
}
}
}
}
}
1.Nested If's are bad
2.Lengthy ifs like that are bad
3.Months become a huge mess like this -> Because If someone books only up until the 15th of the month that doesnt mean that month is booked it just means half of it but how do I check that
My brain is spinning at the moment so apolegies if i explain things confusingly..
Im not sure how to go about If but type of situation as mentioned with the months because if i say StartMonth != (Database.Month) That might be true that it is in the same month but different days..
The Model:
export class Entrymodel {
id: string;
surname: string;
color: string;
startDate: Startdate;
endDate: Enddate;
info: string;
status: boolean;
}
export class Startdate{
day: number;
month: number;
year: number;
}
export class Enddate{
day: number;
month: number;
year: number;
}
How I get and Set the Dates from the Range picker:
createEntry(startDate, endDate, entryinfo: string){
var startValue = startDate;
var startDay = startValue.substring(0,1);
var startMonth = startValue.substring(2,3);
var startYear = startValue.substring(4,8);
var endValue = endDate;
var endDay = endValue.substring(0,1);
var endMonth = endValue.substring(2,3);
var endYear = endValue.substring(4,8);
this.uniqueID = uuidv4();
const newEntry = {
id: this.uniqueID,
surname: this.persist.memberinfo.surname,
color: this.persist.memberinfo.color,
startDate: {
day: startDay,
month: startMonth,
year: startYear
},
endDate: {
day: endDay,
month: endMonth,
year: endYear
},
info: entryinfo,
status: true
} as Entrymodel;
this.entryservice.createEntry(newEntry);
My So Called "Persistent" Variables
ban:number;
loggedin: boolean;
Membercount: number;
memberinfo: Persistance;
persist: Persistance = new Persistance();
export class Persistance {
surname?: string;
color?: string;
}
Edit: This is not me asking For a "do my homework" type thing I have tried this multiple times.. I have provided my although it be very poor attempt at it I just cant seem to find a way to do this properly.. I just require a fresh take on the issue
Aucun commentaire:
Enregistrer un commentaire