@tailgatefantasysports/seasonservice 0.4.21 → 0.5.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.
package/SeasonService.js CHANGED
@@ -93,6 +93,29 @@ module.exports = class SeasonService {
93
93
  return full;
94
94
  }
95
95
 
96
+ /**
97
+ * Returns the regular season frame for a given season year, or null if not configured.
98
+ * @param {string|number} seasonYear
99
+ * @returns {{ season: string, type: string, start: Date, end: Date }|null}
100
+ */
101
+ getRegularSeason(seasonYear) {
102
+ const frames = this.timeframes[seasonYear];
103
+ if (!frames) return null;
104
+ const types = require('./types');
105
+ const frame = frames[types.regular] || frames['regular'];
106
+ if (!frame) return null;
107
+ return { season: String(seasonYear), type: types.regular, ...frame };
108
+ }
109
+
110
+ /**
111
+ * Returns the total number of weeks in the regular season for a given season object.
112
+ * @param {{ season: string, start: Date, end: Date }} season - regular season frame
113
+ * @returns {number}
114
+ */
115
+ getTotalWeeks(season) {
116
+ return Math.round((season.end - season.start) / this._weekInMs);
117
+ }
118
+
96
119
  /**
97
120
  * Walks to a nearby season from date in direction
98
121
  * @param {number} direction - direction to get season (1 for next, -1 for previous)
@@ -7,7 +7,9 @@ describe('Service', () => {
7
7
  ['2020 Post', new Date('2021-01-20T00:00:00Z'), '2020', 2, new Date('2021-01-07T00:00:00Z'), new Date('2021-02-07T00:00:00Z')],
8
8
  ['2021 Beta', new Date('2021-06-20T00:00:00Z'), 'BETA', 'beta', new Date('2021-06-16T00:00:00Z'), new Date('2021-08-05T00:00:00Z')],
9
9
  ['2021 Regular', new Date('2021-09-10T00:00:00Z'), '2021', 1, new Date('2021-09-08T00:00:00Z'), new Date('2022-01-12T00:00:00Z')],
10
- ['2021 Post', new Date('2022-01-20T00:00:00Z'), '2021', 2, new Date('2022-01-12T00:00:00Z'), new Date('2022-02-15T00:00:00Z')]
10
+ ['2021 Post', new Date('2022-01-20T00:00:00Z'), '2021', 2, new Date('2022-01-12T00:00:00Z'), new Date('2022-02-15T00:00:00Z')],
11
+ ['2026 Preseason', new Date('2026-08-13T23:00:00Z'), '2026', 0, new Date('2026-08-12T00:00:00Z'), new Date('2026-09-02T00:00:00Z')],
12
+ ['2026 Regular', new Date('2026-10-11T23:00:00Z'), '2026', 1, new Date('2026-09-09T00:00:00Z'), new Date('2027-01-13T00:00:00Z')]
11
13
  ])('%s', (_tName, date, season, type, start, end) => {
12
14
  let frame = SeasonService.getSeason(date);
13
15
  expect(frame.season).toBe(season);
@@ -15,6 +17,34 @@ describe('Service', () => {
15
17
  expect(frame.start).toStrictEqual(start);
16
18
  expect(frame.end).toStrictEqual(end);
17
19
  });
20
+
21
+ // The Aug 6 Hall of Fame game sits outside the preseason frame on
22
+ // purpose — the game sync drops it, so week 1 is the Aug 13-15 slate.
23
+ test('2026 Hall of Fame game is outside the preseason frame', () => {
24
+ expect(SeasonService.getSeason(new Date('2026-08-06T23:00:00Z'))).toBeUndefined();
25
+ });
26
+ });
27
+
28
+ // Each frame's weeks must line up with the provider's week numbering:
29
+ // dates below are the first and last day of each slate on the real 2026
30
+ // schedule, at 7pm ET.
31
+ describe('Get Week — 2026 slates match provider weeks', () => {
32
+ test.each([
33
+ ['Preseason Week 1 open', new Date('2026-08-13T23:00:00Z'), 1],
34
+ ['Preseason Week 1 close', new Date('2026-08-15T23:00:00Z'), 1],
35
+ ['Preseason Week 2 open', new Date('2026-08-20T23:00:00Z'), 2],
36
+ ['Preseason Week 2 close', new Date('2026-08-23T23:00:00Z'), 2],
37
+ ['Preseason Week 3 open', new Date('2026-08-27T23:00:00Z'), 3],
38
+ ['Preseason Week 3 close', new Date('2026-08-29T23:00:00Z'), 3],
39
+ ['Regular Week 1 open', new Date('2026-09-09T23:00:00Z'), 1],
40
+ ['Regular Week 1 close', new Date('2026-09-14T23:00:00Z'), 1],
41
+ ['Regular Week 2 open', new Date('2026-09-17T23:00:00Z'), 2],
42
+ ['Regular Week 17 open', new Date('2026-12-31T23:00:00Z'), 17],
43
+ ['Regular Week 17 close', new Date('2027-01-04T23:00:00Z'), 17],
44
+ ['Regular Week 18', new Date('2027-01-10T23:00:00Z'), 18]
45
+ ])('%s', (_tName, date, week) => {
46
+ expect(SeasonService.getWeek(date).week).toBe(week);
47
+ });
18
48
  });
19
49
  });
20
50
 
package/app.config.js CHANGED
@@ -89,12 +89,17 @@ module.exports = {
89
89
  }
90
90
  },
91
91
  2026: {
92
+ // Frames start the Wednesday 00:00Z before their week 1 games so the
93
+ // service's week N matches the provider's week N. The Aug 6 Hall of
94
+ // Fame game is intentionally outside the preseason frame — the game
95
+ // sync filters it out (its "Hall of Fame Weekend" label has no week
96
+ // number), so preseason week 1 is the Aug 13-15 slate.
92
97
  [types.preseason]: {
93
- start: new Date('2026-08-05T00:00:00Z'),
94
- end: new Date('2026-09-06T00:00:00Z')
98
+ start: new Date('2026-08-12T00:00:00Z'),
99
+ end: new Date('2026-09-02T00:00:00Z')
95
100
  },
96
101
  [types.regular]: {
97
- start: new Date('2026-09-06T00:00:00Z'),
102
+ start: new Date('2026-09-09T00:00:00Z'),
98
103
  end: new Date('2027-01-13T00:00:00Z'),
99
104
  },
100
105
  [types.postseason]: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailgatefantasysports/seasonservice",
3
- "version": "0.4.21",
3
+ "version": "0.5.1",
4
4
  "description": "Generic Season Service",
5
5
  "main": "index.js",
6
6
  "scripts": {