Add disclaimer about calculation

This commit is contained in:
Zachary
2024-11-13 14:43:13 +01:00
parent 99f76a9a99
commit 37f69739f9

View File

@@ -12,7 +12,7 @@
countries.registerLocale(enLocale); countries.registerLocale(enLocale);
let countriesList = countries.getNames('en'); let countriesList = countries.getNames('en');
let year = new Date().getFullYear(); let year;
let months = Array.from({ length: 12 }, (_, i) => i); let months = Array.from({ length: 12 }, (_, i) => i);
let selectedCountry = ''; let selectedCountry = '';
let holidays = []; let holidays = [];
@@ -37,10 +37,18 @@
$: selectedCountryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry); $: selectedCountryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
$: if (selectedCountryCode || selectedStateCode || daysOff) { $: if (selectedCountryCode || selectedStateCode ) {
updateHolidays(); updateHolidays();
} }
$: if (daysOff) {
localStorage.setItem('daysOff', daysOff);
}
$: if (year) {
localStorage.setItem('year', year);
}
function updateStatesList(countryCode) { function updateStatesList(countryCode) {
const hd = new Holidays(countryCode); const hd = new Holidays(countryCode);
statesList = hd.getStates(countryCode) || []; statesList = hd.getStates(countryCode) || [];
@@ -62,7 +70,7 @@
fetchCountryCode().then(() => { fetchCountryCode().then(() => {
defaultYear = new Date().getFullYear(); defaultYear = new Date().getFullYear();
defaultCountry = selectedCountry; defaultCountry = selectedCountry;
defaultDaysOff = daysOff; defaultDaysOff = ptoData[selectedCountryCode];
const storedYear = localStorage.getItem('year'); const storedYear = localStorage.getItem('year');
const storedCountry = localStorage.getItem('selectedCountry'); const storedCountry = localStorage.getItem('selectedCountry');
@@ -75,6 +83,7 @@
daysOff = storedDaysOff ? parseInt(storedDaysOff, 10) : defaultDaysOff; daysOff = storedDaysOff ? parseInt(storedDaysOff, 10) : defaultDaysOff;
selectedState = storedState || ''; selectedState = storedState || '';
selectedStateCode = storedStateCode || ''; selectedStateCode = storedStateCode || '';
updateHolidays();
}); });
if (selectedCountryCode) { if (selectedCountryCode) {
@@ -85,12 +94,11 @@
async function fetchCountryCode() { async function fetchCountryCode() {
try { try {
const response = await fetch('/cdn-cgi/trace'); const response = await fetch('https://stretchmytimeoff.com/cdn-cgi/trace');
const text = await response.text(); const text = await response.text();
const countryCodeMatch = text.match(/loc=(\w+)/); const countryCodeMatch = text.match(/loc=(\w+)/);
const countryCode = countryCodeMatch ? countryCodeMatch[1] : ''; const countryCode = countryCodeMatch ? countryCodeMatch[1] : '';
selectedCountry = countriesList[countryCode] || ''; selectedCountry = countriesList[countryCode] || '';
daysOff = ptoData[countryCode] || 0;
} catch (error) { } catch (error) {
console.error('Error fetching country code:', error); console.error('Error fetching country code:', error);
} }
@@ -126,8 +134,6 @@
optimizedDaysOff = []; optimizedDaysOff = [];
consecutiveDaysOff = []; consecutiveDaysOff = [];
} }
localStorage.setItem('year', year);
localStorage.setItem('daysOff', daysOff);
} }
function resetToDefault() { function resetToDefault() {
@@ -689,6 +695,9 @@
<p> <p>
The algorithm prioritizes filling the shortest gaps first. It optimizes for spreading your holidays throughout the year to create the most number of consecutive vacation periods. The algorithm prioritizes filling the shortest gaps first. It optimizes for spreading your holidays throughout the year to create the most number of consecutive vacation periods.
</p> </p>
<p>
For the calculation, it counts all vacation stretches that are 3 days or longer, including those lucky 3-day weekends thanks to public holidays. It's slightly optimistic, but captures the spirit of maximising time off.
</p>
<p> <p>
Built with <a href="https://kit.svelte.dev/" target="_blank" rel="noopener noreferrer">SvelteKit</a>. Hosted on <a href="https://vercel.com/" target="_blank" rel="noopener noreferrer">Vercel</a> with <a href="https://www.cloudflare.com/" target="_blank" rel="noopener noreferrer">Cloudflare</a>. Developed using <a href="https://www.cursor.com/" target="_blank" rel="noopener noreferrer">Cursor</a>, an AI-powered code editor, and <a href="https://openai.com/research/gpt-4" target="_blank" rel="noopener noreferrer">GPT-4o</a>. Built with <a href="https://kit.svelte.dev/" target="_blank" rel="noopener noreferrer">SvelteKit</a>. Hosted on <a href="https://vercel.com/" target="_blank" rel="noopener noreferrer">Vercel</a> with <a href="https://www.cloudflare.com/" target="_blank" rel="noopener noreferrer">Cloudflare</a>. Developed using <a href="https://www.cursor.com/" target="_blank" rel="noopener noreferrer">Cursor</a>, an AI-powered code editor, and <a href="https://openai.com/research/gpt-4" target="_blank" rel="noopener noreferrer">GPT-4o</a>.
</p> </p>