diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 55a68472..2c84c92f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,5 +28,8 @@ jobs: run: yarn build - name: Test run: yarn test:coverage - - name: Upload codecov - run: npx codecov + - uses: codecov/codecov-action@v5 + with: + fail_ci_if_error: true + flags: unittests + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/__tests__/calculations.test.ts b/__tests__/calculations.test.ts index de5e6f10..768278f1 100644 --- a/__tests__/calculations.test.ts +++ b/__tests__/calculations.test.ts @@ -178,6 +178,10 @@ describe("DateTime calculations", () => { expect(utils.getYear(date)).toBe(2018); }); + utilsTest("getWeek", (date, utils) => { + expect(utils.getWeek(date)).toBe(44); + }); + utilsTest("getMonth", (date, utils) => { expect(utils.getMonth(date)).toBe(9); }); diff --git a/__tests__/date-fns-jalali.test.ts b/__tests__/date-fns-jalali.test.ts index 0336aabd..9de72b2b 100644 --- a/__tests__/date-fns-jalali.test.ts +++ b/__tests__/date-fns-jalali.test.ts @@ -277,6 +277,10 @@ describe("DateFnsJalali", () => { } }); + it("DateFnsJalali -- getWeek", () => { + expect(utils.getWeek(date)).toBe(33); + }); + it("DateFnsJalali -- getYearRange", () => { const yearRange = utils.getYearRange(date, utils.setYear(date, 1503)); diff --git a/__tests__/hijri.test.ts b/__tests__/hijri.test.ts index 3646559c..9091dc64 100644 --- a/__tests__/hijri.test.ts +++ b/__tests__/hijri.test.ts @@ -214,6 +214,12 @@ describe("Hijri", () => { ); }); + it("Hijiri -- getWeek", () => { + const date = hijriiUtils.date(TEST_TIMESTAMP); + + expect(hijriiUtils.getWeek(date)).toBe(44); + }); + test.each` format | expected ${"keyboardDate"} | ${"١٤٤١/٠٥/٠٦"} diff --git a/__tests__/jalaali.test.ts b/__tests__/jalaali.test.ts index 91794d4f..fed7c0eb 100644 --- a/__tests__/jalaali.test.ts +++ b/__tests__/jalaali.test.ts @@ -213,6 +213,54 @@ describe("Jalaali", () => { ]); }); + it("Jalaali -- getWeek", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + + expect(jalaaliUtils.getWeek(date)).toEqual(44); + }); + + it("Jalaali -- addMonths", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const newDate = jalaaliUtils.addMonths(date, 2); + + expect(jalaaliUtils.getMonth(newDate)).toBe(9); + }); + + it("Jalaali -- addYears", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const newDate = jalaaliUtils.addYears(date, 2); + + expect(jalaaliUtils.getYear(newDate)).toBe(1399); + }); + + it("Jalaali -- isSameMonth", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const anotherDate = jalaaliUtils.date(TEST_TIMESTAMP); + + expect(jalaaliUtils.isSameMonth(date, anotherDate)).toBeTruthy(); + }); + + it("Jalaali -- isSameYear", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const anotherDate = jalaaliUtils.date(TEST_TIMESTAMP); + + expect(jalaaliUtils.isSameYear(date, anotherDate)).toBeTruthy(); + }); + + it("Jalaali -- setMonth", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const newDate = jalaaliUtils.setMonth(date, 0); + + expect(jalaaliUtils.getMonth(newDate)).toBe(0); + }); + + it("Jalaali -- getMonthArray", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const array = jalaaliUtils.getMonthArray(date); + + expect(array.map((dt) => dt.month())).toEqual([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1]); + }); + it("Jalaali -- getYearRange", () => { const date = jalaaliUtils.date(TEST_TIMESTAMP); const anotherYear = jalaaliUtils.setYear(date, 1400); diff --git a/package.json b/package.json index 31cd44f4..6f36562c 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "@types/jest": "^26.0.0", "cldr-data": "^36.0.0", "cldrjs": "^0.5.5", - "codecov": "^3.6.1", "dayjs": "^1.8.17", "full-icu": "^1.3.0", "husky": "^5.0.9", diff --git a/packages/core/IUtils.d.ts b/packages/core/IUtils.d.ts index 09cb3fd9..f985e135 100644 --- a/packages/core/IUtils.d.ts +++ b/packages/core/IUtils.d.ts @@ -173,6 +173,7 @@ export interface IUtils { getDate(value: TDate): number; setDate(value: TDate, count: number): TDate; + getWeek(value: TDate): number; getMonth(value: TDate): number; getDaysInMonth(value: TDate): number; setMonth(value: TDate, count: number): TDate; diff --git a/packages/date-fns-jalali/src/date-fns-jalali-utils.ts b/packages/date-fns-jalali/src/date-fns-jalali-utils.ts index 428328f5..0df44a3a 100644 --- a/packages/date-fns-jalali/src/date-fns-jalali-utils.ts +++ b/packages/date-fns-jalali/src/date-fns-jalali-utils.ts @@ -23,6 +23,7 @@ import { formatISO } from "date-fns-jalali/formatISO"; import { getHours } from "date-fns-jalali/getHours"; import { getSeconds } from "date-fns-jalali/getSeconds"; import { getYear } from "date-fns-jalali/getYear"; +import { getWeek } from "date-fns-jalali/getWeek"; import { getMonth } from "date-fns-jalali/getMonth"; import { getDate } from "date-fns-jalali/getDate"; import { getDay } from "date-fns-jalali/getDay"; @@ -398,6 +399,10 @@ export default class DateFnsJalaliUtils implements IUtils { return getMinutes(date); }; + public getWeek = (date: Date) => { + return getWeek(date); + }; + public getMonth = (date: Date) => { return getMonth(date); }; diff --git a/packages/date-fns/src/date-fns-utils.ts b/packages/date-fns/src/date-fns-utils.ts index 58afe108..9f0cb7be 100644 --- a/packages/date-fns/src/date-fns-utils.ts +++ b/packages/date-fns/src/date-fns-utils.ts @@ -24,6 +24,7 @@ import { getDay } from "date-fns/getDay"; import { getDaysInMonth } from "date-fns/getDaysInMonth"; import { getHours } from "date-fns/getHours"; import { getMinutes } from "date-fns/getMinutes"; +import { getWeek } from "date-fns/getWeek"; import { getMonth } from "date-fns/getMonth"; import { getSeconds } from "date-fns/getSeconds"; import { getYear } from "date-fns/getYear"; @@ -383,6 +384,10 @@ export default class DateFnsUtils implements IUtils { return setDate(date, count); }; + public getWeek = (date: Date) => { + return getWeek(date); + }; + public getMonth = (date: Date) => { return getMonth(date); }; diff --git a/packages/dayjs/src/dayjs-utils.ts b/packages/dayjs/src/dayjs-utils.ts index 4e43588b..7d391c14 100644 --- a/packages/dayjs/src/dayjs-utils.ts +++ b/packages/dayjs/src/dayjs-utils.ts @@ -2,11 +2,13 @@ import defaultDayjs, { QUnitType } from "dayjs"; import customParseFormatPlugin from "dayjs/plugin/customParseFormat"; import localizedFormatPlugin from "dayjs/plugin/localizedFormat"; import isBetweenPlugin from "dayjs/plugin/isBetween"; +import weekOfYear from "dayjs/plugin/weekOfYear"; import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils"; defaultDayjs.extend(customParseFormatPlugin); defaultDayjs.extend(localizedFormatPlugin); defaultDayjs.extend(isBetweenPlugin); +defaultDayjs.extend(weekOfYear); interface Opts { locale?: string; @@ -282,6 +284,10 @@ export default class DayjsUtils return date.set("second", count) as TDate; }; + public getWeek = (date: Dayjs) => { + return date.week(); + }; + public getMonth = (date: Dayjs) => { return date.month(); }; diff --git a/packages/hijri/src/hijri-utils.ts b/packages/hijri/src/hijri-utils.ts index 21518df2..87974738 100644 --- a/packages/hijri/src/hijri-utils.ts +++ b/packages/hijri/src/hijri-utils.ts @@ -104,6 +104,10 @@ export default class MomentUtils extends DefaultMomentUtils { return date.iYear() > value.iYear(); }; + public getWeek = (date: Moment) => { + return date.get("week"); + }; + public getMonth = (date: Moment) => { return date.iMonth(); }; diff --git a/packages/jalaali/src/jalaali-utils.ts b/packages/jalaali/src/jalaali-utils.ts index 9600ffd2..6239a5c3 100644 --- a/packages/jalaali/src/jalaali-utils.ts +++ b/packages/jalaali/src/jalaali-utils.ts @@ -103,6 +103,10 @@ export default class MomentUtils extends DefaultMomentUtils { return date.jYear() > value.jYear(); }; + public getWeek = (date: Moment) => { + return date.get("week"); + }; + public getMonth = (date: Moment) => { return date.jMonth(); }; @@ -214,6 +218,7 @@ export default class MomentUtils extends DefaultMomentUtils { return years; }; + public addMonths = (date: Moment, count: number) => { return count < 0 ? date.clone().subtract(Math.abs(count), "jMonth") diff --git a/packages/js-joda/src/js-joda-utils.ts b/packages/js-joda/src/js-joda-utils.ts index 6773fe04..da4fea4c 100644 --- a/packages/js-joda/src/js-joda-utils.ts +++ b/packages/js-joda/src/js-joda-utils.ts @@ -399,6 +399,10 @@ export default class JsJodaUtils implements IUtils { return date.with(ChronoField.SECOND_OF_MINUTE, count); } + getWeek(date: Temporal): number { + return date.get(ChronoField.ALIGNED_WEEK_OF_YEAR); + } + getMonth(date: Temporal): number { return date.get(ChronoField.MONTH_OF_YEAR) - 1; } diff --git a/packages/luxon/src/luxon-utils.ts b/packages/luxon/src/luxon-utils.ts index 80faec9e..54a8aa45 100644 --- a/packages/luxon/src/luxon-utils.ts +++ b/packages/luxon/src/luxon-utils.ts @@ -72,6 +72,7 @@ export default class LuxonUtils implements IUtils { return DateTime.fromJSDate(value, { locale: this.locale }) as TRes; } + /* istanbul ignore next */ return DateTime.local() as TRes; } @@ -288,6 +289,10 @@ export default class LuxonUtils implements IUtils { return value.set({ second: count }); }; + public getWeek = (value: DateTime) => { + return value.get("weekNumber"); + }; + public getMonth = (value: DateTime) => { // See https://github.com/moment/luxon/blob/master/docs/moment.md#major-functional-differences return value.get("month") - 1; diff --git a/packages/moment/src/moment-utils.ts b/packages/moment/src/moment-utils.ts index f81b9d5d..a09a00f5 100644 --- a/packages/moment/src/moment-utils.ts +++ b/packages/moment/src/moment-utils.ts @@ -268,6 +268,10 @@ export default class MomentUtils implements IUtils return date.clone().seconds(count); }; + public getWeek = (date: Moment) => { + return date.get("week"); + }; + public getMonth = (date: Moment) => { return date.get("month"); };