Created
August 7, 2013 22:38
-
-
Save danielef/6179535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
padding: 5px; | |
width: 90%; | |
} | |
#n, #m { | |
width: 40% | |
} | |
div { | |
padding: 5px; | |
width: 100%; | |
} | |
button { | |
width: 90%; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Problema 1</title> | |
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script> | |
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> | |
</head> | |
<body> | |
<div> | |
<p><label>inicio: <input type="text" id="n" value="08/06/2013"/></label></p> | |
<p><label>final: <input type="text" id="m" value="08/20/2013"/></label></p> | |
</div> | |
<div> | |
<button id="e">dias habiles</button> | |
</div> | |
<div> | |
<input type="text" id="a"/> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$("#n, #m").datepicker(); | |
$("#e").click(function(){ | |
$("#a").val(diasHabiles(new Date($("#n").val()),new Date($("#m").val()))); | |
}); | |
}); | |
function diasHabiles(from, to){ | |
if (from < to) { | |
dFrom = from.getDay(); | |
dTo = to.getDay(); | |
nDays = (to.getTime()-from.getTime()) / (60*60*24*1000) + 1; | |
fWeeks = Math.floor(nDays/7); | |
rDays = nDays%7; | |
if (dFrom <= dTo) { | |
if (dFrom <= 6 && 6 <= dTo) rDays--; | |
if (dFrom <= 0 && 0 <= dTo) rDays--; | |
} else { | |
if (dFrom === 0) { | |
rDays--; | |
if (dTo == 6) { | |
rDays--; | |
} | |
} else { | |
rDays -= 2; | |
} | |
} | |
a = fWeeks * 5; | |
if (rDays > 0) a += rDays; | |
return a; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment