@progress/kendo-date-math
Version:
Kendo UI typescript package exporting functions for Date manipulations
31 lines (30 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dayOfWeek = void 0;
var direction_enum_1 = require("./direction.enum");
var adjust_dst_1 = require("./adjust-dst");
var clone_date_1 = require("./clone-date");
/**
* @hidden
*
* A function which returns the next or previous date for a specific week day. For example, `Day.Monday`.
*
* @param date - The date to calculate from.
* @param weekDay - The `Day` enum specifying the desired week day.
* @param direction - The `Direction` enum specifying the calculation direction.
* @returns - A `Date` instance.
*
* @example
* ```ts-no-run
* dayOfWeek(new Date(2016, 0, 1), Day.Wednesday, Direction.Forward); // 2016-01-06, Wednesday
* dayOfWeek(new Date(2016, 0, 1), Day.Wednesday, Direction.Backward); // 2015-12-30, Wednesday
* ```
*/
var dayOfWeek = function (date, weekDay, direction) {
if (direction === void 0) { direction = direction_enum_1.Direction.Forward; }
var newDate = (0, clone_date_1.cloneDate)(date);
var newDay = ((weekDay - newDate.getDay()) + (7 * direction)) % 7;
newDate.setDate(newDate.getDate() + newDay);
return (0, adjust_dst_1.adjustDST)(newDate, date.getHours());
};
exports.dayOfWeek = dayOfWeek;