javascript - How to compare dates to see where adjacent times meet? -
i have dates formatted in next way:
[ [ tue jun 17 2014 09:00:00 gmt-0400 (edt), tue jun 17 2014 10:00:00 gmt-0400 (edt) ] ] [ [ thu jun 19 2014 09:30:00 gmt-0400 (edt), thu jun 19 2014 11:30:00 gmt-0400 (edt) ] ] [ [ tue jun 17 2014 10:00:00 gmt-0400 (edt), tue jun 17 2014 11:00:00 gmt-0400 (edt) ] ]
these dates "sessions", , need see sessions adjacent each other. example, in specific case, first array of dates has end time of 10am while lastly array of dates has start time 10am. how can computationally find situation?
the 1 approach have first sort array sets earliest time to latest time, , compare each of start/end date pairs see if same, can't seem through. ideas welcome!
turn strings unix timestamps date.parse()
(if these date
objects, utilize .gettime()
method) , order sessions array.prototype.sort()
. here's illustration sessions ordered start time:
var sessions = [ ["tue jun 17 2014 09:00:00 gmt-0400 (edt)", "tue jun 17 2014 10:00:00 gmt-0400 (edt)"], ["thu jun 19 2014 09:30:00 gmt-0400 (edt)", "thu jun 19 2014 11:30:00 gmt-0400 (edt)"], ["tue jun 17 2014 10:00:00 gmt-0400 (edt)", "tue jun 17 2014 11:00:00 gmt-0400 (edt)"] ]; (var = 0; < sessions.length; i++) { sessions[i].starttime= date.parse(sessions[i][0]); } sessions.sort(function(a, b) { homecoming a.starttime-b.starttime; });
javascript sorting date date-sorting
No comments:
Post a Comment