/*global window, document, BytePushers*/
/*jslint unparam: true*/
(function (window, document, BytePushers) {
'use strict';
BytePushers = BytePushers || {};
BytePushers.DateUtility = BytePushers.namespace("software.bytepushers.utils.DateUtility");
BytePushers.DateUtility.date_sort_asc = function (date1, date2) {
// This is a comparison function that will result in dates being sorted in
// ASCENDING order. As you can see, JavaScript's native comparison operators
// can be used to compare dates. This was news to me.
Iif (date1 > date2) {
return 1;
}
Eif (date1 < date2) {
return -1;
}
return 0;
};
BytePushers.DateUtility.date_sort_desc = function (date1, date2) {
// This is a comparison function that will result in dates being sorted in
// DESCENDING order.
if (date1 > date2) {
return -1;
}
if (date1 < date2) {
return 1;
}
return 0;
};
/*checks if string passed in is valid MM/DD/YYYY date*/
BytePushers.DateUtility.isDateString_MMDDYYYY = function (dateString) {
/*credit: https://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript/6178341#6178341*/
/* First check for the pattern */
if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString)) { return false; }
/* Parse the date parts to integers */
var parts = dateString.split("/"),
day = parseInt(parts[1], 10),
month = parseInt(parts[0], 10),
year = parseInt(parts[2], 10),
monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
/* Check the ranges of month and year */
Iif (year < 1000 || year > 3000 || month === 0 || month > 12) { return false; }
/* Adjust for leap years */
Eif (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) { monthLength[1] = 29; }
/* Check the range of the day */
return day > 0 && day <= monthLength[month - 1];
};
}(window, document, BytePushers));
/*jslint unparam: false*/
|