Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practice slots 6 to 10am #319

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/components/PracticeSlots/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,35 @@ export default class extends React.Component {
}

getTimeSlot = (index) => {
let hours = ["06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05"]
let mins = ["00", "15", "30", "45"]
let endMin = ["59", "14", "29", "44"]
let meridiem = ["AM", "PM"];
let startHourIndex = Math.floor(index / 4) % 12;
let startMinIndex = index % 4;
let startMeridiemIndex = (Math.floor((startHourIndex + 6) / 12)) % 2;
let nextIndex = index + 1;
let endHourIndex = Math.floor(index / 4) % 12;
let endMinIndex = nextIndex % 4;
let endMeridiemIndex = (Math.floor((endHourIndex + 6) / 12)) % 2;
return `${hours[startHourIndex]}:${mins[startMinIndex]} ${meridiem[startMeridiemIndex]} - ${hours[endHourIndex]}:${endMin[endMinIndex]} ${meridiem[endMeridiemIndex]}`
}
var totalTeams = this.state.slots.length;
// time should start from 6 till 10 am
const startTime = new Date();
startTime.setHours(6, 0, 0, 0);
const endTime = new Date();
endTime.setHours(10, 0, 0, 0);
//total = 10am-6am = 240 minutes

// total minutes between 6 am to 10 am
//can hardcode 240 mins
const totalMinutes = (endTime - startTime) / (1000 * 60);

// time in minutes per team
let timePerTeam = Math.floor(totalMinutes / totalTeams);

// if it exceeds 15 min then restrict it to 15 only ie (if there are less teams)
timePerTeam = Math.min(timePerTeam, 15);

// calculate slot timing for perticular team
const slotStartTime = new Date(startTime.getTime() + index * timePerTeam * 60 * 1000);
const slotEndTime = new Date(slotStartTime.getTime() + timePerTeam * 60 * 1000);

// formating of time
const startTimeString = slotStartTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const endTimeString = slotEndTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });

return `${startTimeString} - ${endTimeString}`;
}


animate(slots) {
this.slots = Object.assign([], slots);
Expand Down
Loading