Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Created June 5, 2025 09:32
Show Gist options
  • Save aimahdi/b96b52b3e4cecc76a571f1b3803f7957 to your computer and use it in GitHub Desktop.
Save aimahdi/b96b52b3e4cecc76a571f1b3803f7957 to your computer and use it in GitHub Desktop.
window.onload= function () {
flatpickr('.fp', {
enableTime: true,
dateFormat: "Y-m-d H:i",
onReady: updateLimits,
onChange: updateLimits
});
function updateLimits(selectedDates, dateStr, instance) {
const day = (selectedDates[0] || new Date()).getDay();
const timeLimits = {
0: ['10:00', '14:00'], // Sunday
1: ['09:00', '17:00'],
2: ['09:00', '17:00'],
3: ['09:00', '17:00'],
4: ['09:00', '17:00'],
5: ['09:00', '17:00'],
6: ['11:00', '15:00'] // Saturday
};
const [min, max] = timeLimits[day];
instance.set('minTime', min);
instance.set('maxTime', max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment