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K,SAAS,CAAC,QAAQ,EAAE,IAAI,WAAW,CAAC,OAAO,EAAE,KAAK,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;oBACrG,cAAc,GAAG,IAAI,CAAC;gBACxB,CAAC;gBACD,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACnB,WAAW,EAAE,CAAC;QAChB,CAAC;QAED,QAAQ,iBAAiB,CAAC,IAAI,EAAE,CAAC;YAC/B,KAAK,iCAAiC,CAAC,KAAK;gBAC1C,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;gBACxE,MAAM;YACR,KAAK,iCAAiC,CAAC,MAAM;gBAC3C,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,iBAAiB,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;gBAC5E,MAAM;YACR,KAAK,iCAAiC,CAAC,eAAe;gBACpD,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;gBAC1E,MAAM;YACR,KAAK,iCAAiC,CAAC,cAAc;gBACnD,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;gBAChF,MAAM;QACV,CAAC;QAED,wBAAwB;QACxB,IAAI,eAAe,CAAC,IAAI,KAAK,OAAO,IAAI,WAAW,GAAG,GAAG,EAAE,CAAC;YAC1D,MAAM,CAAC,uCAAuC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","file":"helpers.js","sourcesContent":["import { daytool_case, daytool_entity, daytool_event, daytool_goal, daytool_need, daytool_note, daytool_person, daytool_plan, daytool_stat } from \"./classes/daytool_entity.js\";\nimport { DateTimeTimeZone, MICROSOFT_RECURRENCE_PATTERN_TYPE } from \"./classes/UI/daytool_event.js\";\n\nexport function pad_with_zero(n: number): string {\n return n < 10 ? \"0\" + n.toString() : n.toString();\n}\n\nexport function capitalizeFirstLetter(string: string) {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n// Arrays\nexport function sort_items(array_to_sort_over: any[], asc_or_dsc: string) {\n var sorted_items: any[] = [];\n if (asc_or_dsc == \"asc\") {\n array_to_sort_over.sort(function (a, b) {\n return a[0] - b[0];\n });\n } else if (asc_or_dsc == \"dsc\") {\n array_to_sort_over.sort(function (a, b) {\n return b[0] - a[0];\n });\n }\n // Populate cards_to_return\n for (var i = 0; i < array_to_sort_over.length; i++) {\n sorted_items.push(array_to_sort_over[i][1]);\n }\n return sorted_items;\n}\n\nexport function handleScroll(scrollContainer, contentDiv, action ) {\n const containerHeight = scrollContainer.clientHeight;\n const scrollTop = scrollContainer.scrollTop;\n const contentHeight = contentDiv.offsetHeight;\n\n // Check if the user has scrolled to the bottom\n if (scrollTop + containerHeight >= contentHeight) {\n action();\n }\n}\n\n\nexport function setSelectedOptionByValue(selectId, value) {\n var selectElement = document.getElementById(selectId);\n for (let i = 0; i < selectElement.options.length; i++) {\n if (selectElement.options[i].value === value.toString()) {\n selectElement.selectedIndex = i;\n break;\n }\n }\n}\n\n\n\nexport function escapeHtml(input: string): string {\n const map: { [key: string]: string } = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n };\n\n return input.replace(/[&<>\"']/g, (m) => map[m]);\n}\n\nclass DateTimeFormatOptions {\n weekday:string;\n year:string;\n month:string;\n day:string;\n}\n\nexport function formatDate(startTimestamp: number, endTimestamp: number) {\n var startTimeDateObject = new Date(startTimestamp);\n var endTimeDateObject = new Date(endTimestamp);\n const options : Intl.DateTimeFormatOptions = {\n weekday: \"long\",\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n };\n endTimeDateObject.setHours(endTimeDateObject.getHours() + 1); // Set end time to 1 hour later\n\n // Format time\n const startHour = startTimeDateObject.getHours() % 12 || 12; // Convert 24-hour time to 12-hour time\n const startMinutes = startTimeDateObject.getMinutes().toString().padStart(2, \"0\");\n const startPeriod = startTimeDateObject.getHours() >= 12 ? \"PM\" : \"AM\";\n const endHour = endTimeDateObject.getHours() % 12 || 12;\n const endMinutes = endTimeDateObject.getMinutes().toString().padStart(2, \"0\");\n const endPeriod = endTimeDateObject.getHours() >= 12 ? \"PM\" : \"AM\";\n\n // Format date\n const formattedDate = startTimeDateObject.toLocaleDateString(\"en-US\", options);\n\n // Extract day with suffix\n const day = startTimeDateObject.getDate();\n const suffix =\n day % 10 === 1 && day !== 11\n ? \"st\"\n : day % 10 === 2 && day !== 12\n ? \"nd\"\n : day % 10 === 3 && day !== 13\n ? \"rd\"\n : \"th\";\n\n const dayWithSuffix = day + suffix;\n\n // Construct final formatted string\n const finalFormattedString = `${startHour}:${startMinutes} ${startPeriod} - ${endHour}:${endMinutes} ${endPeriod} ${\n formattedDate.split(\" \")[0]\n } ${\n formattedDate.split(\" \")[1]\n } ${dayWithSuffix}, ${startTimeDateObject.getFullYear()}`;\n\n return finalFormattedString;\n}\n\nexport function resetNodeEvents(node) {\n // Create a clone of the node\n const clone = node.cloneNode(true); // true means deep clone, copying child nodes as well\n\n // Replace the original node with the clone\n node.parentNode.replaceChild(clone, node);\n\n return clone; // Return the new node if further manipulation is needed\n}\n\nexport function parseYYYYMMDDDate(dateString: string): Date {\n const [year, month, day] = dateString.split(\"-\").map(Number);\n return new Date(year, month - 1, day);\n}\n\nexport function returnDateFromDateTimeTimeZone(date_object: DateTimeTimeZone) {\n if (date_object) {\n const dateTimeString = date_object.dateTime;\n const timeZone = date_object.timeZone;\n const dateObject = new Date(dateTimeString);\n const dateWithTimeZone = new Date(\n dateObject.toLocaleString(\"en-US\", { timeZone: timeZone })\n );\n return dateWithTimeZone;\n }\n return null;\n}\n\nexport function make_id(length: number) {\n let result = \"\";\n const characters =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n const charactersLength = characters.length;\n let counter = 0;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n return result;\n}\n\nexport function reset_casting (entities: daytool_entity[]) {\n var casted_entities = [];\n var object;\n for (var e = 0; e < entities.length; e++) {\n // Explicit casting\n if (entities[e].type == 'needs') {\n object = new daytool_need();\n } else if (entities[e].type == 'plans') {\n object = new daytool_plan();\n } else if (entities[e].type == 'events') {\n object = new daytool_event(null, null, null);\n } else if (entities[e].type == 'cases') {\n object = new daytool_case();\n } else if (entities[e].type == 'stats') {\n object = new daytool_stat();\n } else if (entities[e].type == 'goals') {\n object = new daytool_goal();\n } else if (entities[e].type == 'notes') {\n object = new daytool_note();\n } else if (entities[e].type == 'persons') {\n object = new daytool_person();\n }\n Object.assign(object, entities[e]);\n casted_entities.push(object);\n }\n return casted_entities;\n}\n\nexport function calculateNumberOfOccurrences(recurrencePattern, recurrenceRange) {\n const startDate = new Date(recurrenceRange.startDate);\n const endDate = recurrenceRange.type === 'endDate' ? new Date(recurrenceRange.endDate) : null;\n\n if (recurrenceRange.type === 'numbered') {\n return recurrenceRange.numberOfOccurrences;\n }\n\n const daysOfWeekMap = {\n \"sunday\": 0,\n \"monday\": 1,\n \"tuesday\": 2,\n \"wednesday\": 3,\n \"thursday\": 4,\n \"friday\": 5,\n \"saturday\": 6\n };\n\n let occurrences = 0;\n let currentDate = new Date(startDate);\n\n while (!endDate || currentDate <= endDate) {\n let matchesPattern = false;\n\n switch (recurrencePattern.type) {\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.daily:\n matchesPattern = true;\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.weekly:\n if (recurrencePattern.daysOfWeek.includes(Object.keys(daysOfWeekMap)[currentDate.getDay()])) {\n matchesPattern = true;\n }\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.relativeMonthly:\n if (currentDate.getDate() === startDate.getDate()) {\n matchesPattern = true;\n }\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.relativeYearly:\n if (currentDate.getMonth() === startDate.getMonth() && currentDate.getDate() === startDate.getDate()) {\n matchesPattern = true;\n }\n break;\n default:\n throw new Error(\"Unsupported recurrence pattern type\");\n }\n\n if (matchesPattern) {\n occurrences++;\n }\n\n switch (recurrencePattern.type) {\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.daily:\n currentDate.setDate(currentDate.getDate() + recurrencePattern.interval);\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.weekly:\n currentDate.setDate(currentDate.getDate() + recurrencePattern.interval * 7);\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.relativeMonthly:\n currentDate.setMonth(currentDate.getMonth() + recurrencePattern.interval);\n break;\n case MICROSOFT_RECURRENCE_PATTERN_TYPE.relativeYearly:\n currentDate.setFullYear(currentDate.getFullYear() + recurrencePattern.interval);\n break;\n }\n\n // Handle the noEnd case\n if (recurrenceRange.type === 'noEnd' && occurrences > 999) {\n break; // Safety check to avoid infinite loops\n }\n }\n\n return occurrences;\n}"]}