finished schedule module

This commit is contained in:
faris Aljohari
2024-09-15 18:03:30 +03:00
parent 0df4af175f
commit d962d4a7b3
11 changed files with 559 additions and 0 deletions

View File

@ -0,0 +1,23 @@
export function convertTimestampToDubaiTime(timestamp) {
// Convert timestamp to milliseconds
const date = new Date(timestamp * 1000);
// Convert to Dubai time (UTC+4)
const dubaiTimeOffset = 4 * 60; // 4 hours in minutes
const dubaiTime = new Date(date.getTime() + dubaiTimeOffset * 60 * 1000);
// Format the date as YYYYMMDD
const year = dubaiTime.getUTCFullYear();
const month = String(dubaiTime.getUTCMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(dubaiTime.getUTCDate()).padStart(2, '0');
// Format the time as HH:MM (24-hour format)
const hours = String(dubaiTime.getUTCHours()).padStart(2, '0');
const minutes = String(dubaiTime.getUTCMinutes()).padStart(2, '0');
// Return formatted date and time
return {
date: `${year}${month}${day}`,
time: `${hours}:${minutes}`,
};
}

View File

@ -0,0 +1,27 @@
export function getScheduleStatus(daysEnabled: string[]): string {
const daysMap: string[] = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const schedule: string[] = Array(7).fill('0');
daysEnabled.forEach((day) => {
const index: number = daysMap.indexOf(day);
if (index !== -1) {
schedule[index] = '1';
}
});
return schedule.join('');
}
export function getEnabledDays(schedule: string): string[] {
const daysMap: string[] = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const enabledDays: string[] = [];
// Iterate through the schedule string
for (let i = 0; i < schedule.length; i++) {
if (schedule[i] === '1') {
enabledDays.push(daysMap[i]);
}
}
return enabledDays;
}