UNPKG

905 BJavaScriptView Raw
1import { constructFrom } from "./constructFrom.js";
2import { constructNow } from "./constructNow.js";
3import { isSameYear } from "./isSameYear.js";
4
5/**
6 * The {@link isThisYear} function options.
7 */
8
9/**
10 * @name isThisYear
11 * @category Year Helpers
12 * @summary Is the given date in the same year as the current date?
13 * @pure false
14 *
15 * @description
16 * Is the given date in the same year as the current date?
17 *
18 * @param date - The date to check
19 * @param options - An object with options
20 *
21 * @returns The date is in this year
22 *
23 * @example
24 * // If today is 25 September 2014, is 2 July 2014 in this year?
25 * const result = isThisYear(new Date(2014, 6, 2))
26 * //=> true
27 */
28export function isThisYear(date, options) {
29 return isSameYear(
30 constructFrom(options?.in || date, date),
31 constructNow(options?.in || date),
32 );
33}
34
35// Fallback for modularized imports:
36export default isThisYear;