first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,32 @@
import { IDateGridStrings, IDateFormatting, ICalendarStrings } from './dateFormatting.types';
/**
* Format date to a day string representation
* @param date - input date to format
*/
export declare const formatDay: (date: Date) => string;
/**
* Format date to a month-day-year string
* @param date - input date to format
* @param strings - localized strings
*/
export declare const formatMonthDayYear: (date: Date, strings: IDateGridStrings) => string;
/**
* Format date to a month-year string
* @param date - input date to format
* @param strings - localized strings
*/
export declare const formatMonthYear: (date: Date, strings: IDateGridStrings) => string;
/**
* Format date to a month string
* @param date - input date to format
* @param strings - localized strings
*/
export declare const formatMonth: (date: Date, strings: IDateGridStrings) => string;
/**
* Format date to a year string representation
* @param date - input date to format
*/
export declare const formatYear: (date: Date) => string;
export declare const DEFAULT_DATE_GRID_STRINGS: IDateGridStrings;
export declare const DEFAULT_DATE_FORMATTING: IDateFormatting;
export declare const DEFAULT_CALENDAR_STRINGS: ICalendarStrings;
@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_CALENDAR_STRINGS = exports.DEFAULT_DATE_FORMATTING = exports.DEFAULT_DATE_GRID_STRINGS = exports.formatYear = exports.formatMonth = exports.formatMonthYear = exports.formatMonthDayYear = exports.formatDay = void 0;
var tslib_1 = require("tslib");
/**
* Format date to a day string representation
* @param date - input date to format
*/
var formatDay = function (date) { return date.getDate().toString(); };
exports.formatDay = formatDay;
/**
* Format date to a month-day-year string
* @param date - input date to format
* @param strings - localized strings
*/
var formatMonthDayYear = function (date, strings) {
return strings.months[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();
};
exports.formatMonthDayYear = formatMonthDayYear;
/**
* Format date to a month-year string
* @param date - input date to format
* @param strings - localized strings
*/
var formatMonthYear = function (date, strings) {
return strings.months[date.getMonth()] + ' ' + date.getFullYear();
};
exports.formatMonthYear = formatMonthYear;
/**
* Format date to a month string
* @param date - input date to format
* @param strings - localized strings
*/
var formatMonth = function (date, strings) { return strings.months[date.getMonth()]; };
exports.formatMonth = formatMonth;
/**
* Format date to a year string representation
* @param date - input date to format
*/
var formatYear = function (date) { return date.getFullYear().toString(); };
exports.formatYear = formatYear;
exports.DEFAULT_DATE_GRID_STRINGS = {
months: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
};
exports.DEFAULT_DATE_FORMATTING = {
formatDay: exports.formatDay,
formatMonth: exports.formatMonth,
formatYear: exports.formatYear,
formatMonthDayYear: exports.formatMonthDayYear,
formatMonthYear: exports.formatMonthYear,
};
exports.DEFAULT_CALENDAR_STRINGS = tslib_1.__assign(tslib_1.__assign({}, exports.DEFAULT_DATE_GRID_STRINGS), { goToToday: 'Go to today', weekNumberFormatString: 'Week number {0}', prevMonthAriaLabel: 'Previous month', nextMonthAriaLabel: 'Next month', prevYearAriaLabel: 'Previous year', nextYearAriaLabel: 'Next year', prevYearRangeAriaLabel: 'Previous year range', nextYearRangeAriaLabel: 'Next year range', closeButtonAriaLabel: 'Close', selectedDateFormatString: 'Selected date {0}', todayDateFormatString: "Today's date {0}", monthPickerHeaderAriaLabel: '{0}, change year', yearPickerHeaderAriaLabel: '{0}, change month', dayMarkedAriaLabel: 'marked' });
//# sourceMappingURL=dateFormatting.defaults.js.map
@@ -0,0 +1 @@
{"version":3,"file":"dateFormatting.defaults.js","sourceRoot":"../src/","sources":["dateFormatting/dateFormatting.defaults.ts"],"names":[],"mappings":";;;;AAEA;;;GAGG;AACI,IAAM,SAAS,GAAG,UAAC,IAAU,IAAa,OAAA,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAzB,CAAyB,CAAC;AAA9D,QAAA,SAAS,aAAqD;AAE3E;;;;GAIG;AACI,IAAM,kBAAkB,GAAG,UAAC,IAAU,EAAE,OAAyB;IACtE,OAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;AAAlF,CAAkF,CAAC;AADxE,QAAA,kBAAkB,sBACsD;AAErF;;;;GAIG;AACI,IAAM,eAAe,GAAG,UAAC,IAAU,EAAE,OAAyB;IACnE,OAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE;AAA1D,CAA0D,CAAC;AADhD,QAAA,eAAe,mBACiC;AAE7D;;;;GAIG;AACI,IAAM,WAAW,GAAG,UAAC,IAAU,EAAE,OAAyB,IAAa,OAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAA/B,CAA+B,CAAC;AAAjG,QAAA,WAAW,eAAsF;AAE9G;;;GAGG;AACI,IAAM,UAAU,GAAG,UAAC,IAAU,IAAa,OAAA,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,EAA7B,CAA6B,CAAC;AAAnE,QAAA,UAAU,cAAyD;AAEnE,QAAA,yBAAyB,GAAqB;IACzD,MAAM,EAAE;QACN,SAAS;QACT,UAAU;QACV,OAAO;QACP,OAAO;QACP,KAAK;QACL,MAAM;QACN,MAAM;QACN,QAAQ;QACR,WAAW;QACX,SAAS;QACT,UAAU;QACV,UAAU;KACX;IACD,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;IACjG,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC;IACpF,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CAC/C,CAAC;AAEW,QAAA,uBAAuB,GAAoB;IACtD,SAAS,mBAAA;IACT,WAAW,qBAAA;IACX,UAAU,oBAAA;IACV,kBAAkB,4BAAA;IAClB,eAAe,yBAAA;CAChB,CAAC;AAEW,QAAA,wBAAwB,yCAChC,iCAAyB,KAE5B,SAAS,EAAE,aAAa,EACxB,sBAAsB,EAAE,iBAAiB,EACzC,kBAAkB,EAAE,gBAAgB,EACpC,kBAAkB,EAAE,YAAY,EAChC,iBAAiB,EAAE,eAAe,EAClC,iBAAiB,EAAE,WAAW,EAC9B,sBAAsB,EAAE,qBAAqB,EAC7C,sBAAsB,EAAE,iBAAiB,EACzC,oBAAoB,EAAE,OAAO,EAC7B,wBAAwB,EAAE,mBAAmB,EAC7C,qBAAqB,EAAE,kBAAkB,EACzC,0BAA0B,EAAE,kBAAkB,EAC9C,yBAAyB,EAAE,mBAAmB,EAC9C,kBAAkB,EAAE,QAAQ,IAC5B","sourcesContent":["import { IDateGridStrings, IDateFormatting, ICalendarStrings } from './dateFormatting.types';\n\n/**\n * Format date to a day string representation\n * @param date - input date to format\n */\nexport const formatDay = (date: Date): string => date.getDate().toString();\n\n/**\n * Format date to a month-day-year string\n * @param date - input date to format\n * @param strings - localized strings\n */\nexport const formatMonthDayYear = (date: Date, strings: IDateGridStrings): string =>\n strings.months[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();\n\n/**\n * Format date to a month-year string\n * @param date - input date to format\n * @param strings - localized strings\n */\nexport const formatMonthYear = (date: Date, strings: IDateGridStrings): string =>\n strings.months[date.getMonth()] + ' ' + date.getFullYear();\n\n/**\n * Format date to a month string\n * @param date - input date to format\n * @param strings - localized strings\n */\nexport const formatMonth = (date: Date, strings: IDateGridStrings): string => strings.months[date.getMonth()];\n\n/**\n * Format date to a year string representation\n * @param date - input date to format\n */\nexport const formatYear = (date: Date): string => date.getFullYear().toString();\n\nexport const DEFAULT_DATE_GRID_STRINGS: IDateGridStrings = {\n months: [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n ],\n shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],\n};\n\nexport const DEFAULT_DATE_FORMATTING: IDateFormatting = {\n formatDay,\n formatMonth,\n formatYear,\n formatMonthDayYear,\n formatMonthYear,\n};\n\nexport const DEFAULT_CALENDAR_STRINGS: ICalendarStrings = {\n ...DEFAULT_DATE_GRID_STRINGS,\n\n goToToday: 'Go to today',\n weekNumberFormatString: 'Week number {0}',\n prevMonthAriaLabel: 'Previous month',\n nextMonthAriaLabel: 'Next month',\n prevYearAriaLabel: 'Previous year',\n nextYearAriaLabel: 'Next year',\n prevYearRangeAriaLabel: 'Previous year range',\n nextYearRangeAriaLabel: 'Next year range',\n closeButtonAriaLabel: 'Close',\n selectedDateFormatString: 'Selected date {0}',\n todayDateFormatString: \"Today's date {0}\",\n monthPickerHeaderAriaLabel: '{0}, change year',\n yearPickerHeaderAriaLabel: '{0}, change month',\n dayMarkedAriaLabel: 'marked',\n};\n"]}
@@ -0,0 +1,114 @@
/**
* {@docCategory DateTimeUtilities}
*/
export interface IDateGridStrings {
/**
* An array of strings for the full names of months.
* The array is 0-based, so months[0] should be the full name of January.
*/
months: string[];
/**
* An array of strings for the short names of months.
* The array is 0-based, so shortMonths[0] should be the short name of January.
*/
shortMonths: string[];
/**
* An array of strings for the full names of days of the week.
* The array is 0-based, so days[0] should be the full name of Sunday.
*/
days: string[];
/**
* An array of strings for the initials of the days of the week.
* The array is 0-based, so days[0] should be the initial of Sunday.
*/
shortDays: string[];
}
/**
* {@docCategory DateTimeUtilities}
*/
export interface IDateFormatting {
/**
* Get a localized string for a day.
*/
formatDay: (date: Date) => string;
/**
* Get a localized string for a month.
*/
formatMonth: (date: Date, strings: IDateGridStrings) => string;
/**
* Get a localized string for a year.
*/
formatYear: (date: Date) => string;
/**
* Get a localized string for a month, day, and year.
*/
formatMonthDayYear: (date: Date, strings: IDateGridStrings) => string;
/**
* Get a localized string for a month and year.
*/
formatMonthYear: (date: Date, strings: IDateGridStrings) => string;
}
/**
* {@docCategory DateTimeUtilities}
*/
export interface ICalendarStrings extends IDateGridStrings {
/**
* String to render for button to direct the user to today's date.
*/
goToToday: string;
/**
* Aria-label for the "previous month" button in day picker.
*/
prevMonthAriaLabel?: string;
/**
* Aria-label for the "next month" button in day picker.
*/
nextMonthAriaLabel?: string;
/**
* Aria-label for the "previous year" button in month picker.
*/
prevYearAriaLabel?: string;
/**
* Aria-label for the "next year" button in month picker.
*/
nextYearAriaLabel?: string;
/**
* Aria-label for the "previous year range" button in year picker.
*/
prevYearRangeAriaLabel?: string;
/**
* Aria-label for the "next year range" button in year picker.
*/
nextYearRangeAriaLabel?: string;
/**
* Aria-label format string for the header button in the month picker. Should have 1 string param, e.g. "`{0}`,
* select to change the year". This aria-label will only be applied if the year picker is enabled; otherwise
* the label will default to the header string, e.g. "2019".
*/
monthPickerHeaderAriaLabel?: string;
/**
* Aria-label format string for the header button in the year picker.
* Should have 1 string param, e.g. "`{0}`, select to change the month"
*/
yearPickerHeaderAriaLabel?: string;
/**
* Aria-label for the "close" button.
*/
closeButtonAriaLabel?: string;
/**
* Aria-label format string for the week number header. Should have 1 string param, e.g. "week number `{0}`"
*/
weekNumberFormatString?: string;
/**
* Aria-label format string for the currently selected date. Should have 1 string param, e.g. "Selected date `{0}`"
*/
selectedDateFormatString?: string;
/**
* Aria-label format string for today's date. Should have 1 string param, e.g. "Today's date `{0}`"
*/
todayDateFormatString?: string;
/**
* Aria-label for when a date is marked
*/
dayMarkedAriaLabel?: string;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=dateFormatting.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"dateFormatting.types.js","sourceRoot":"../src/","sources":["dateFormatting/dateFormatting.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * {@docCategory DateTimeUtilities}\n */\nexport interface IDateGridStrings {\n /**\n * An array of strings for the full names of months.\n * The array is 0-based, so months[0] should be the full name of January.\n */\n months: string[];\n\n /**\n * An array of strings for the short names of months.\n * The array is 0-based, so shortMonths[0] should be the short name of January.\n */\n shortMonths: string[];\n\n /**\n * An array of strings for the full names of days of the week.\n * The array is 0-based, so days[0] should be the full name of Sunday.\n */\n days: string[];\n\n /**\n * An array of strings for the initials of the days of the week.\n * The array is 0-based, so days[0] should be the initial of Sunday.\n */\n shortDays: string[];\n}\n\n/**\n * {@docCategory DateTimeUtilities}\n */\nexport interface IDateFormatting {\n /**\n * Get a localized string for a day.\n */\n formatDay: (date: Date) => string;\n\n /**\n * Get a localized string for a month.\n */\n formatMonth: (date: Date, strings: IDateGridStrings) => string;\n\n /**\n * Get a localized string for a year.\n */\n formatYear: (date: Date) => string;\n\n /**\n * Get a localized string for a month, day, and year.\n */\n formatMonthDayYear: (date: Date, strings: IDateGridStrings) => string;\n\n /**\n * Get a localized string for a month and year.\n */\n formatMonthYear: (date: Date, strings: IDateGridStrings) => string;\n}\n\n/**\n * {@docCategory DateTimeUtilities}\n */\nexport interface ICalendarStrings extends IDateGridStrings {\n /**\n * String to render for button to direct the user to today's date.\n */\n goToToday: string;\n\n /**\n * Aria-label for the \"previous month\" button in day picker.\n */\n prevMonthAriaLabel?: string;\n\n /**\n * Aria-label for the \"next month\" button in day picker.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Aria-label for the \"previous year\" button in month picker.\n */\n prevYearAriaLabel?: string;\n\n /**\n * Aria-label for the \"next year\" button in month picker.\n */\n nextYearAriaLabel?: string;\n\n /**\n * Aria-label for the \"previous year range\" button in year picker.\n */\n prevYearRangeAriaLabel?: string;\n\n /**\n * Aria-label for the \"next year range\" button in year picker.\n */\n nextYearRangeAriaLabel?: string;\n\n /**\n * Aria-label format string for the header button in the month picker. Should have 1 string param, e.g. \"`{0}`,\n * select to change the year\". This aria-label will only be applied if the year picker is enabled; otherwise\n * the label will default to the header string, e.g. \"2019\".\n */\n monthPickerHeaderAriaLabel?: string;\n\n /**\n * Aria-label format string for the header button in the year picker.\n * Should have 1 string param, e.g. \"`{0}`, select to change the month\"\n */\n yearPickerHeaderAriaLabel?: string;\n\n /**\n * Aria-label for the \"close\" button.\n */\n closeButtonAriaLabel?: string;\n\n /**\n * Aria-label format string for the week number header. Should have 1 string param, e.g. \"week number `{0}`\"\n */\n weekNumberFormatString?: string;\n\n /**\n * Aria-label format string for the currently selected date. Should have 1 string param, e.g. \"Selected date `{0}`\"\n */\n selectedDateFormatString?: string;\n\n /**\n * Aria-label format string for today's date. Should have 1 string param, e.g. \"Today's date `{0}`\"\n */\n todayDateFormatString?: string;\n\n /**\n * Aria-label for when a date is marked\n */\n dayMarkedAriaLabel?: string;\n}\n"]}
@@ -0,0 +1,2 @@
export * from './dateFormatting.types';
export * from './dateFormatting.defaults';
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./dateFormatting.types"), exports);
tslib_1.__exportStar(require("./dateFormatting.defaults"), exports);
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["dateFormatting/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC;AACvC,oEAA0C","sourcesContent":["export * from './dateFormatting.types';\nexport * from './dateFormatting.defaults';\n"]}
@@ -0,0 +1,98 @@
import { DayOfWeek, DateRangeType, FirstWeekOfYear } from '../dateValues/dateValues';
export interface IDay {
/** `Date.toString()` value of current date */
key: string;
/** `Date.getDate()` value of current date */
date: string;
/** `Date` object of current date */
originalDate: Date;
/** Is current date is in the same month as "today" date */
isInMonth: boolean;
/** Is current date is "today" date */
isToday: boolean;
/** Is current date is selected */
isSelected: boolean;
/** Is current date within restriction boundaries */
isInBounds: boolean;
/** Is current date marked */
isMarked: boolean;
}
export interface IAvailableDateOptions extends IRestrictedDatesOptions {
/** Date from which we start the search */
initialDate: Date;
/** Ideal available date */
targetDate: Date;
/** Direction of search (`1` - search in future / `-1` search in past) */
direction: number;
}
/**
* {@docCategory DateTimeUtilities}
*/
export interface IRestrictedDatesOptions {
/**
* If set the Calendar will not allow navigation to or selection of a date earlier than this value.
*/
minDate?: Date;
/**
* If set the Calendar will not allow navigation to or selection of a date later than this value.
*/
maxDate?: Date;
/**
* If set the Calendar will not allow selection of dates in this array.
*/
restrictedDates?: Date[];
}
/**
* {@docCategory DateTimeUtilities}
*/
export interface IDayGridOptions extends IRestrictedDatesOptions {
/**
* The first day of the week for your locale.
*/
firstDayOfWeek: DayOfWeek;
/**
* Defines when the first week of the year should start, FirstWeekOfYear.FirstDay,
* FirstWeekOfYear.FirstFullWeek or FirstWeekOfYear.FirstFourDayWeek are the possible values
*/
firstWeekOfYear: FirstWeekOfYear;
/**
* The date range type indicating how many days should be selected as the user
* selects days
*/
dateRangeType: DateRangeType;
/**
* The number of days to select while dateRangeType === DateRangeType.Day. Used in order to have multi-day
* views.
*/
daysToSelectInDayView?: number;
/**
* Value of today. If unspecified, current time in client machine will be used.
*/
today?: Date;
/**
* Whether the calendar should show the week number (weeks 1 to 53) before each week row
*/
showWeekNumbers?: boolean;
/**
* The days that are selectable when `dateRangeType` is WorkWeek.
* If `dateRangeType` is not WorkWeek this property does nothing.
*/
workWeekDays?: DayOfWeek[];
/**
* Which days in the generated grid should be marked.
*/
markedDays?: Date[];
/**
* The currently selected date
*/
selectedDate: Date;
/**
* The currently navigated date
*/
navigatedDate: Date;
/**
* How many weeks to show by default. If not provided, will show enough weeks to display the current
* month, between 4 and 6 depending
*/
weeksToShow?: number;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=dateGrid.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"dateGrid.types.js","sourceRoot":"../src/","sources":["dateGrid/dateGrid.types.ts"],"names":[],"mappings":"","sourcesContent":["import { DayOfWeek, DateRangeType, FirstWeekOfYear } from '../dateValues/dateValues';\n\nexport interface IDay {\n /** `Date.toString()` value of current date */\n key: string;\n /** `Date.getDate()` value of current date */\n date: string;\n /** `Date` object of current date */\n originalDate: Date;\n /** Is current date is in the same month as \"today\" date */\n isInMonth: boolean;\n /** Is current date is \"today\" date */\n isToday: boolean;\n /** Is current date is selected */\n isSelected: boolean;\n /** Is current date within restriction boundaries */\n isInBounds: boolean;\n /** Is current date marked */\n isMarked: boolean;\n}\n\nexport interface IAvailableDateOptions extends IRestrictedDatesOptions {\n /** Date from which we start the search */\n initialDate: Date;\n /** Ideal available date */\n targetDate: Date;\n /** Direction of search (`1` - search in future / `-1` search in past) */\n direction: number;\n}\n\n/**\n * {@docCategory DateTimeUtilities}\n */\nexport interface IRestrictedDatesOptions {\n /**\n * If set the Calendar will not allow navigation to or selection of a date earlier than this value.\n */\n minDate?: Date;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a date later than this value.\n */\n maxDate?: Date;\n\n /**\n * If set the Calendar will not allow selection of dates in this array.\n */\n restrictedDates?: Date[];\n}\n\n/**\n * {@docCategory DateTimeUtilities}\n */\nexport interface IDayGridOptions extends IRestrictedDatesOptions {\n /**\n * The first day of the week for your locale.\n */\n firstDayOfWeek: DayOfWeek;\n\n /**\n * Defines when the first week of the year should start, FirstWeekOfYear.FirstDay,\n * FirstWeekOfYear.FirstFullWeek or FirstWeekOfYear.FirstFourDayWeek are the possible values\n */\n firstWeekOfYear: FirstWeekOfYear;\n\n /**\n * The date range type indicating how many days should be selected as the user\n * selects days\n */\n dateRangeType: DateRangeType;\n\n /**\n * The number of days to select while dateRangeType === DateRangeType.Day. Used in order to have multi-day\n * views.\n */\n daysToSelectInDayView?: number;\n\n /**\n * Value of today. If unspecified, current time in client machine will be used.\n */\n today?: Date;\n\n /**\n * Whether the calendar should show the week number (weeks 1 to 53) before each week row\n */\n showWeekNumbers?: boolean;\n\n /**\n * The days that are selectable when `dateRangeType` is WorkWeek.\n * If `dateRangeType` is not WorkWeek this property does nothing.\n */\n workWeekDays?: DayOfWeek[];\n\n /**\n * Which days in the generated grid should be marked.\n */\n markedDays?: Date[];\n\n /**\n * The currently selected date\n */\n selectedDate: Date;\n\n /**\n * The currently navigated date\n */\n navigatedDate: Date;\n\n /**\n * How many weeks to show by default. If not provided, will show enough weeks to display the current\n * month, between 4 and 6 depending\n */\n weeksToShow?: number;\n}\n"]}
@@ -0,0 +1,6 @@
import { IAvailableDateOptions } from './dateGrid.types';
/**
* Returns closest available date given the restriction `options`, or undefined otherwise
* @param options - list of search options
*/
export declare const findAvailableDate: (options: IAvailableDateOptions) => Date | undefined;
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAvailableDate = void 0;
var tslib_1 = require("tslib");
var isRestrictedDate_1 = require("./isRestrictedDate");
var isAfterMaxDate_1 = require("./isAfterMaxDate");
var isBeforeMinDate_1 = require("./isBeforeMinDate");
var dateMath_1 = require("../dateMath/dateMath");
/**
* Returns closest available date given the restriction `options`, or undefined otherwise
* @param options - list of search options
*/
var findAvailableDate = function (options) {
var targetDate = options.targetDate, initialDate = options.initialDate, direction = options.direction, restrictedDateOptions = tslib_1.__rest(options, ["targetDate", "initialDate", "direction"]);
var availableDate = targetDate;
// if the target date is available, return it immediately
if (!(0, isRestrictedDate_1.isRestrictedDate)(targetDate, restrictedDateOptions)) {
return targetDate;
}
while ((0, dateMath_1.compareDatePart)(initialDate, availableDate) !== 0 &&
(0, isRestrictedDate_1.isRestrictedDate)(availableDate, restrictedDateOptions) &&
!(0, isAfterMaxDate_1.isAfterMaxDate)(availableDate, restrictedDateOptions) &&
!(0, isBeforeMinDate_1.isBeforeMinDate)(availableDate, restrictedDateOptions)) {
availableDate = (0, dateMath_1.addDays)(availableDate, direction);
}
if ((0, dateMath_1.compareDatePart)(initialDate, availableDate) !== 0 && !(0, isRestrictedDate_1.isRestrictedDate)(availableDate, restrictedDateOptions)) {
return availableDate;
}
return undefined;
};
exports.findAvailableDate = findAvailableDate;
//# sourceMappingURL=findAvailableDate.js.map
@@ -0,0 +1 @@
{"version":3,"file":"findAvailableDate.js","sourceRoot":"../src/","sources":["dateGrid/findAvailableDate.ts"],"names":[],"mappings":";;;;AAEA,uDAAsD;AAEtD,mDAAkD;AAElD,qDAAoD;AACpD,iDAAgE;AAEhE;;;GAGG;AACI,IAAM,iBAAiB,GAAG,UAAC,OAA8B;IACtD,IAAA,UAAU,GAAuD,OAAO,WAA9D,EAAE,WAAW,GAA0C,OAAO,YAAjD,EAAE,SAAS,GAA+B,OAAO,UAAtC,EAAK,qBAAqB,kBAAK,OAAO,EAA1E,0CAAgE,CAAF,CAAa;IACjF,IAAI,aAAa,GAAG,UAAU,CAAC;IAC/B,yDAAyD;IACzD,IAAI,CAAC,IAAA,mCAAgB,EAAC,UAAU,EAAE,qBAAqB,CAAC,EAAE,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OACE,IAAA,0BAAe,EAAC,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC;QACjD,IAAA,mCAAgB,EAAC,aAAa,EAAE,qBAAqB,CAAC;QACtD,CAAC,IAAA,+BAAc,EAAC,aAAa,EAAE,qBAAqB,CAAC;QACrD,CAAC,IAAA,iCAAe,EAAC,aAAa,EAAE,qBAAqB,CAAC,EACtD,CAAC;QACD,aAAa,GAAG,IAAA,kBAAO,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,IAAA,0BAAe,EAAC,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,IAAA,mCAAgB,EAAC,aAAa,EAAE,qBAAqB,CAAC,EAAE,CAAC;QACjH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B","sourcesContent":["import { IAvailableDateOptions } from './dateGrid.types';\n\nimport { isRestrictedDate } from './isRestrictedDate';\n\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { compareDatePart, addDays } from '../dateMath/dateMath';\n\n/**\n * Returns closest available date given the restriction `options`, or undefined otherwise\n * @param options - list of search options\n */\nexport const findAvailableDate = (options: IAvailableDateOptions): Date | undefined => {\n const { targetDate, initialDate, direction, ...restrictedDateOptions } = options;\n let availableDate = targetDate;\n // if the target date is available, return it immediately\n if (!isRestrictedDate(targetDate, restrictedDateOptions)) {\n return targetDate;\n }\n\n while (\n compareDatePart(initialDate, availableDate) !== 0 &&\n isRestrictedDate(availableDate, restrictedDateOptions) &&\n !isAfterMaxDate(availableDate, restrictedDateOptions) &&\n !isBeforeMinDate(availableDate, restrictedDateOptions)\n ) {\n availableDate = addDays(availableDate, direction);\n }\n\n if (compareDatePart(initialDate, availableDate) !== 0 && !isRestrictedDate(availableDate, restrictedDateOptions)) {\n return availableDate;\n }\n\n return undefined;\n};\n"]}
@@ -0,0 +1,7 @@
/**
* Generates a list of dates, bounded by min and max dates
* @param dateRange - input date range
* @param minDate - min date to limit the range
* @param maxDate - max date to limit the range
*/
export declare const getBoundedDateRange: (dateRange: Date[], minDate?: Date, maxDate?: Date) => Date[];
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBoundedDateRange = void 0;
var tslib_1 = require("tslib");
var dateMath_1 = require("../dateMath/dateMath");
/**
* Generates a list of dates, bounded by min and max dates
* @param dateRange - input date range
* @param minDate - min date to limit the range
* @param maxDate - max date to limit the range
*/
var getBoundedDateRange = function (dateRange, minDate, maxDate) {
var boundedDateRange = tslib_1.__spreadArray([], dateRange, true);
if (minDate) {
boundedDateRange = boundedDateRange.filter(function (date) { return (0, dateMath_1.compareDatePart)(date, minDate) >= 0; });
}
if (maxDate) {
boundedDateRange = boundedDateRange.filter(function (date) { return (0, dateMath_1.compareDatePart)(date, maxDate) <= 0; });
}
return boundedDateRange;
};
exports.getBoundedDateRange = getBoundedDateRange;
//# sourceMappingURL=getBoundedDateRange.js.map
@@ -0,0 +1 @@
{"version":3,"file":"getBoundedDateRange.js","sourceRoot":"../src/","sources":["dateGrid/getBoundedDateRange.ts"],"names":[],"mappings":";;;;AAAA,iDAAuD;AAEvD;;;;;GAKG;AACI,IAAM,mBAAmB,GAAG,UAAC,SAAiB,EAAE,OAAc,EAAE,OAAc;IACnF,IAAI,gBAAgB,6BAAO,SAAS,OAAC,CAAC;IACtC,IAAI,OAAO,EAAE,CAAC;QACZ,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,UAAC,IAAU,IAAK,OAAA,IAAA,0BAAe,EAAC,IAAI,EAAE,OAAe,CAAC,IAAI,CAAC,EAA3C,CAA2C,CAAC,CAAC;IAC1G,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,UAAC,IAAU,IAAK,OAAA,IAAA,0BAAe,EAAC,IAAI,EAAE,OAAe,CAAC,IAAI,CAAC,EAA3C,CAA2C,CAAC,CAAC;IAC1G,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AATW,QAAA,mBAAmB,uBAS9B","sourcesContent":["import { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Generates a list of dates, bounded by min and max dates\n * @param dateRange - input date range\n * @param minDate - min date to limit the range\n * @param maxDate - max date to limit the range\n */\nexport const getBoundedDateRange = (dateRange: Date[], minDate?: Date, maxDate?: Date): Date[] => {\n let boundedDateRange = [...dateRange];\n if (minDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, minDate as Date) >= 0);\n }\n if (maxDate) {\n boundedDateRange = boundedDateRange.filter((date: Date) => compareDatePart(date, maxDate as Date) <= 0);\n }\n return boundedDateRange;\n};\n"]}
@@ -0,0 +1,9 @@
import { DateRangeType, DayOfWeek } from '../dateValues/dateValues';
/**
* Return corrected date range type, given `dateRangeType` and list of working days.
* For non-contiguous working days and working week range type, returns general week range type.
* For other cases returns input date range type.
* @param dateRangeType - input type of range
* @param workWeekDays - list of working days in a week
*/
export declare const getDateRangeTypeToUse: (dateRangeType: DateRangeType, workWeekDays: DayOfWeek[] | undefined, firstDayOfWeek: DayOfWeek) => DateRangeType;
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDateRangeTypeToUse = void 0;
var dateValues_1 = require("../dateValues/dateValues");
var isContiguous_1 = require("./isContiguous");
/**
* Return corrected date range type, given `dateRangeType` and list of working days.
* For non-contiguous working days and working week range type, returns general week range type.
* For other cases returns input date range type.
* @param dateRangeType - input type of range
* @param workWeekDays - list of working days in a week
*/
var getDateRangeTypeToUse = function (dateRangeType, workWeekDays, firstDayOfWeek) {
if (workWeekDays && dateRangeType === dateValues_1.DateRangeType.WorkWeek) {
if (!(0, isContiguous_1.isContiguous)(workWeekDays, true, firstDayOfWeek) || workWeekDays.length === 0) {
return dateValues_1.DateRangeType.Week;
}
}
return dateRangeType;
};
exports.getDateRangeTypeToUse = getDateRangeTypeToUse;
//# sourceMappingURL=getDateRangeTypeToUse.js.map
@@ -0,0 +1 @@
{"version":3,"file":"getDateRangeTypeToUse.js","sourceRoot":"../src/","sources":["dateGrid/getDateRangeTypeToUse.ts"],"names":[],"mappings":";;;AAAA,uDAAoE;AACpE,+CAA8C;AAC9C;;;;;;GAMG;AACI,IAAM,qBAAqB,GAAG,UACnC,aAA4B,EAC5B,YAAqC,EACrC,cAAyB;IAEzB,IAAI,YAAY,IAAI,aAAa,KAAK,0BAAa,CAAC,QAAQ,EAAE,CAAC;QAC7D,IAAI,CAAC,IAAA,2BAAY,EAAC,YAAY,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnF,OAAO,0BAAa,CAAC,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAZW,QAAA,qBAAqB,yBAYhC","sourcesContent":["import { DateRangeType, DayOfWeek } from '../dateValues/dateValues';\nimport { isContiguous } from './isContiguous';\n/**\n * Return corrected date range type, given `dateRangeType` and list of working days.\n * For non-contiguous working days and working week range type, returns general week range type.\n * For other cases returns input date range type.\n * @param dateRangeType - input type of range\n * @param workWeekDays - list of working days in a week\n */\nexport const getDateRangeTypeToUse = (\n dateRangeType: DateRangeType,\n workWeekDays: DayOfWeek[] | undefined,\n firstDayOfWeek: DayOfWeek,\n): DateRangeType => {\n if (workWeekDays && dateRangeType === DateRangeType.WorkWeek) {\n if (!isContiguous(workWeekDays, true, firstDayOfWeek) || workWeekDays.length === 0) {\n return DateRangeType.Week;\n }\n }\n\n return dateRangeType;\n};\n"]}
@@ -0,0 +1,8 @@
import { IDay, IDayGridOptions } from './dateGrid.types';
/**
* Generates a grid of days, given the `options`.
* Returns one additional week at the begining from the previous range
* and one at the end from the future range
* @param options - parameters to specify date related restrictions for the resulting grid
*/
export declare const getDayGrid: (options: IDayGridOptions) => IDay[][];
@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDayGrid = void 0;
var dateMath_1 = require("../dateMath/dateMath");
var dateValues_1 = require("../dateValues/dateValues");
var getDateRangeTypeToUse_1 = require("./getDateRangeTypeToUse");
var getBoundedDateRange_1 = require("./getBoundedDateRange");
var isRestrictedDate_1 = require("./isRestrictedDate");
/**
* Generates a grid of days, given the `options`.
* Returns one additional week at the begining from the previous range
* and one at the end from the future range
* @param options - parameters to specify date related restrictions for the resulting grid
*/
var getDayGrid = function (options) {
var selectedDate = options.selectedDate, dateRangeType = options.dateRangeType, firstDayOfWeek = options.firstDayOfWeek, today = options.today, minDate = options.minDate, maxDate = options.maxDate, weeksToShow = options.weeksToShow, workWeekDays = options.workWeekDays, daysToSelectInDayView = options.daysToSelectInDayView, restrictedDates = options.restrictedDates, markedDays = options.markedDays;
var restrictedDateOptions = { minDate: minDate, maxDate: maxDate, restrictedDates: restrictedDates };
var todaysDate = today || new Date();
var navigatedDate = options.navigatedDate ? options.navigatedDate : todaysDate;
var date;
if (weeksToShow && weeksToShow <= 4) {
// if showing less than a full month, just use date == navigatedDate
date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), navigatedDate.getDate());
}
else {
date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), 1);
}
var weeks = [];
// Cycle the date backwards to get to the first day of the week.
while (date.getDay() !== firstDayOfWeek) {
date.setDate(date.getDate() - 1);
}
// add the transition week as last week of previous range
date = (0, dateMath_1.addDays)(date, -dateValues_1.DAYS_IN_WEEK);
// a flag to indicate whether all days of the week are outside the month
var isAllDaysOfWeekOutOfMonth = false;
// in work week view if the days aren't contiguous we use week view instead
var selectedDateRangeType = (0, getDateRangeTypeToUse_1.getDateRangeTypeToUse)(dateRangeType, workWeekDays, firstDayOfWeek);
var selectedDates = [];
if (selectedDate) {
selectedDates = (0, dateMath_1.getDateRangeArray)(selectedDate, selectedDateRangeType, firstDayOfWeek, workWeekDays, daysToSelectInDayView);
selectedDates = (0, getBoundedDateRange_1.getBoundedDateRange)(selectedDates, minDate, maxDate);
}
var shouldGetWeeks = true;
for (var weekIndex = 0; shouldGetWeeks; weekIndex++) {
var week = [];
isAllDaysOfWeekOutOfMonth = true;
var _loop_1 = function (dayIndex) {
var originalDate = new Date(date.getTime());
var dayInfo = {
key: date.toString(),
date: date.getDate().toString(),
originalDate: originalDate,
isInMonth: date.getMonth() === navigatedDate.getMonth(),
isToday: (0, dateMath_1.compareDates)(todaysDate, date),
isSelected: (0, dateMath_1.isInDateRangeArray)(date, selectedDates),
isInBounds: !(0, isRestrictedDate_1.isRestrictedDate)(date, restrictedDateOptions),
isMarked: (markedDays === null || markedDays === void 0 ? void 0 : markedDays.some(function (markedDay) { return (0, dateMath_1.compareDates)(originalDate, markedDay); })) || false,
};
week.push(dayInfo);
if (dayInfo.isInMonth) {
isAllDaysOfWeekOutOfMonth = false;
}
date.setDate(date.getDate() + 1);
};
for (var dayIndex = 0; dayIndex < dateValues_1.DAYS_IN_WEEK; dayIndex++) {
_loop_1(dayIndex);
}
// We append the condition of the loop depending upon the showSixWeeksByDefault prop.
shouldGetWeeks = weeksToShow ? weekIndex < weeksToShow + 1 : !isAllDaysOfWeekOutOfMonth || weekIndex === 0;
// we don't check shouldGetWeeks before pushing because we want to add one extra week for transition state
weeks.push(week);
}
return weeks;
};
exports.getDayGrid = getDayGrid;
//# sourceMappingURL=getDayGrid.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,9 @@
export * from './dateGrid.types';
export * from './findAvailableDate';
export * from './getBoundedDateRange';
export * from './getDateRangeTypeToUse';
export * from './getDayGrid';
export * from './isAfterMaxDate';
export * from './isBeforeMinDate';
export * from './isRestrictedDate';
export * from './isContiguous';
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./dateGrid.types"), exports);
tslib_1.__exportStar(require("./findAvailableDate"), exports);
tslib_1.__exportStar(require("./getBoundedDateRange"), exports);
tslib_1.__exportStar(require("./getDateRangeTypeToUse"), exports);
tslib_1.__exportStar(require("./getDayGrid"), exports);
tslib_1.__exportStar(require("./isAfterMaxDate"), exports);
tslib_1.__exportStar(require("./isBeforeMinDate"), exports);
tslib_1.__exportStar(require("./isRestrictedDate"), exports);
tslib_1.__exportStar(require("./isContiguous"), exports);
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["dateGrid/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,8DAAoC;AACpC,gEAAsC;AACtC,kEAAwC;AACxC,uDAA6B;AAC7B,2DAAiC;AACjC,4DAAkC;AAClC,6DAAmC;AACnC,yDAA+B","sourcesContent":["export * from './dateGrid.types';\nexport * from './findAvailableDate';\nexport * from './getBoundedDateRange';\nexport * from './getDateRangeTypeToUse';\nexport * from './getDayGrid';\nexport * from './isAfterMaxDate';\nexport * from './isBeforeMinDate';\nexport * from './isRestrictedDate';\nexport * from './isContiguous';\n"]}
@@ -0,0 +1,7 @@
import { IRestrictedDatesOptions } from './dateGrid.types';
/**
* Checks if `date` happens later than max date
* @param date - date to check
* @param options - object with max date to check against
*/
export declare const isAfterMaxDate: (date: Date, options: IRestrictedDatesOptions) => boolean;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAfterMaxDate = void 0;
var dateMath_1 = require("../dateMath/dateMath");
/**
* Checks if `date` happens later than max date
* @param date - date to check
* @param options - object with max date to check against
*/
var isAfterMaxDate = function (date, options) {
var maxDate = options.maxDate;
return maxDate ? (0, dateMath_1.compareDatePart)(date, maxDate) >= 1 : false;
};
exports.isAfterMaxDate = isAfterMaxDate;
//# sourceMappingURL=isAfterMaxDate.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isAfterMaxDate.js","sourceRoot":"../src/","sources":["dateGrid/isAfterMaxDate.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAEvD;;;;GAIG;AACI,IAAM,cAAc,GAAG,UAAC,IAAU,EAAE,OAAgC;IACjE,IAAA,OAAO,GAAK,OAAO,QAAZ,CAAa;IAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,IAAA,0BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/D,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB","sourcesContent":["import { IRestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens later than max date\n * @param date - date to check\n * @param options - object with max date to check against\n */\nexport const isAfterMaxDate = (date: Date, options: IRestrictedDatesOptions): boolean => {\n const { maxDate } = options;\n return maxDate ? compareDatePart(date, maxDate) >= 1 : false;\n};\n"]}
@@ -0,0 +1,7 @@
import { IRestrictedDatesOptions } from './dateGrid.types';
/**
* Checks if `date` happens earlier than min date
* @param date - date to check
* @param options - object with min date to check against
*/
export declare const isBeforeMinDate: (date: Date, options: IRestrictedDatesOptions) => boolean;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBeforeMinDate = void 0;
var dateMath_1 = require("../dateMath/dateMath");
/**
* Checks if `date` happens earlier than min date
* @param date - date to check
* @param options - object with min date to check against
*/
var isBeforeMinDate = function (date, options) {
var minDate = options.minDate;
return minDate ? (0, dateMath_1.compareDatePart)(minDate, date) >= 1 : false;
};
exports.isBeforeMinDate = isBeforeMinDate;
//# sourceMappingURL=isBeforeMinDate.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isBeforeMinDate.js","sourceRoot":"../src/","sources":["dateGrid/isBeforeMinDate.ts"],"names":[],"mappings":";;;AACA,iDAAuD;AAEvD;;;;GAIG;AACI,IAAM,eAAe,GAAG,UAAC,IAAU,EAAE,OAAgC;IAClE,IAAA,OAAO,GAAK,OAAO,QAAZ,CAAa;IAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,IAAA,0BAAe,EAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/D,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B","sourcesContent":["import { IRestrictedDatesOptions } from './dateGrid.types';\nimport { compareDatePart } from '../dateMath/dateMath';\n\n/**\n * Checks if `date` happens earlier than min date\n * @param date - date to check\n * @param options - object with min date to check against\n */\nexport const isBeforeMinDate = (date: Date, options: IRestrictedDatesOptions): boolean => {\n const { minDate } = options;\n return minDate ? compareDatePart(minDate, date) >= 1 : false;\n};\n"]}
@@ -0,0 +1,8 @@
import { DayOfWeek } from '../dateValues/dateValues';
/**
* Returns whether provided week days are contiguous.
* @param days - list of days in a week
* @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not
* @param firstDayOfWeek - decides which day of week is the first one in the order.
*/
export declare const isContiguous: (days: DayOfWeek[], isSingleWeek: boolean, firstDayOfWeek: DayOfWeek) => boolean;
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isContiguous = void 0;
/**
* Returns whether provided week days are contiguous.
* @param days - list of days in a week
* @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not
* @param firstDayOfWeek - decides which day of week is the first one in the order.
*/
var isContiguous = function (days, isSingleWeek, firstDayOfWeek) {
var daySet = new Set(days);
var amountOfNoNeighbors = 0;
for (var _i = 0, days_1 = days; _i < days_1.length; _i++) {
var day = days_1[_i];
var nextDay = (day + 1) % 7;
if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {
amountOfNoNeighbors++;
}
}
// In case the full week is provided, then each day has a neighbor
//, otherwise the last day does not have a neighbor.
return amountOfNoNeighbors < 2;
};
exports.isContiguous = isContiguous;
//# sourceMappingURL=isContiguous.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isContiguous.js","sourceRoot":"../src/","sources":["dateGrid/isContiguous.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,IAAM,YAAY,GAAG,UAAC,IAAiB,EAAE,YAAqB,EAAE,cAAyB;IAC9F,IAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE,CAAC;QAApB,IAAM,GAAG,aAAA;QACZ,IAAM,OAAO,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,YAAY,IAAI,cAAc,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC;YAC5E,mBAAmB,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,oDAAoD;IACpD,OAAO,mBAAmB,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC;AAbW,QAAA,YAAY,gBAavB","sourcesContent":["import { DayOfWeek } from '../dateValues/dateValues';\n\n/**\n * Returns whether provided week days are contiguous.\n * @param days - list of days in a week\n * @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not\n * @param firstDayOfWeek - decides which day of week is the first one in the order.\n */\nexport const isContiguous = (days: DayOfWeek[], isSingleWeek: boolean, firstDayOfWeek: DayOfWeek): boolean => {\n const daySet = new Set(days);\n let amountOfNoNeighbors = 0;\n for (const day of days) {\n const nextDay = (day + 1) % 7;\n if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {\n amountOfNoNeighbors++;\n }\n }\n\n // In case the full week is provided, then each day has a neighbor\n //, otherwise the last day does not have a neighbor.\n return amountOfNoNeighbors < 2;\n};\n"]}
@@ -0,0 +1,7 @@
import { IRestrictedDatesOptions } from './dateGrid.types';
/**
* Checks if `date` falls into the restricted `options`
* @param date - date to check
* @param options - restriction options (min date, max date and list of restricted dates)
*/
export declare const isRestrictedDate: (date: Date, options: IRestrictedDatesOptions) => boolean;
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isRestrictedDate = void 0;
var dateMath_1 = require("../dateMath/dateMath");
var isBeforeMinDate_1 = require("./isBeforeMinDate");
var isAfterMaxDate_1 = require("./isAfterMaxDate");
/**
* Checks if `date` falls into the restricted `options`
* @param date - date to check
* @param options - restriction options (min date, max date and list of restricted dates)
*/
var isRestrictedDate = function (date, options) {
var restrictedDates = options.restrictedDates, minDate = options.minDate, maxDate = options.maxDate;
if (!restrictedDates && !minDate && !maxDate) {
return false;
}
var inRestrictedDates = restrictedDates && restrictedDates.some(function (rd) { return (0, dateMath_1.compareDates)(rd, date); });
return inRestrictedDates || (0, isBeforeMinDate_1.isBeforeMinDate)(date, options) || (0, isAfterMaxDate_1.isAfterMaxDate)(date, options);
};
exports.isRestrictedDate = isRestrictedDate;
//# sourceMappingURL=isRestrictedDate.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isRestrictedDate.js","sourceRoot":"../src/","sources":["dateGrid/isRestrictedDate.ts"],"names":[],"mappings":";;;AACA,iDAAoD;AACpD,qDAAoD;AACpD,mDAAkD;AAElD;;;;GAIG;AACI,IAAM,gBAAgB,GAAG,UAAC,IAAU,EAAE,OAAgC;IACnE,IAAA,eAAe,GAAuB,OAAO,gBAA9B,EAAE,OAAO,GAAc,OAAO,QAArB,EAAE,OAAO,GAAK,OAAO,QAAZ,CAAa;IACtD,IAAI,CAAC,eAAe,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAM,iBAAiB,GAAG,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,UAAC,EAAQ,IAAK,OAAA,IAAA,uBAAY,EAAC,EAAE,EAAE,IAAI,CAAC,EAAtB,CAAsB,CAAC,CAAC;IACxG,OAAO,iBAAiB,IAAI,IAAA,iCAAe,EAAC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAA,+BAAc,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9F,CAAC,CAAC;AAPW,QAAA,gBAAgB,oBAO3B","sourcesContent":["import { IRestrictedDatesOptions } from './dateGrid.types';\nimport { compareDates } from '../dateMath/dateMath';\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\n/**\n * Checks if `date` falls into the restricted `options`\n * @param date - date to check\n * @param options - restriction options (min date, max date and list of restricted dates)\n */\nexport const isRestrictedDate = (date: Date, options: IRestrictedDatesOptions): boolean => {\n const { restrictedDates, minDate, maxDate } = options;\n if (!restrictedDates && !minDate && !maxDate) {\n return false;\n }\n const inRestrictedDates = restrictedDates && restrictedDates.some((rd: Date) => compareDates(rd, date));\n return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);\n};\n"]}
@@ -0,0 +1,134 @@
import { DayOfWeek, FirstWeekOfYear, DateRangeType } from '../dateValues/dateValues';
/**
* Returns a date offset from the given date by the specified number of days.
* @param date - The origin date
* @param days - The number of days to offset. 'days' can be negative.
* @returns A new Date object offset from the origin date by the given number of days
*/
export declare function addDays(date: Date, days: number): Date;
/**
* Returns a date offset from the given date by the specified number of weeks.
* @param date - The origin date
* @param weeks - The number of weeks to offset. 'weeks' can be negative.
* @returns A new Date object offset from the origin date by the given number of weeks
*/
export declare function addWeeks(date: Date, weeks: number): Date;
/**
* Returns a date offset from the given date by the specified number of months.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param months - The number of months to offset. 'months' can be negative.
* @returns A new Date object offset from the origin date by the given number of months
*/
export declare function addMonths(date: Date, months: number): Date;
/**
* Returns a date offset from the given date by the specified number of years.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param years - The number of years to offset. 'years' can be negative.
* @returns A new Date object offset from the origin date by the given number of years
*/
export declare function addYears(date: Date, years: number): Date;
/**
* Returns a date that is the first day of the month of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the first day of the month.
*/
export declare function getMonthStart(date: Date): Date;
/**
* Returns a date that is the last day of the month of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the last day of the month.
*/
export declare function getMonthEnd(date: Date): Date;
/**
* Returns a date that is the first day of the year of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the first day of the year.
*/
export declare function getYearStart(date: Date): Date;
/**
* Returns a date that is the last day of the year of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the last day of the year.
*/
export declare function getYearEnd(date: Date): Date;
/**
* Returns a date that is a copy of the given date, aside from the month changing to the given month.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param month - The 0-based index of the month to set on the date.
* @returns A new Date object with the given month set.
*/
export declare function setMonth(date: Date, month: number): Date;
/**
* Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.
* @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.
*/
export declare function compareDates(date1: Date, date2: Date): boolean;
/**
* Compare the date parts of two dates
* @param date1 - The first date to compare
* @param date2 - The second date to compare
* @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value
* if date1 is later than date2.
*/
export declare function compareDatePart(date1: Date, date2: Date): number;
/**
* Gets the date range array including the specified date. The date range array is calculated as the list
* of dates accounting for the specified first day of the week and date range type.
* @param date - The input date
* @param dateRangeType - The desired date range type, i.e., day, week, month, etc.
* @param firstDayOfWeek - The first day of the week.
* @param workWeekDays - The allowed days in work week. If not provided, assumes all days are allowed.
* @param daysToSelectInDayView - The number of days to include when using dateRangeType === DateRangeType.Day
* for multiday view. Defaults to 1
* @returns An array of dates representing the date range containing the specified date.
*/
export declare function getDateRangeArray(date: Date, dateRangeType: DateRangeType, firstDayOfWeek: DayOfWeek, workWeekDays?: DayOfWeek[], daysToSelectInDayView?: number): Date[];
/**
* Checks whether the specified date is in the given date range.
* @param date - The origin date
* @param dateRange - An array of dates to do the lookup on
* @returns True if the date matches one of the dates in the specified array, false otherwise.
*/
export declare function isInDateRangeArray(date: Date, dateRange: Date[]): boolean;
/**
* Returns the week number for a date.
* Week numbers are 1 - 52 (53) in a year
* @param navigatedDate - A date to find the week number for.
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
* @param firstWeekOfYear - The first week of the year (1-2)
* @returns The weeks number array for the current month.
*/
export declare function getWeekNumbersInMonth(weeksInMonth: number, firstDayOfWeek: DayOfWeek, firstWeekOfYear: FirstWeekOfYear, navigatedDate: Date): number[];
/**
* Returns the week number for a date.
* Week numbers are 1 - 52 (53) in a year
* @param date - A date to find the week number for.
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
* @param firstWeekOfYear - The first week of the year (1-2)
* @returns The week's number in the year.
*/
export declare function getWeekNumber(date: Date, firstDayOfWeek: DayOfWeek, firstWeekOfYear: FirstWeekOfYear): number;
/**
* Gets the date for the first day of the week based on the given date assuming
* the specified first day of the week.
* @param date - The date to find the beginning of the week date for.
* @returns A new date object representing the first day of the week containing the input date.
*/
export declare function getStartDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date;
/**
* Gets the date for the last day of the week based on the given date assuming
* the specified first day of the week.
* @param date - The date to find the beginning of the week date for.
* @returns A new date object representing the first day of the week containing the input date.
*/
export declare function getEndDateOfWeek(date: Date, firstDayOfWeek: DayOfWeek): Date;
/**
* Helper function to assist in date comparisons
*/
export declare function getDatePartHashValue(date: Date): number;
@@ -0,0 +1,392 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addDays = addDays;
exports.addWeeks = addWeeks;
exports.addMonths = addMonths;
exports.addYears = addYears;
exports.getMonthStart = getMonthStart;
exports.getMonthEnd = getMonthEnd;
exports.getYearStart = getYearStart;
exports.getYearEnd = getYearEnd;
exports.setMonth = setMonth;
exports.compareDates = compareDates;
exports.compareDatePart = compareDatePart;
exports.getDateRangeArray = getDateRangeArray;
exports.isInDateRangeArray = isInDateRangeArray;
exports.getWeekNumbersInMonth = getWeekNumbersInMonth;
exports.getWeekNumber = getWeekNumber;
exports.getStartDateOfWeek = getStartDateOfWeek;
exports.getEndDateOfWeek = getEndDateOfWeek;
exports.getDatePartHashValue = getDatePartHashValue;
var dateValues_1 = require("../dateValues/dateValues");
var timeConstants_1 = require("../dateValues/timeConstants");
/**
* Returns a date offset from the given date by the specified number of days.
* @param date - The origin date
* @param days - The number of days to offset. 'days' can be negative.
* @returns A new Date object offset from the origin date by the given number of days
*/
function addDays(date, days) {
var result = new Date(date.getTime());
result.setDate(result.getDate() + days);
return result;
}
/**
* Returns a date offset from the given date by the specified number of weeks.
* @param date - The origin date
* @param weeks - The number of weeks to offset. 'weeks' can be negative.
* @returns A new Date object offset from the origin date by the given number of weeks
*/
function addWeeks(date, weeks) {
return addDays(date, weeks * timeConstants_1.TimeConstants.DaysInOneWeek);
}
/**
* Returns a date offset from the given date by the specified number of months.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param months - The number of months to offset. 'months' can be negative.
* @returns A new Date object offset from the origin date by the given number of months
*/
function addMonths(date, months) {
var result = new Date(date.getTime());
var newMonth = result.getMonth() + months;
result.setMonth(newMonth);
// We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.
// Loop until we back up to a day the new month has.
// (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)
if (result.getMonth() !==
((newMonth % timeConstants_1.TimeConstants.MonthInOneYear) + timeConstants_1.TimeConstants.MonthInOneYear) % timeConstants_1.TimeConstants.MonthInOneYear) {
result = addDays(result, -result.getDate());
}
return result;
}
/**
* Returns a date offset from the given date by the specified number of years.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param years - The number of years to offset. 'years' can be negative.
* @returns A new Date object offset from the origin date by the given number of years
*/
function addYears(date, years) {
var result = new Date(date.getTime());
result.setFullYear(date.getFullYear() + years);
// We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.
// Loop until we back up to a day the new month has.
// (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)
if (result.getMonth() !==
((date.getMonth() % timeConstants_1.TimeConstants.MonthInOneYear) + timeConstants_1.TimeConstants.MonthInOneYear) % timeConstants_1.TimeConstants.MonthInOneYear) {
result = addDays(result, -result.getDate());
}
return result;
}
/**
* Returns a date that is the first day of the month of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the first day of the month.
*/
function getMonthStart(date) {
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
}
/**
* Returns a date that is the last day of the month of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the last day of the month.
*/
function getMonthEnd(date) {
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 0, 0, 0, 0);
}
/**
* Returns a date that is the first day of the year of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the first day of the year.
*/
function getYearStart(date) {
return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
}
/**
* Returns a date that is the last day of the year of the provided date.
* @param date - The origin date
* @returns A new Date object with the day set to the last day of the year.
*/
function getYearEnd(date) {
return new Date(date.getFullYear() + 1, 0, 0, 0, 0, 0, 0);
}
/**
* Returns a date that is a copy of the given date, aside from the month changing to the given month.
* The method tries to preserve the day-of-month; however, if the new month does not have enough days
* to contain the original day-of-month, we'll use the last day of the new month.
* @param date - The origin date
* @param month - The 0-based index of the month to set on the date.
* @returns A new Date object with the given month set.
*/
function setMonth(date, month) {
return addMonths(date, month - date.getMonth());
}
/**
* Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.
* @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.
*/
function compareDates(date1, date2) {
if (!date1 && !date2) {
return true;
}
else if (!date1 || !date2) {
return false;
}
else {
return (date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate());
}
}
/**
* Compare the date parts of two dates
* @param date1 - The first date to compare
* @param date2 - The second date to compare
* @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value
* if date1 is later than date2.
*/
function compareDatePart(date1, date2) {
return getDatePartHashValue(date1) - getDatePartHashValue(date2);
}
/**
* Gets the date range array including the specified date. The date range array is calculated as the list
* of dates accounting for the specified first day of the week and date range type.
* @param date - The input date
* @param dateRangeType - The desired date range type, i.e., day, week, month, etc.
* @param firstDayOfWeek - The first day of the week.
* @param workWeekDays - The allowed days in work week. If not provided, assumes all days are allowed.
* @param daysToSelectInDayView - The number of days to include when using dateRangeType === DateRangeType.Day
* for multiday view. Defaults to 1
* @returns An array of dates representing the date range containing the specified date.
*/
function getDateRangeArray(date, dateRangeType, firstDayOfWeek, workWeekDays, daysToSelectInDayView) {
if (daysToSelectInDayView === void 0) { daysToSelectInDayView = 1; }
var datesArray = [];
var startDate;
var endDate = null;
if (!workWeekDays) {
workWeekDays = [dateValues_1.DayOfWeek.Monday, dateValues_1.DayOfWeek.Tuesday, dateValues_1.DayOfWeek.Wednesday, dateValues_1.DayOfWeek.Thursday, dateValues_1.DayOfWeek.Friday];
}
daysToSelectInDayView = Math.max(daysToSelectInDayView, 1);
switch (dateRangeType) {
case dateValues_1.DateRangeType.Day:
startDate = getDatePart(date);
endDate = addDays(startDate, daysToSelectInDayView);
break;
case dateValues_1.DateRangeType.Week:
case dateValues_1.DateRangeType.WorkWeek:
startDate = getStartDateOfWeek(getDatePart(date), firstDayOfWeek);
endDate = addDays(startDate, timeConstants_1.TimeConstants.DaysInOneWeek);
break;
case dateValues_1.DateRangeType.Month:
startDate = new Date(date.getFullYear(), date.getMonth(), 1);
endDate = addMonths(startDate, 1);
break;
default:
throw new Error('Unexpected object: ' + dateRangeType);
}
// Populate the dates array with the dates in range
var nextDate = startDate;
do {
if (dateRangeType !== dateValues_1.DateRangeType.WorkWeek) {
// push all days not in work week view
datesArray.push(nextDate);
}
else if (workWeekDays.indexOf(nextDate.getDay()) !== -1) {
datesArray.push(nextDate);
}
nextDate = addDays(nextDate, 1);
} while (!compareDates(nextDate, endDate));
return datesArray;
}
/**
* Checks whether the specified date is in the given date range.
* @param date - The origin date
* @param dateRange - An array of dates to do the lookup on
* @returns True if the date matches one of the dates in the specified array, false otherwise.
*/
function isInDateRangeArray(date, dateRange) {
for (var _i = 0, dateRange_1 = dateRange; _i < dateRange_1.length; _i++) {
var dateInRange = dateRange_1[_i];
if (compareDates(date, dateInRange)) {
return true;
}
}
return false;
}
/**
* Returns the week number for a date.
* Week numbers are 1 - 52 (53) in a year
* @param navigatedDate - A date to find the week number for.
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
* @param firstWeekOfYear - The first week of the year (1-2)
* @returns The weeks number array for the current month.
*/
function getWeekNumbersInMonth(weeksInMonth, firstDayOfWeek, firstWeekOfYear, navigatedDate) {
var selectedYear = navigatedDate.getFullYear();
var selectedMonth = navigatedDate.getMonth();
var dayOfMonth = 1;
var fistDayOfMonth = new Date(selectedYear, selectedMonth, dayOfMonth);
var endOfFirstWeek = dayOfMonth +
(firstDayOfWeek + timeConstants_1.TimeConstants.DaysInOneWeek - 1) -
adjustWeekDay(firstDayOfWeek, fistDayOfMonth.getDay());
var endOfWeekRange = new Date(selectedYear, selectedMonth, endOfFirstWeek);
dayOfMonth = endOfWeekRange.getDate();
var weeksArray = [];
for (var i = 0; i < weeksInMonth; i++) {
// Get week number for end of week
weeksArray.push(getWeekNumber(endOfWeekRange, firstDayOfWeek, firstWeekOfYear));
dayOfMonth += timeConstants_1.TimeConstants.DaysInOneWeek;
endOfWeekRange = new Date(selectedYear, selectedMonth, dayOfMonth);
}
return weeksArray;
}
/**
* Returns the week number for a date.
* Week numbers are 1 - 52 (53) in a year
* @param date - A date to find the week number for.
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
* @param firstWeekOfYear - The first week of the year (1-2)
* @returns The week's number in the year.
*/
function getWeekNumber(date, firstDayOfWeek, firstWeekOfYear) {
// First four-day week of the year - minumum days count
var fourDayWeek = 4;
switch (firstWeekOfYear) {
case dateValues_1.FirstWeekOfYear.FirstFullWeek:
return getWeekOfYearFullDays(date, firstDayOfWeek, timeConstants_1.TimeConstants.DaysInOneWeek);
case dateValues_1.FirstWeekOfYear.FirstFourDayWeek:
return getWeekOfYearFullDays(date, firstDayOfWeek, fourDayWeek);
default:
return getFirstDayWeekOfYear(date, firstDayOfWeek);
}
}
/**
* Gets the date for the first day of the week based on the given date assuming
* the specified first day of the week.
* @param date - The date to find the beginning of the week date for.
* @returns A new date object representing the first day of the week containing the input date.
*/
function getStartDateOfWeek(date, firstDayOfWeek) {
var daysOffset = firstDayOfWeek - date.getDay();
if (daysOffset > 0) {
// If first day of week is > date, go 1 week back, to ensure resulting date is in the past.
daysOffset -= timeConstants_1.TimeConstants.DaysInOneWeek;
}
return addDays(date, daysOffset);
}
/**
* Gets the date for the last day of the week based on the given date assuming
* the specified first day of the week.
* @param date - The date to find the beginning of the week date for.
* @returns A new date object representing the first day of the week containing the input date.
*/
function getEndDateOfWeek(date, firstDayOfWeek) {
var lastDayOfWeek = firstDayOfWeek - 1 >= 0 ? firstDayOfWeek - 1 : timeConstants_1.TimeConstants.DaysInOneWeek - 1;
var daysOffset = lastDayOfWeek - date.getDay();
if (daysOffset < 0) {
// If last day of week is < date, go 1 week forward, to ensure resulting date is in the future.
daysOffset += timeConstants_1.TimeConstants.DaysInOneWeek;
}
return addDays(date, daysOffset);
}
/**
* Gets a new date with the time portion zeroed out, i.e., set to midnight
* @param date - The origin date
* @returns A new date with the time set to midnight
*/
function getDatePart(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}
/**
* Helper function to assist in date comparisons
*/
function getDatePartHashValue(date) {
// Generate date hash value created as sum of Date (up to 31 = 5 bits), Month (up to 11 = 4 bits) and Year.
// eslint-disable-next-line no-bitwise
return date.getDate() + (date.getMonth() << 5) + (date.getFullYear() << 9);
}
/**
* Helper function for `getWeekNumber`.
* Returns week number for a date.
* @param date - current selected date.
* @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)
* @param numberOfFullDays - week settings.
* @returns The week's number in the year.
*/
function getWeekOfYearFullDays(date, firstDayOfWeek, numberOfFullDays) {
var dayOfYear = getDayOfYear(date) - 1;
var num = date.getDay() - (dayOfYear % timeConstants_1.TimeConstants.DaysInOneWeek);
var lastDayOfPrevYear = new Date(date.getFullYear() - 1, dateValues_1.MonthOfYear.December, 31);
var daysInYear = getDayOfYear(lastDayOfPrevYear) - 1;
var num2 = (firstDayOfWeek - num + 2 * timeConstants_1.TimeConstants.DaysInOneWeek) % timeConstants_1.TimeConstants.DaysInOneWeek;
if (num2 !== 0 && num2 >= numberOfFullDays) {
num2 -= timeConstants_1.TimeConstants.DaysInOneWeek;
}
var num3 = dayOfYear - num2;
if (num3 < 0) {
num -= daysInYear % timeConstants_1.TimeConstants.DaysInOneWeek;
num2 = (firstDayOfWeek - num + 2 * timeConstants_1.TimeConstants.DaysInOneWeek) % timeConstants_1.TimeConstants.DaysInOneWeek;
if (num2 !== 0 && num2 + 1 >= numberOfFullDays) {
num2 -= timeConstants_1.TimeConstants.DaysInOneWeek;
}
num3 = daysInYear - num2;
}
return Math.floor(num3 / timeConstants_1.TimeConstants.DaysInOneWeek + 1);
}
/**
* Helper function for `getWeekNumber`.
* Returns week number for a date.
* @param date - current selected date.
* @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)
* @returns The week's number in the year.
*/
function getFirstDayWeekOfYear(date, firstDayOfWeek) {
var num = getDayOfYear(date) - 1;
var num2 = date.getDay() - (num % timeConstants_1.TimeConstants.DaysInOneWeek);
var num3 = (num2 - firstDayOfWeek + 2 * timeConstants_1.TimeConstants.DaysInOneWeek) % timeConstants_1.TimeConstants.DaysInOneWeek;
return Math.floor((num + num3) / timeConstants_1.TimeConstants.DaysInOneWeek + 1);
}
/**
* Helper function for `getWeekNumber`.
* Returns adjusted week day number when `firstDayOfWeek` is other than Sunday.
* For Week Day Number comparison checks
* @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)
* @param dateWeekDay - shifts number forward to 1 week in case passed as true
* @returns The day of week adjusted to `firstDayOfWeek`; e.g. when `firstDayOfWeek` is Monday (1),
* Sunday becomes 7.
*/
function adjustWeekDay(firstDayOfWeek, dateWeekDay) {
return firstDayOfWeek !== dateValues_1.DayOfWeek.Sunday && dateWeekDay < firstDayOfWeek
? dateWeekDay + timeConstants_1.TimeConstants.DaysInOneWeek
: dateWeekDay;
}
/**
* Returns the day number for a date in a year:
* the number of days since January 1st in the particular year.
* @param date - A date to find the day number for.
* @returns The day's number in the year.
*/
function getDayOfYear(date) {
var month = date.getMonth();
var year = date.getFullYear();
var daysUntilDate = 0;
for (var i = 0; i < month; i++) {
daysUntilDate += daysInMonth(i + 1, year);
}
daysUntilDate += date.getDate();
return daysUntilDate;
}
/**
* Returns the number of days in the month
* @param month - The month number to target (months 1-12).
* @param year - The year to target.
* @returns The number of days in the month.
*/
function daysInMonth(month, year) {
return new Date(year, month, 0).getDate();
}
//# sourceMappingURL=dateMath.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,51 @@
/**
* The days of the week
* {@docCategory DateTimeUtilities}
*/
export declare enum DayOfWeek {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
/**
* The months
* {@docCategory DateTimeUtilities}
*/
export declare enum MonthOfYear {
January = 0,
February = 1,
March = 2,
April = 3,
May = 4,
June = 5,
July = 6,
August = 7,
September = 8,
October = 9,
November = 10,
December = 11
}
/**
* First week of the year settings types
* {@docCategory DateTimeUtilities}
*/
export declare enum FirstWeekOfYear {
FirstDay = 0,
FirstFullWeek = 1,
FirstFourDayWeek = 2
}
/**
* The supported date range types
* {@docCategory DateTimeUtilities}
*/
export declare enum DateRangeType {
Day = 0,
Week = 1,
Month = 2,
WorkWeek = 3
}
export declare const DAYS_IN_WEEK = 7;
@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DAYS_IN_WEEK = exports.DateRangeType = exports.FirstWeekOfYear = exports.MonthOfYear = exports.DayOfWeek = void 0;
/**
* The days of the week
* {@docCategory DateTimeUtilities}
*/
var DayOfWeek;
(function (DayOfWeek) {
DayOfWeek[DayOfWeek["Sunday"] = 0] = "Sunday";
DayOfWeek[DayOfWeek["Monday"] = 1] = "Monday";
DayOfWeek[DayOfWeek["Tuesday"] = 2] = "Tuesday";
DayOfWeek[DayOfWeek["Wednesday"] = 3] = "Wednesday";
DayOfWeek[DayOfWeek["Thursday"] = 4] = "Thursday";
DayOfWeek[DayOfWeek["Friday"] = 5] = "Friday";
DayOfWeek[DayOfWeek["Saturday"] = 6] = "Saturday";
})(DayOfWeek || (exports.DayOfWeek = DayOfWeek = {}));
/**
* The months
* {@docCategory DateTimeUtilities}
*/
var MonthOfYear;
(function (MonthOfYear) {
MonthOfYear[MonthOfYear["January"] = 0] = "January";
MonthOfYear[MonthOfYear["February"] = 1] = "February";
MonthOfYear[MonthOfYear["March"] = 2] = "March";
MonthOfYear[MonthOfYear["April"] = 3] = "April";
MonthOfYear[MonthOfYear["May"] = 4] = "May";
MonthOfYear[MonthOfYear["June"] = 5] = "June";
MonthOfYear[MonthOfYear["July"] = 6] = "July";
MonthOfYear[MonthOfYear["August"] = 7] = "August";
MonthOfYear[MonthOfYear["September"] = 8] = "September";
MonthOfYear[MonthOfYear["October"] = 9] = "October";
MonthOfYear[MonthOfYear["November"] = 10] = "November";
MonthOfYear[MonthOfYear["December"] = 11] = "December";
})(MonthOfYear || (exports.MonthOfYear = MonthOfYear = {}));
/**
* First week of the year settings types
* {@docCategory DateTimeUtilities}
*/
var FirstWeekOfYear;
(function (FirstWeekOfYear) {
FirstWeekOfYear[FirstWeekOfYear["FirstDay"] = 0] = "FirstDay";
FirstWeekOfYear[FirstWeekOfYear["FirstFullWeek"] = 1] = "FirstFullWeek";
FirstWeekOfYear[FirstWeekOfYear["FirstFourDayWeek"] = 2] = "FirstFourDayWeek";
})(FirstWeekOfYear || (exports.FirstWeekOfYear = FirstWeekOfYear = {}));
/**
* The supported date range types
* {@docCategory DateTimeUtilities}
*/
var DateRangeType;
(function (DateRangeType) {
DateRangeType[DateRangeType["Day"] = 0] = "Day";
DateRangeType[DateRangeType["Week"] = 1] = "Week";
DateRangeType[DateRangeType["Month"] = 2] = "Month";
DateRangeType[DateRangeType["WorkWeek"] = 3] = "WorkWeek";
})(DateRangeType || (exports.DateRangeType = DateRangeType = {}));
exports.DAYS_IN_WEEK = 7;
//# sourceMappingURL=dateValues.js.map
@@ -0,0 +1 @@
{"version":3,"file":"dateValues.js","sourceRoot":"../src/","sources":["dateValues/dateValues.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,6CAAU,CAAA;IACV,6CAAU,CAAA;IACV,+CAAW,CAAA;IACX,mDAAa,CAAA;IACb,iDAAY,CAAA;IACZ,6CAAU,CAAA;IACV,iDAAY,CAAA;AACd,CAAC,EARW,SAAS,yBAAT,SAAS,QAQpB;AAED;;;GAGG;AACH,IAAY,WAaX;AAbD,WAAY,WAAW;IACrB,mDAAW,CAAA;IACX,qDAAY,CAAA;IACZ,+CAAS,CAAA;IACT,+CAAS,CAAA;IACT,2CAAO,CAAA;IACP,6CAAQ,CAAA;IACR,6CAAQ,CAAA;IACR,iDAAU,CAAA;IACV,uDAAa,CAAA;IACb,mDAAW,CAAA;IACX,sDAAa,CAAA;IACb,sDAAa,CAAA;AACf,CAAC,EAbW,WAAW,2BAAX,WAAW,QAatB;AAED;;;GAGG;AACH,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,6DAAY,CAAA;IACZ,uEAAiB,CAAA;IACjB,6EAAoB,CAAA;AACtB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED;;;GAGG;AACH,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,mDAAS,CAAA;IACT,yDAAY,CAAA;AACd,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB;AAEY,QAAA,YAAY,GAAG,CAAC,CAAC","sourcesContent":["/**\n * The days of the week\n * {@docCategory DateTimeUtilities}\n */\nexport enum DayOfWeek {\n Sunday = 0,\n Monday = 1,\n Tuesday = 2,\n Wednesday = 3,\n Thursday = 4,\n Friday = 5,\n Saturday = 6,\n}\n\n/**\n * The months\n * {@docCategory DateTimeUtilities}\n */\nexport enum MonthOfYear {\n January = 0,\n February = 1,\n March = 2,\n April = 3,\n May = 4,\n June = 5,\n July = 6,\n August = 7,\n September = 8,\n October = 9,\n November = 10,\n December = 11,\n}\n\n/**\n * First week of the year settings types\n * {@docCategory DateTimeUtilities}\n */\nexport enum FirstWeekOfYear {\n FirstDay = 0,\n FirstFullWeek = 1,\n FirstFourDayWeek = 2,\n}\n\n/**\n * The supported date range types\n * {@docCategory DateTimeUtilities}\n */\nexport enum DateRangeType {\n Day = 0,\n Week = 1,\n Month = 2,\n WorkWeek = 3,\n}\n\nexport const DAYS_IN_WEEK = 7;\n"]}
@@ -0,0 +1,22 @@
export declare const TimeConstants: {
MillisecondsInOneDay: number;
MillisecondsIn1Sec: number;
MillisecondsIn1Min: number;
MillisecondsIn30Mins: number;
MillisecondsIn1Hour: number;
MinutesInOneDay: number;
MinutesInOneHour: number;
DaysInOneWeek: number;
MonthInOneYear: number;
HoursInOneDay: number;
SecondsInOneMinute: number;
OffsetTo24HourFormat: number;
/**
* Matches a time string. Groups:
* 1. hours (with or without leading 0)
* 2. minutes
* 3. seconds (optional)
* 4. meridiem (am/pm, case-insensitive, optional)
*/
TimeFormatRegex: RegExp;
};
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeConstants = void 0;
exports.TimeConstants = {
MillisecondsInOneDay: 86400000,
MillisecondsIn1Sec: 1000,
MillisecondsIn1Min: 60000,
MillisecondsIn30Mins: 1800000,
MillisecondsIn1Hour: 3600000,
MinutesInOneDay: 1440,
MinutesInOneHour: 60,
DaysInOneWeek: 7,
MonthInOneYear: 12,
HoursInOneDay: 24,
SecondsInOneMinute: 60,
OffsetTo24HourFormat: 12,
/**
* Matches a time string. Groups:
* 1. hours (with or without leading 0)
* 2. minutes
* 3. seconds (optional)
* 4. meridiem (am/pm, case-insensitive, optional)
*/
TimeFormatRegex: /^(\d\d?):(\d\d):?(\d\d)? ?([ap]m)?/i,
};
//# sourceMappingURL=timeConstants.js.map
@@ -0,0 +1 @@
{"version":3,"file":"timeConstants.js","sourceRoot":"../src/","sources":["dateValues/timeConstants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,oBAAoB,EAAE,QAAQ;IAC9B,kBAAkB,EAAE,IAAI;IACxB,kBAAkB,EAAE,KAAK;IACzB,oBAAoB,EAAE,OAAO;IAC7B,mBAAmB,EAAE,OAAO;IAC5B,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE,CAAC;IAChB,cAAc,EAAE,EAAE;IAClB,aAAa,EAAE,EAAE;IACjB,kBAAkB,EAAE,EAAE;IACtB,oBAAoB,EAAE,EAAE;IACxB;;;;;;OAMG;IACH,eAAe,EAAE,qCAAqC;CACvD,CAAC","sourcesContent":["export const TimeConstants = {\n MillisecondsInOneDay: 86400000,\n MillisecondsIn1Sec: 1000,\n MillisecondsIn1Min: 60000,\n MillisecondsIn30Mins: 1800000,\n MillisecondsIn1Hour: 3600000,\n MinutesInOneDay: 1440,\n MinutesInOneHour: 60,\n DaysInOneWeek: 7,\n MonthInOneYear: 12,\n HoursInOneDay: 24,\n SecondsInOneMinute: 60,\n OffsetTo24HourFormat: 12,\n /**\n * Matches a time string. Groups:\n * 1. hours (with or without leading 0)\n * 2. minutes\n * 3. seconds (optional)\n * 4. meridiem (am/pm, case-insensitive, optional)\n */\n TimeFormatRegex: /^(\\d\\d?):(\\d\\d):?(\\d\\d)? ?([ap]m)?/i,\n};\n"]}
+8
View File
@@ -0,0 +1,8 @@
export * from './dateMath/dateMath';
export * from './dateValues/dateValues';
export * from './dateValues/timeConstants';
export * from './dateFormatting/index';
export * from './dateGrid/index';
export * from './timeMath/timeMath';
export * from './timeFormatting/index';
import './version';
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./dateMath/dateMath"), exports);
tslib_1.__exportStar(require("./dateValues/dateValues"), exports);
tslib_1.__exportStar(require("./dateValues/timeConstants"), exports);
tslib_1.__exportStar(require("./dateFormatting/index"), exports);
tslib_1.__exportStar(require("./dateGrid/index"), exports);
tslib_1.__exportStar(require("./timeMath/timeMath"), exports);
tslib_1.__exportStar(require("./timeFormatting/index"), exports);
require("./version");
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,kEAAwC;AACxC,qEAA2C;AAC3C,iEAAuC;AACvC,2DAAiC;AACjC,8DAAoC;AACpC,iEAAuC;AACvC,qBAAmB","sourcesContent":["export * from './dateMath/dateMath';\nexport * from './dateValues/dateValues';\nexport * from './dateValues/timeConstants';\nexport * from './dateFormatting/index';\nexport * from './dateGrid/index';\nexport * from './timeMath/timeMath';\nexport * from './timeFormatting/index';\nimport './version';\n"]}
@@ -0,0 +1,7 @@
/**
* Format a date object to a localized time string using the browser's default locale
* @param date - Input date to format
* @param showSeconds - Whether to show seconds in the formatted string
* @param useHour12 - Whether to use 12-hour time
*/
export declare const formatTimeString: (date: Date, showSeconds?: boolean, useHour12?: boolean) => string;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatTimeString = void 0;
/**
* Format a date object to a localized time string using the browser's default locale
* @param date - Input date to format
* @param showSeconds - Whether to show seconds in the formatted string
* @param useHour12 - Whether to use 12-hour time
*/
var formatTimeString = function (date, showSeconds, useHour12) {
var localeTimeString = date.toLocaleTimeString([], {
hour: 'numeric',
minute: '2-digit',
second: showSeconds ? '2-digit' : undefined,
hour12: useHour12,
});
if (!useHour12 && localeTimeString.slice(0, 2) === '24') {
localeTimeString = '00' + localeTimeString.slice(2);
}
return localeTimeString;
};
exports.formatTimeString = formatTimeString;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["timeFormatting/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,IAAM,gBAAgB,GAAG,UAAC,IAAU,EAAE,WAAqB,EAAE,SAAmB;IACrF,IAAI,gBAAgB,GAAG,IAAI,CAAC,kBAAkB,CAAC,EAAE,EAAE;QACjD,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC3C,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACxD,gBAAgB,GAAG,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B","sourcesContent":["/**\n * Format a date object to a localized time string using the browser's default locale\n * @param date - Input date to format\n * @param showSeconds - Whether to show seconds in the formatted string\n * @param useHour12 - Whether to use 12-hour time\n */\nexport const formatTimeString = (date: Date, showSeconds?: boolean, useHour12?: boolean): string => {\n let localeTimeString = date.toLocaleTimeString([], {\n hour: 'numeric',\n minute: '2-digit',\n second: showSeconds ? '2-digit' : undefined,\n hour12: useHour12,\n });\n\n if (!useHour12 && localeTimeString.slice(0, 2) === '24') {\n localeTimeString = '00' + localeTimeString.slice(2);\n }\n\n return localeTimeString;\n};\n"]}
@@ -0,0 +1,23 @@
/**
* Returns a date offset from the given date by the specified number of minutes.
* @param date - The origin date
* @param minutes - The number of minutes to offset. 'minutes' can be negative.
* @returns A new Date object offset from the origin date by the given number of minutes
*/
export declare const addMinutes: (date: Date, minutes: number) => Date;
/**
* Rounds the date's minute up to the next available increment. For example, if `date` has time 1:21
* and `increments` is 5, the resulting time will be 1:25.
* @param date - Date to ceil minutes
* @param increments - Time increments
* @returns Date with ceiled minute
*/
export declare const ceilMinuteToIncrement: (date: Date, increments: number) => Date;
/**
* Returns a date object from the selected time.
* @param useHour12 - If the time picker uses 12 or 24 hour formatting
* @param dateStartAnchor - The baseline date to calculate the offset of the selected time
* @param selectedTime - A string representing the user selected time
* @returns A new date object offset from the baseDate using the selected time.
*/
export declare const getDateFromTimeSelection: (useHour12: boolean, dateStartAnchor: Date, selectedTime: string) => Date;
@@ -0,0 +1,79 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDateFromTimeSelection = exports.ceilMinuteToIncrement = exports.addMinutes = void 0;
var timeConstants_1 = require("../dateValues/timeConstants");
/**
* Returns a date offset from the given date by the specified number of minutes.
* @param date - The origin date
* @param minutes - The number of minutes to offset. 'minutes' can be negative.
* @returns A new Date object offset from the origin date by the given number of minutes
*/
var addMinutes = function (date, minutes) {
var result = new Date(date.getTime());
result.setTime(result.getTime() + minutes * timeConstants_1.TimeConstants.MinutesInOneHour * timeConstants_1.TimeConstants.MillisecondsIn1Sec);
return result;
};
exports.addMinutes = addMinutes;
/**
* Rounds the date's minute up to the next available increment. For example, if `date` has time 1:21
* and `increments` is 5, the resulting time will be 1:25.
* @param date - Date to ceil minutes
* @param increments - Time increments
* @returns Date with ceiled minute
*/
var ceilMinuteToIncrement = function (date, increments) {
var result = new Date(date.getTime());
var minute = result.getMinutes();
if (timeConstants_1.TimeConstants.MinutesInOneHour % increments) {
result.setMinutes(0);
}
else {
var times = timeConstants_1.TimeConstants.MinutesInOneHour / increments;
for (var i = 1; i <= times; i++) {
if (minute > increments * (i - 1) && minute <= increments * i) {
minute = increments * i;
break;
}
}
result.setMinutes(minute);
}
return result;
};
exports.ceilMinuteToIncrement = ceilMinuteToIncrement;
/**
* Returns a date object from the selected time.
* @param useHour12 - If the time picker uses 12 or 24 hour formatting
* @param dateStartAnchor - The baseline date to calculate the offset of the selected time
* @param selectedTime - A string representing the user selected time
* @returns A new date object offset from the baseDate using the selected time.
*/
var getDateFromTimeSelection = function (useHour12, dateStartAnchor, selectedTime) {
var _a = timeConstants_1.TimeConstants.TimeFormatRegex.exec(selectedTime) || [], selectedHours = _a[1], selectedMinutes = _a[2], selectedSeconds = _a[3], selectedAp = _a[4];
var hours = +selectedHours;
var minutes = +selectedMinutes;
var seconds = selectedSeconds ? +selectedSeconds : 0;
if (useHour12 && selectedAp) {
if (selectedAp.toLowerCase() === 'pm' && hours !== timeConstants_1.TimeConstants.OffsetTo24HourFormat) {
hours += timeConstants_1.TimeConstants.OffsetTo24HourFormat;
}
else if (selectedAp.toLowerCase() === 'am' && hours === timeConstants_1.TimeConstants.OffsetTo24HourFormat) {
hours -= timeConstants_1.TimeConstants.OffsetTo24HourFormat;
}
}
var hoursOffset;
if (dateStartAnchor.getHours() > hours ||
(dateStartAnchor.getHours() === hours && dateStartAnchor.getMinutes() > minutes)) {
hoursOffset = timeConstants_1.TimeConstants.HoursInOneDay - dateStartAnchor.getHours() + hours;
}
else {
hoursOffset = Math.abs(dateStartAnchor.getHours() - hours);
}
var offset = timeConstants_1.TimeConstants.MillisecondsIn1Sec * timeConstants_1.TimeConstants.MinutesInOneHour * hoursOffset * timeConstants_1.TimeConstants.SecondsInOneMinute +
seconds * timeConstants_1.TimeConstants.MillisecondsIn1Sec;
var date = new Date(dateStartAnchor.getTime() + offset);
date.setMinutes(minutes);
date.setSeconds(seconds);
return date;
};
exports.getDateFromTimeSelection = getDateFromTimeSelection;
//# sourceMappingURL=timeMath.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export {};
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Do not modify this file; it is generated as part of publish.
// The checked in version is a placeholder only and will not be updated.
var set_version_1 = require("@fluentui/set-version");
(0, set_version_1.setVersion)('@fluentui/date-time-utilities', '8.6.11');
//# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"../src/","sources":["version.ts"],"names":[],"mappings":";;AAAA,+DAA+D;AAC/D,wEAAwE;AACxE,qDAAmD;AACnD,IAAA,wBAAU,EAAC,+BAA+B,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["// Do not modify this file; it is generated as part of publish.\n// The checked in version is a placeholder only and will not be updated.\nimport { setVersion } from '@fluentui/set-version';\nsetVersion('@fluentui/date-time-utilities', '8.6.11');"]}