md2
Version:
Angular2 based Material Design components, directives and services are Accordion, Autocomplete, Chips(Tags), Collapse, Colorpicker, Data Table, Datepicker, Dialog(Modal), Menu, Multiselect, Select, Tabs, Tags(Chips), Toast and Tooltip.
54 lines • 2.08 kB
JavaScript
/** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */
var DateAdapter = (function () {
function DateAdapter() {
}
/**
* Sets the locale used for all dates.
* @param locale The new locale.
*/
DateAdapter.prototype.setLocale = function (locale) {
this.locale = locale;
};
/**
* Compares two dates.
* @param first The first date to compare.
* @param second The second date to compare.
* @returns 0 if the dates are equal, a number less than 0 if the first date is earlier,
* a number greater than 0 if the first date is later.
*/
DateAdapter.prototype.compareDate = function (first, second) {
return this.getYear(first) - this.getYear(second) ||
this.getMonth(first) - this.getMonth(second) ||
this.getDate(first) - this.getDate(second);
};
/**
* Checks if two dates are equal.
* @param first The first date to check.
* @param second The second date to check.
* @returns {boolean} Whether the two dates are equal.
* Null dates are considered equal to other null dates.
*/
DateAdapter.prototype.sameDate = function (first, second) {
return first && second ? !this.compareDate(first, second) : first == second;
};
/**
* Clamp the given date between min and max dates.
* @param date The date to clamp.
* @param min The minimum value to allow. If null or omitted no min is enforced.
* @param max The maximum value to allow. If null or omitted no max is enforced.
* @returns `min` if `date` is less than `min`, `max` if date is greater than `max`,
* otherwise `date`.
*/
DateAdapter.prototype.clampDate = function (date, min, max) {
if (min && this.compareDate(date, min) < 0) {
return min;
}
if (max && this.compareDate(date, max) > 0) {
return max;
}
return date;
};
return DateAdapter;
}());
export { DateAdapter };
//# sourceMappingURL=date-adapter.js.map