Skip to content

Instantly share code, notes, and snippets.

@jakubka
Created June 11, 2020 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubka/81d22629464725fdcf8aee4131f77a6f to your computer and use it in GitHub Desktop.
Save jakubka/81d22629464725fdcf8aee4131f77a6f to your computer and use it in GitHub Desktop.
// funkce, ktera vygeneruje 7 datumu (ode dneska vcetne)
function generateDates() {
const dates = [];
const currentDate = new Date();
for (let i = 0; i < 7; i++) {
const date = new Date(currentDate);
date.setDate(date.getDate() + i);
dates.push(date);
}
return dates;
}
// naformatuje do citelne podoby
function formatDate(date) {
const weekdayTranslations = [
'neděle',
'pondělí',
'úterý',
'středa',
'čtvrtek',
'pátek',
'sobota'
];
const weekday = weekdayTranslations[date.getDay()];
return `${weekday} ${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
}
// Cast 2: a tak nejak by mohl vypadat pak ten <select>, kterym bude uzivatel vybirat datum
// misto <selectu> by se stejnym zpusobem dalo pouzit <divy> nebo cokoliv jineho
const dates = generateDates();
<select>
<option v-bind:value="dates[0]">Dnes</option>
<option v-bind:value="dates[1]">Zítra</option>
<option v-bind:value="dates[2]">{{ formatDate(dates[2]) }}</option>
<option v-bind:value="dates[3]">{{ formatDate(dates[3]) }}</option>
<option v-bind:value="dates[4]">{{ formatDate(dates[4]) }}</option>
<option v-bind:value="dates[5]">{{ formatDate(dates[5]) }}</option>
<option v-bind:value="dates[6]">{{ formatDate(dates[6]) }}</option>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment