Created
February 10, 2024 23:19
-
-
Save X7md/4a9d7af21dbf55d0ecd10c69ff6f8fe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hijriToCalendars(year, month, day, op={}) { | |
op.fromCal ??= "islamic-umalqura"; // | |
let gD = new Date(Date.UTC(2000,0,1)); | |
gD = new Date(gD.setUTCDate(gD.getUTCDate() + | |
~~(227022+(year+(month-1)/12+day/354)*354.367))); | |
const gY = gD.getUTCFullYear(gD)-2000, | |
dFormat = new Intl.DateTimeFormat('en-u-ca-' + op.fromCal, {dateStyle:'short', timeZone:'UTC'}); | |
gD = new Date(( gY < 0 ? "-" : "+")+("00000" + Math.abs(gY)).slice(-6)+"-"+("0" + (gD.getUTCMonth(gD)+1)).slice(-2)+"-" + ("0" + gD.getUTCDate(gD)).slice(-2)); | |
let [iM,iD,iY]= [...dFormat.format(gD).split("/")], i=0; | |
gD = new Date(gD.setUTCDate(gD.getUTCDate() + | |
~~(year*354+month*29.53+day-(iY.split(" ")[0]*354+iM*29.53+iD*1)-2))); | |
while (i < 4) { | |
[iM,iD,iY] = [...dFormat.format(gD).split("/")]; | |
if (iD == day && iM == month && iY.split(" ")[0] == year) return formatOutput(gD); | |
gD = new Date(gD.setUTCDate(gD.getUTCDate()+1)); i++; | |
} | |
throw new Error("Invalid "+op.fromCal+" date!"); | |
function formatOutput(gD){ | |
return "toCal"in op ? (op.calendar= op.toCal, | |
new Intl.DateTimeFormat(op.locale ??= "en", op).format(gD)) : gD; | |
} | |
} | |
undefined | |
const tableOfTest = [] | |
undefined | |
const timeTable = [ | |
{"start": "08:00", "end": "10:00"}, | |
{"start": "10:15", "end": "12:15"}, | |
{"start": "12:30", "end": "14:30"}, | |
{"start": "14:45", "end": "16:45"}, | |
{"start": "17:00", "end": "19:00"}, | |
{"start": "19:15", "end": "21:15"} | |
] | |
document.querySelectorAll(".is-active [class*='ROW']").forEach((elem)=> { | |
const theData = {"thetime": elem.lastElementChild?.childNodes[0]?.childNodes[1].childNodes[1].childNodes[3].innerText.trim(), "thedate": elem.lastElementChild?.childNodes[0]?.childNodes[1].childNodes[1].childNodes[1].innerText.trim(), "thesubject": elem.childNodes[3].innerText.trim() | |
} | |
if(!(Object.values(theData).indexOf(undefined) > -1)){ | |
tableOfTest.push({...theData, ...{"thetime": JSON.stringify(timeTable[parseInt(theData["thetime"]) - 1])}, ...{"thedate": hijriToCalendars( ...theData["thedate"].split('-').map(i => parseInt(i)).reverse()).toString().replace(/\d{2}\:.*?$/g, "")}}) | |
} | |
}) | |
console.table(tableOfTest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment