Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set time range from 10:00 am to 11:00 pm? #380

Open
kuldeepJain11 opened this issue Jul 20, 2018 · 1 comment
Open

How to set time range from 10:00 am to 11:00 pm? #380

kuldeepJain11 opened this issue Jul 20, 2018 · 1 comment

Comments

@kuldeepJain11
Copy link

Hello,

I am using bootstrap-timepicker plugin with milton admin panel. I want to define time range from 10:am to 11:00 pm.

can you please guide me, how it is possible?

Thanks,

@o2sevruk
Copy link

o2sevruk commented Jul 27, 2020

This is some self-written function. Maybe it'll help someone.

function compareTimestamps(from, to) {
		var fromCurHoursIsSet = false,
			fromMinHours = null,
			fromMinMinutes = null,
			toCurHoursIsSet = false,
			toMinHours = null,
			toMinMinutes = null;
		
		$(from).timepicker().on('changeTime.timepicker', function (e) {
			fromMinHours = e.time.minutes + 15 === 60 ? (e.time.hours >= 24 ? 0 : e.time.hours + 1) : e.time.hours;
			fromMinMinutes = e.time.minutes + 15 === 60 ? 0 : e.time.minutes + 15;
			
			if (
				toCurHoursIsSet &&
				Date.parse(`01/01/2011 ${e.time.hours}:${e.time.minutes}:00`) > Date.parse(`01/01/2011 ${toMinHours}:${toMinMinutes}:00`)
			) {
				$(from).timepicker('setTime', `${toMinHours}:${toMinMinutes}`);
				
				if (!fromCurHoursIsSet) {
					fromCurHoursIsSet = true;
				}
			}
		});
		
		$(to).timepicker().on('changeTime.timepicker', function (e) {
			toMinHours = e.time.minutes - 15 === 60 ? (e.time.hours >= 24 ? 0 : e.time.hours - 1) : e.time.hours;
			toMinMinutes = e.time.minutes - 15 === 60 ? 45 : e.time.minutes - 15;
			
			if (Date.parse(`01/01/2011 ${e.time.hours}:${e.time.minutes}:00`) < Date.parse(`01/01/2011 ${fromMinHours}:${fromMinMinutes}:00`)) {
				$(to).timepicker('setTime', `${fromMinHours}:${fromMinMinutes}`);
				
				if (!toCurHoursIsSet) {
					toCurHoursIsSet = true;
				}
			}
		});
	}
	
	// Private functions
	var bsTimePickerInit = function () {
		$('#timepicker_1, #timepicker_2').timepicker({
			defaultTime: '',
			maxHours: 24,
			showMeridian: false
		});
		
		compareTimestamps('#timepicker_1', '#timepicker_2');
	};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants