Skip to content

Commit 287b8dc

Browse files
feat: add getWeek (#673)
* feat: getWeek * fix: Codecov * chore: Get coverage back to 100% --------- Co-authored-by: Dmitriy Kovalenko <[email protected]>
1 parent 4fe3848 commit 287b8dc

File tree

15 files changed

+106
-3
lines changed

15 files changed

+106
-3
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ jobs:
2828
run: yarn build
2929
- name: Test
3030
run: yarn test:coverage
31-
- name: Upload codecov
32-
run: npx codecov
31+
- uses: codecov/codecov-action@v5
32+
with:
33+
fail_ci_if_error: true
34+
flags: unittests
35+
token: ${{ secrets.CODECOV_TOKEN }}

__tests__/calculations.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ describe("DateTime calculations", () => {
178178
expect(utils.getYear(date)).toBe(2018);
179179
});
180180

181+
utilsTest("getWeek", (date, utils) => {
182+
expect(utils.getWeek(date)).toBe(44);
183+
});
184+
181185
utilsTest("getMonth", (date, utils) => {
182186
expect(utils.getMonth(date)).toBe(9);
183187
});

__tests__/date-fns-jalali.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ describe("DateFnsJalali", () => {
277277
}
278278
});
279279

280+
it("DateFnsJalali -- getWeek", () => {
281+
expect(utils.getWeek(date)).toBe(33);
282+
});
283+
280284
it("DateFnsJalali -- getYearRange", () => {
281285
const yearRange = utils.getYearRange(date, utils.setYear(date, 1503));
282286

__tests__/hijri.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ describe("Hijri", () => {
214214
);
215215
});
216216

217+
it("Hijiri -- getWeek", () => {
218+
const date = hijriiUtils.date(TEST_TIMESTAMP);
219+
220+
expect(hijriiUtils.getWeek(date)).toBe(44);
221+
});
222+
217223
test.each`
218224
format | expected
219225
${"keyboardDate"} | ${"١٤٤١/٠٥/٠٦"}

__tests__/jalaali.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,54 @@ describe("Jalaali", () => {
213213
]);
214214
});
215215

216+
it("Jalaali -- getWeek", () => {
217+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
218+
219+
expect(jalaaliUtils.getWeek(date)).toEqual(44);
220+
});
221+
222+
it("Jalaali -- addMonths", () => {
223+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
224+
const newDate = jalaaliUtils.addMonths(date, 2);
225+
226+
expect(jalaaliUtils.getMonth(newDate)).toBe(9);
227+
});
228+
229+
it("Jalaali -- addYears", () => {
230+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
231+
const newDate = jalaaliUtils.addYears(date, 2);
232+
233+
expect(jalaaliUtils.getYear(newDate)).toBe(1399);
234+
});
235+
236+
it("Jalaali -- isSameMonth", () => {
237+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
238+
const anotherDate = jalaaliUtils.date(TEST_TIMESTAMP);
239+
240+
expect(jalaaliUtils.isSameMonth(date, anotherDate)).toBeTruthy();
241+
});
242+
243+
it("Jalaali -- isSameYear", () => {
244+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
245+
const anotherDate = jalaaliUtils.date(TEST_TIMESTAMP);
246+
247+
expect(jalaaliUtils.isSameYear(date, anotherDate)).toBeTruthy();
248+
});
249+
250+
it("Jalaali -- setMonth", () => {
251+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
252+
const newDate = jalaaliUtils.setMonth(date, 0);
253+
254+
expect(jalaaliUtils.getMonth(newDate)).toBe(0);
255+
});
256+
257+
it("Jalaali -- getMonthArray", () => {
258+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
259+
const array = jalaaliUtils.getMonthArray(date);
260+
261+
expect(array.map((dt) => dt.month())).toEqual([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1]);
262+
});
263+
216264
it("Jalaali -- getYearRange", () => {
217265
const date = jalaaliUtils.date(TEST_TIMESTAMP);
218266
const anotherYear = jalaaliUtils.setYear(date, 1400);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@types/jest": "^26.0.0",
3737
"cldr-data": "^36.0.0",
3838
"cldrjs": "^0.5.5",
39-
"codecov": "^3.6.1",
4039
"dayjs": "^1.8.17",
4140
"full-icu": "^1.3.0",
4241
"husky": "^5.0.9",

packages/core/IUtils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export interface IUtils<TDate, TLocale> {
173173
getDate(value: TDate): number;
174174
setDate(value: TDate, count: number): TDate;
175175

176+
getWeek(value: TDate): number;
176177
getMonth(value: TDate): number;
177178
getDaysInMonth(value: TDate): number;
178179
setMonth(value: TDate, count: number): TDate;

packages/date-fns-jalali/src/date-fns-jalali-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { formatISO } from "date-fns-jalali/formatISO";
2323
import { getHours } from "date-fns-jalali/getHours";
2424
import { getSeconds } from "date-fns-jalali/getSeconds";
2525
import { getYear } from "date-fns-jalali/getYear";
26+
import { getWeek } from "date-fns-jalali/getWeek";
2627
import { getMonth } from "date-fns-jalali/getMonth";
2728
import { getDate } from "date-fns-jalali/getDate";
2829
import { getDay } from "date-fns-jalali/getDay";
@@ -398,6 +399,10 @@ export default class DateFnsJalaliUtils implements IUtils<Date, Locale> {
398399
return getMinutes(date);
399400
};
400401

402+
public getWeek = (date: Date) => {
403+
return getWeek(date);
404+
};
405+
401406
public getMonth = (date: Date) => {
402407
return getMonth(date);
403408
};

packages/date-fns/src/date-fns-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getDay } from "date-fns/getDay";
2424
import { getDaysInMonth } from "date-fns/getDaysInMonth";
2525
import { getHours } from "date-fns/getHours";
2626
import { getMinutes } from "date-fns/getMinutes";
27+
import { getWeek } from "date-fns/getWeek";
2728
import { getMonth } from "date-fns/getMonth";
2829
import { getSeconds } from "date-fns/getSeconds";
2930
import { getYear } from "date-fns/getYear";
@@ -383,6 +384,10 @@ export default class DateFnsUtils implements IUtils<Date, Locale> {
383384
return setDate(date, count);
384385
};
385386

387+
public getWeek = (date: Date) => {
388+
return getWeek(date);
389+
};
390+
386391
public getMonth = (date: Date) => {
387392
return getMonth(date);
388393
};

packages/dayjs/src/dayjs-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import defaultDayjs, { QUnitType } from "dayjs";
22
import customParseFormatPlugin from "dayjs/plugin/customParseFormat";
33
import localizedFormatPlugin from "dayjs/plugin/localizedFormat";
44
import isBetweenPlugin from "dayjs/plugin/isBetween";
5+
import weekOfYear from "dayjs/plugin/weekOfYear";
56
import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils";
67

78
defaultDayjs.extend(customParseFormatPlugin);
89
defaultDayjs.extend(localizedFormatPlugin);
910
defaultDayjs.extend(isBetweenPlugin);
11+
defaultDayjs.extend(weekOfYear);
1012

1113
interface Opts {
1214
locale?: string;
@@ -282,6 +284,10 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs>
282284
return date.set("second", count) as TDate;
283285
};
284286

287+
public getWeek = (date: Dayjs) => {
288+
return date.week();
289+
};
290+
285291
public getMonth = (date: Dayjs) => {
286292
return date.month();
287293
};

0 commit comments

Comments
 (0)