Reputation: 467
I am creating a calendar and need to be able to select (to show/hide) div.event
who's data-dates
(which may be string or array, depending on number of days the event appears in) by determining if any of the unix timestamp dates stored there are such that they fall between the unix timestamps which represent the start and end of the currently chosen month. So for example:
It is April 2013, so I wish to see only events that occur in April (1364774400
[April 1st, midnight] and 1367366399
[April 30th, 23:59:59]).
I have many event
divs. They look something like this:
<div class="event" data-dates="[1367539200, 1367625600]">...</div>
<div class="event" data-dates="[1364947200]">...</div>
Let's assume one or more of those have timestamps that fall sometime in April 2013. How do I select them?
Upvotes: 2
Views: 2615
Reputation: 193261
Try to make use of filter
:
var rangeStart = 1364774400,
rangeEnd = 1367366399;
$('.event').filter(function() {
return $(this).data('dates').some(function(date) {
return date >= rangeStart && date < rangeEnd;
});
})
.addClass('active');
Note. some method is not available in IE<9 so you can shim it or use simple for
loop to check if data array contains any value between start
and end
. Demo 2.
Upvotes: 5