define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function _validateDateTimeComponent(unitName, min, max) {
return function (dataType, value) {
if (!Number.isInteger(value)) {
throw new Error("Non-integral " + unitName + " supplied to " + dataType + ".");
}
if (value > max) {
throw new Error("Encountered " + unitName + " greater than " + max + " in " + dataType + ".");
}
if (value < min) {
throw new Error("Encountered " + unitName + " less than " + min + " in " + dataType + ".");
}
};
}
exports._validateDateTimeComponent = _validateDateTimeComponent;
function _isGeneralCharacter(characterCode) {
return (characterCode <= 0x7F);
}
exports._isGeneralCharacter = _isGeneralCharacter;
function _isGraphicCharacter(characterCode) {
return (characterCode >= 0x20 && characterCode <= 0x7E);
}
exports._isGraphicCharacter = _isGraphicCharacter;
function _isPrintableCharacter(characterCode) {
return ((characterCode >= 0x27 && characterCode <= 0x39 && characterCode !== 0x2A)
|| (characterCode >= 0x41 && characterCode <= 0x5A)
|| (characterCode >= 0x61 && characterCode <= 0x7A)
|| (characterCode === 0x20)
|| (characterCode === 0x3A)
|| (characterCode === 0x3D)
|| (characterCode === 0x3F));
}
exports._isPrintableCharacter = _isPrintableCharacter;
function _validateDate(dataType, year, month, date) {
if (!Number.isSafeInteger(year)) {
throw new Error("Invalid year in " + dataType);
}
if (!Number.isSafeInteger(month)) {
throw new Error("Invalid month in " + dataType);
}
if (!Number.isSafeInteger(date) || (date < 1)) {
throw new Error("Invalid day in " + dataType);
}
switch (month) {
case 0:
case 2:
case 4:
case 6:
case 7:
case 9:
case 11: {
if (date > 31) {
throw new Error("Day > 31 encountered in " + dataType + " with 31-day month.");
}
break;
}
case 3:
case 5:
case 8:
case 10: {
if (date > 30) {
throw new Error("Day > 31 encountered in " + dataType + " with 30-day month.");
}
break;
}
case 1: {
var isLeapYear = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
if (isLeapYear) {
if (date > 29) {
throw new Error("Day > 29 encountered in " + dataType + " with month of February in leap year.");
}
}
else if (date > 28) {
throw new Error("Day > 28 encountered in " + dataType + " with month of February and non leap year.");
}
break;
}
default:
throw new Error("Invalid month in " + dataType);
}
}
exports._validateDate = _validateDate;
function _validateTime(dataType, hours, minutes, seconds) {
if (!Number.isSafeInteger(hours)) {
throw new Error("Invalid hours in " + dataType);
}
if (!Number.isSafeInteger(minutes)) {
throw new Error("Invalid minutes in " + dataType);
}
if (!Number.isSafeInteger(seconds) || (seconds < 0)) {
throw new Error("Invalid seconds in " + dataType);
}
if (hours > 23) {
throw new Error("Hours > 23 encountered in " + dataType + ".");
}
if (minutes > 59) {
throw new Error("Minutes > 60 encountered in " + dataType + ".");
}
if (seconds > 59) {
throw new Error("Seconds > 60 encountered in " + dataType + ".");
}
}
exports._validateTime = _validateTime;
function _validateDateTime(dataType, year, month, date, hours, minutes, seconds) {
_validateDate(dataType, year, month, date);
_validateTime(dataType, hours, minutes, seconds);
}
exports._validateDateTime = _validateDateTime;
function isNumericString(characterCode) {
return ((characterCode >= 0x30 && characterCode <= 0x39) || characterCode === 0x20);
}
exports.isNumericString = isNumericString;
});
|