chuvsu-js 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,12 +2,15 @@ import { Period } from "../../common/types.js";
|
|
|
2
2
|
import type { SemesterWeek } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Start date of a semester.
|
|
5
|
-
* Fall: September 1 of the
|
|
6
|
-
* Spring: first Monday of February of the
|
|
5
|
+
* Fall: September 1 of the semester year.
|
|
6
|
+
* Spring: first Monday of February of the semester year.
|
|
7
|
+
* If year is omitted, the semester year is derived from the current
|
|
8
|
+
* academic year instead of the calendar year.
|
|
7
9
|
*/
|
|
8
10
|
export declare function getSemesterStart(opts: {
|
|
9
11
|
period: Period;
|
|
10
12
|
year?: number;
|
|
13
|
+
date?: Date;
|
|
11
14
|
}): Date;
|
|
12
15
|
/**
|
|
13
16
|
* All weeks in a semester with their start/end dates.
|
|
@@ -16,10 +19,12 @@ export declare function getSemesterStart(opts: {
|
|
|
16
19
|
export declare function getSemesterWeeks(opts: {
|
|
17
20
|
period: Period;
|
|
18
21
|
year?: number;
|
|
22
|
+
date?: Date;
|
|
19
23
|
weekCount?: number;
|
|
20
24
|
}): SemesterWeek[];
|
|
21
25
|
/** Current week number within a semester. */
|
|
22
26
|
export declare function getWeekNumber(opts: {
|
|
23
27
|
period: Period;
|
|
28
|
+
year?: number;
|
|
24
29
|
date?: Date;
|
|
25
30
|
}): number;
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { getMonday } from "./date.js";
|
|
2
|
+
function getAcademicYearStartYear(date) {
|
|
3
|
+
const year = date.getFullYear();
|
|
4
|
+
const month = date.getMonth();
|
|
5
|
+
// Academic year starts in September.
|
|
6
|
+
return month >= 8 ? year : year - 1;
|
|
7
|
+
}
|
|
8
|
+
function resolveSemesterYear(opts) {
|
|
9
|
+
if (opts.year != null)
|
|
10
|
+
return opts.year;
|
|
11
|
+
const baseDate = opts.date ?? new Date();
|
|
12
|
+
const academicYearStart = getAcademicYearStartYear(baseDate);
|
|
13
|
+
return opts.period === 1 /* Period.FallSemester */
|
|
14
|
+
? academicYearStart
|
|
15
|
+
: academicYearStart + 1;
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Start date of a semester.
|
|
4
|
-
* Fall: September 1 of the
|
|
5
|
-
* Spring: first Monday of February of the
|
|
19
|
+
* Fall: September 1 of the semester year.
|
|
20
|
+
* Spring: first Monday of February of the semester year.
|
|
21
|
+
* If year is omitted, the semester year is derived from the current
|
|
22
|
+
* academic year instead of the calendar year.
|
|
6
23
|
*/
|
|
7
24
|
export function getSemesterStart(opts) {
|
|
8
|
-
const year = opts
|
|
25
|
+
const year = resolveSemesterYear(opts);
|
|
9
26
|
if (opts.period === 1 /* Period.FallSemester */) {
|
|
10
27
|
return new Date(year, 8, 1); // September 1
|
|
11
28
|
}
|
|
@@ -39,7 +56,7 @@ export function getSemesterWeeks(opts) {
|
|
|
39
56
|
/** Current week number within a semester. */
|
|
40
57
|
export function getWeekNumber(opts) {
|
|
41
58
|
const date = opts.date ?? new Date();
|
|
42
|
-
const semesterStart = getSemesterStart(opts);
|
|
59
|
+
const semesterStart = getSemesterStart({ ...opts, date });
|
|
43
60
|
const startMonday = getMonday(semesterStart);
|
|
44
61
|
const targetMonday = getMonday(date);
|
|
45
62
|
const diff = targetMonday.getTime() - startMonday.getTime();
|