I have here a javascript function in some view. The controller send to this view two dates(start_date & end_date). All i want to do in my function is to check a condition before doing some action.
<script>
$(function() {
var start_date = <% @date1 %>
var end_date = <% @date2 %>
unavailableDates = [];
$.ajax({
url: '/preload',
data: {'voiture_id': <%= @voiture.id %>},
dataType: 'json',
success: function(data) {
$.each(data, function(arrID, arrValue) {
for(var d = new Date(arrValue.start_date); d <= new Date(arrValue.end_date); d.setDate(d.getDate() + 1)) {
// CHECK that !(d >= start_date && d <= end_date) before push action
unavailableDates.push($.datepicker.formatDate('d-m-yy', d));
}
});
}
</script>
. Types of start_date & end_date
t.datetime "start_date"
t.datetime "end_date"
I hope that it was clear, thanks !
SOLUTION:
var startDate = new Date(<%= @date1.to_i*1000 %>);
var endDate = new Date(<%= @date2.to_i*1000 %>);
.
if (!(d.getDate()>=startDate.getDate() && d.getDate()<=endDate.getDate()))
{
unavailableDates.push($.datepicker.formatDate('d-m-yy', d));
}