๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์„ ํ˜ธํ•˜๋Š”๊ฐœ๋ฐœ

Javascript jQuery 24์‹œ๊ฐ„ ์‹œ๊ฐ„๋น„๊ต ์‹œ๊ฐ„์ฐจ์ด ๊ตฌํ˜„ํ•˜๊ธฐ

 

Javascript jQuery 24์‹œ๊ฐ„ ์‹œ๊ฐ„๋น„๊ต ์‹œ๊ฐ„์ฐจ์ด ๊ตฌํ˜„ํ•˜๊ธฐ

์ž๋™์œผ๋กœ ์‹œ์ž‘์‹œ๊ฐ„๊ณผ ์ข…๋ฃŒ์‹œ๊ฐ„์˜ ์‹œ๊ฐ„์ฐจ์ด๋ฅผ ๋„ฃ์–ด๋‹ฌ๋ผ๋Š” ์š”์ฒญ์ด์žˆ์–ด์„œ.....์ฒ˜๋ฆฌํ•˜๊ฒŒ๋˜์—ˆ์–ด์š”.

ms-sql ์ฟผ๋ฆฌ๋กœ๋Š” ์‹œ๊ฐ„๋งŒ์œผ๋กœ ์‹œ๊ฐ„์ฐจ์ด๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ์—ˆ๋Š”๋ฐ;;;

javascript ์—์„œ๋Š” 0:00 ~13:00 ์ด๋Ÿฐ์‹์˜ ์‹œ๊ฐ„๋งŒ์œผ๋กœ๋Š”์‹œ๊ฐ„์ฐจ์ด๋ฅผ ๊ตฌํ•  ์ˆ˜ ๊ฐ€ ์—†์—ˆ์–ด์š”.

๊ทธ๋ž˜์„œ ์‹ค์ œ ์กด์žฌํ•˜๋Š” ์ž„์˜์˜ ๊ธฐ์ค€์ผ์„ ์„ค์ •ํ•˜๊ณ , FROM์ด TO ๋ณด๋‹ค ํฐ๊ฒฝ์šฐ์—๋Š” ๋‹ค์Œ๋‚ ๋กœ ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค!!

์ด๋ถ€๋ถ„์ด ํ•ต์‹ฌ!! ์ง„์งœ ๊ณ ๋ฏผ๊ณ ๋ฏผํ•˜์˜€์Œ!

23:30(FROM)> 1:30(TO) ์ด๋Ÿฐ๊ฒฝ์šฐ์— ๋‹ค์Œ๋‚ ๋กœ ์„ค์ •.

๊ทธ๋ฆฌ๊ณ  ๊ธฐ์ค€์ผ์˜ ๋‚ ์งœ ํ˜•ํƒœ๋Š” 2020/10/20 "/"๋กœ ๊ตฌ๋ถ„ํ•ด์•ผ ie/chrome ๋‘˜๋‹ค ์ž‘๋™์ด ๋ฉ๋‹ˆ๋‹ค!!

 

์™„์„ฑํ•œ ์ฝ”๋“œ์˜ ํ˜ธ์ถœ ๋ฐฉ๋ฒ• ์˜ˆ์‹œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

//alert(GetTimeDiff("2300", "400")); //5์‹œ๊ฐ„ ๋ฐ˜ํ™˜
//alert(GetTimeDiff("2300", "400", "mm")); //300๋ถ„ ๋ฐ˜ํ™˜

์•„๋ž˜๋Š” ๊ตฌํ˜„ํ•œ ์ƒ˜ํ”Œ์ž…๋‹ˆ๋‹ค.

์‹œ๊ฐ„

 

//์ž๋ฃŒํ˜•์— ์ƒ๊ด€์—†์ด ๊ฐ’์˜ ์กด์žฌ ์œ ๋ฌด ํ™•์ธ, true:์žˆ์Œ, false:์—†์Œ ([], {} ๋„ ๋นˆ๊ฐ’)
function isExist(val) {
	if (val == "" || val == null || val == undefined || val == "undefined" || (val != null && typeof val == "object" && !Object.keys(val).length)) {
		return false;
	} else {
		return true;
	}
}

function SetTimeToString(intTime) {
	var tmpString = "0:00";
	var tmpInt = 0;
	if (!isNaN(intTime)) {
		tmpString = String(intTime); //๋ฌธ์žํ˜• ๋ณ€ํ™˜
		tmpInt = parseInt(intTime); //์ธํŠธํ˜•

		//์‹œ๊ฐ„ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜
		if (tmpInt <= 0 || tmpInt > 2400) { tmpString = "00:00:00"; } //์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ตœ๋Œ€ 24์‹œ๊ฐ„, ๋งˆ์ด๋„ˆ์Šค์‹œ๊ฐ„ ์—†์Œ
		else if (tmpInt == 30) { tmpString = "00:30:00"; }
		else if (tmpInt >= 100 && tmpInt < 1000) { tmpString = tmpString.substr(0, 1) + ":" + tmpString.substr(1, 2) + ":00"; }
		else if (tmpInt >= 1000) { tmpString = tmpString.substr(0, 2) + ":" + tmpString.substr(2, 2) + ":00"; }
	}
	return tmpString;
}

function GetTimeDiff(sTime, eTime, tType) {
	var tmpTime = "0";
	var strStartTime = ""; //๋ฌธ์žํ˜•
	var strEndTime = ""; //๋ฌธ์žํ˜•

	if (!isNaN(sTime) && !isNaN(eTime)) {
		//isNaN ์ˆซ์ž์ธ๊ฒฝ์šฐ false ๋ฐ˜ํ™˜, ๊ทธ์™ธ true
		if (parseInt(sTime) == parseInt(eTime)) {
			tmpTime = "24"; //์ตœ๋Œ€์‹œ๊ฐ„ 24์‹œ๊ฐ„
		} else {
			strStartTime = SetTimeToString(sTime); //strStartTime์„ ์‹œ๊ฐ„ ํ˜•ํƒœ์˜ ๋ฌธ์žํ˜•์œผ๋กœ ๋ณ€ํ™˜
			strEndTime = SetTimeToString(eTime); //strEndTime์„ ์‹œ๊ฐ„ ํ˜•ํƒœ์˜ ๋ฌธ์žํ˜•์œผ๋กœ ๋ณ€ํ™˜

			//๊ธฐ์ค€ ๋‚ ์งœ(2020/10/20)๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ ๋‚ ์งœ๋กœ ์ž„์˜ ์„ค์ •
			strStartTime = "2020/10/20 " + strStartTime;
			if (parseInt(sTime) > parseInt(eTime)) {
				//strEndTime ์„ ๋‹ค์Œ๋‚ ๋กœ ์„ค์ •
				strEndTime = "2020/10/21 " + strEndTime;
			} else {
				//strStartTime, strEndTime ๋™์ผ๋กœ ์„ค์ •
				strEndTime = "2020/10/20 " + strEndTime;
			}

			var sDate = new Date(strStartTime);
			var eDate = new Date(strEndTime);
			tmpTime = (eDate.getTime() - sDate.getTime()) / (1000 * 60 * (tType == "mm" ? 1 : 60)); //mm์ด๋ฉด ๋ถ„๋‹จ์œ„ ๋ฐ˜ํ™˜, ๊ทธ์™ธ ์‹œ๊ฐ„ ๋‹จ์œ„ ๋ฐ˜ํ™˜
		}
	}

	return tmpTime;
}

function SetRealWorkTime() {
	var workTimeFrom = $("#sltWorkTimeFrom option:selected").val(); //์‹œ์ž‘์‹œ๊ฐ„
	var workTimeTo = $("#sltWorkTimeTo option:selected").val(); //์ข…๋ฃŒ์‹œ๊ฐ„
	
	if (isExist(workTimeFrom) && isExist(workTimeTo)) {
		$("#txtReal_WorkTime").val(GetTimeDiff(workTimeFrom, workTimeTo));
	} else {
		$("#txtReal_WorkTime").val("0");
	}
	//alert(GetTimeDiff("2300", "400")); //5์‹œ๊ฐ„ ๋ฐ˜ํ™˜
	//alert(GetTimeDiff("2300", "400", "mm")); //300๋ถ„ ๋ฐ˜ํ™˜
}