Created
March 29, 2013 11:36
-
-
Save schovi/5270342 to your computer and use it in GitHub Desktop.
This file contains 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
// Generator | |
function timeDataGenerator(interval) { | |
var times = []; | |
for (x = 0; x < 24; x++) { | |
if (x.toString().length === 1) { var hours = "0"+x; } | |
else { var hours = x; } | |
for (y = 0; y < 60; y+=interval) { | |
if (y.toString().length === 1) { var minutes = "0"+y; } | |
else { var minutes = y; } | |
times.push(hours+":"+minutes); | |
} | |
} | |
return times; | |
} | |
// Matcher | |
var timeData = timeDataGenerator(5) | |
function matchTime(req) { | |
var matcher = new RegExp( "^0?" + req, "i" ), | |
result = $.grep(timeData, function(item,index){ | |
return matcher.test(item); | |
}); | |
return result; | |
} | |
matchTime("10:") -> ["10:00", "10:05",....., "10:55"] | |
matchTime("10:3") -> ["10:30", "10:35"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment