Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created May 17, 2018 07:16
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 uno-de-piera/489032d6849253ad9545b47cf01a13c8 to your computer and use it in GitHub Desktop.
Save uno-de-piera/489032d6849253ad9545b47cf01a13c8 to your computer and use it in GitHub Desktop.
<template>
<div>
<select v-model="selected_hour">
<option v-for="(value, key) in hours" :value="value">{{ value }}</option>
</select>
</div>
</template>
<script>
export defaul {
data () {
return {
selected_hour: '9:45'
}
},
computed: {
hours () {
let arr = [], i, j;
for(i=0; i<24; i++) {
for(j=0; j<4; j++) {
arr.push(i + ":" + (j===0 ? "00" : 15*j) );
}
}
let d = new Date(),
h = d.getHours(),
m = 15 * Math.floor(d.getMinutes()/15),
stamp = h + ":" + (m === 0 ? "00" : m),
pos = arr.indexOf(stamp);
return arr.slice(pos).concat(arr.slice(0,pos));
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment