UNPKG

ag-charts-community

Version:

Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue

32 lines 1.28 kB
import { durationMinute, durationWeek } from "./duration"; import { CountableTimeInterval } from "./interval"; // Set date to n-th day of the week. function weekday(n) { // Sets the `date` to the start of the `n`-th day of the current week. // n == 0 is Sunday. function floor(date) { // 1..31 1..7 date.setDate(date.getDate() - (date.getDay() + 7 - n) % 7); date.setHours(0, 0, 0, 0); // h, m, s, ms } // Offset the date by the given number of weeks. function offset(date, weeks) { date.setDate(date.getDate() + weeks * 7); } // Count the number of weeks between the start and end dates. function count(start, end) { var msDelta = end.getTime() - start.getTime(); var tzMinuteDelta = end.getTimezoneOffset() - start.getTimezoneOffset(); return (msDelta - tzMinuteDelta * durationMinute) / durationWeek; } return new CountableTimeInterval(floor, offset, count); } export var sunday = weekday(0); export var monday = weekday(1); export var tuesday = weekday(2); export var wednesday = weekday(3); export var thursday = weekday(4); export var friday = weekday(5); export var saturday = weekday(6); export default sunday; //# sourceMappingURL=week.js.map