clashofclans.js 3.4.2-dev.559ce53 → 3.4.3-dev.fd394cc

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.
@@ -33,7 +33,9 @@ export declare class Util extends null {
33
33
  static formatDate(date: string): Date;
34
34
  /** Returns a string containing a query string suitable for use in a URL. */
35
35
  static queryString(options?: SearchOptions | ClanSearchOptions): string;
36
+ /** @deprecated Use getSeason instead */
36
37
  static getSeasonStart(inputDate: Date): Date;
38
+ /** @deprecated Use getSeason instead */
37
39
  static getSeasonEnd(inputDate: Date, forward?: boolean): Date;
38
40
  /** Get the current season ID. */
39
41
  static getSeasonId(): string;
@@ -45,6 +47,7 @@ export declare class Util extends null {
45
47
  static getSeason(timestamp?: Date, forward?: boolean): {
46
48
  endTime: Date;
47
49
  startTime: Date;
50
+ seasonId: string;
48
51
  };
49
52
  static allSettled<T>(values: Promise<T>[]): Promise<T[]>;
50
53
  static delay(ms: number): Promise<unknown>;
package/dist/util/Util.js CHANGED
@@ -95,6 +95,7 @@ class Util extends null {
95
95
  const query = new URLSearchParams(Object.entries(options).filter(([key]) => params.includes(key))).toString();
96
96
  return query.length ? `?${query}` : query;
97
97
  }
98
+ /** @deprecated Use getSeason instead */
98
99
  static getSeasonStart(inputDate) {
99
100
  const lastMonthLastDay = new Date(Date.UTC(inputDate.getUTCFullYear(), inputDate.getUTCMonth(), 0));
100
101
  const lastMonthLastMonday = new Date(lastMonthLastDay);
@@ -102,6 +103,7 @@ class Util extends null {
102
103
  lastMonthLastMonday.setUTCHours(5, 0, 0, 0);
103
104
  return lastMonthLastMonday;
104
105
  }
106
+ /** @deprecated Use getSeason instead */
105
107
  static getSeasonEnd(inputDate, forward = true) {
106
108
  const lastDayOfMonth = new Date(Date.UTC(inputDate.getUTCFullYear(), inputDate.getUTCMonth() + 1, 0));
107
109
  const lastMonday = new Date(lastDayOfMonth);
@@ -121,7 +123,7 @@ class Util extends null {
121
123
  }
122
124
  /** Get the current season ID. */
123
125
  static getSeasonId() {
124
- return this.getSeasonEnd(new Date()).toISOString().slice(0, 7);
126
+ return this.getSeason(new Date()).seasonId;
125
127
  }
126
128
  /**
127
129
  * Get the season start and end timestamp.
@@ -129,9 +131,34 @@ class Util extends null {
129
131
  * @param {boolean} forward - Whether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.
130
132
  */
131
133
  static getSeason(timestamp, forward = true) {
132
- const endTime = this.getSeasonEnd(timestamp ?? new Date(), forward);
133
- const startTime = this.getSeasonStart(endTime);
134
- return { endTime, startTime };
134
+ const target = timestamp ?? new Date();
135
+ if (target < new Date('2025-08-25T05:00:00.000Z')) {
136
+ const endTime = this.getSeasonEnd(timestamp ?? new Date(), forward);
137
+ const startTime = this.getSeasonStart(endTime);
138
+ return { endTime, startTime, seasonId: endTime.toISOString().slice(0, 7) };
139
+ }
140
+ if (target > new Date('2025-08-25T05:00:00.000Z') && target <= new Date('2025-10-06T05:00:00.000Z')) {
141
+ return {
142
+ startTime: new Date('2025-08-25T05:00:00.000Z'),
143
+ endTime: new Date('2025-10-06T05:00:00.000Z'),
144
+ seasonId: '2025-09'
145
+ };
146
+ }
147
+ // After 6th October 2025, season ends every 4 weeks
148
+ const seasonDuration = 7 * 4 * 24 * 60 * 60 * 1000;
149
+ const referenceDate = new Date('2025-10-06T05:00:00.000Z');
150
+ const timeDifference = target.getTime() - referenceDate.getTime();
151
+ const seasonsPassed = Math.floor(timeDifference / seasonDuration);
152
+ const startTime = new Date(referenceDate.getTime() + seasonsPassed * seasonDuration);
153
+ const endTime = new Date(startTime.getTime() + seasonDuration);
154
+ // "month" increments by 1 each season starting from referenceDate's month
155
+ const refYear = referenceDate.getUTCFullYear();
156
+ const refMonthIndex = referenceDate.getUTCMonth(); // 0-based (Oct -> 9)
157
+ const totalMonths = refYear * 12 + refMonthIndex + seasonsPassed;
158
+ const year = Math.floor(totalMonths / 12);
159
+ const month = totalMonths - year * 12 + 1; // 1..12
160
+ const seasonId = `${year}-${String(month).padStart(2, '0')}`;
161
+ return { startTime, endTime, seasonId };
135
162
  }
136
163
  static async allSettled(values) {
137
164
  return (await Promise.allSettled(values))
package/dist/util.spec.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ process.env.TZ = 'UTC';
3
4
  const Util_1 = require("./util/Util");
4
5
  describe('util', () => {
5
6
  it('should always be UTC', () => {
@@ -31,10 +32,56 @@ describe('util', () => {
31
32
  });
32
33
  it('should forward to the next year at the end of the year', async () => {
33
34
  const timestamp = new Date('2024-12-30T05:01');
34
- const { endTime, startTime } = Util_1.Util.getSeason(timestamp);
35
- const expectedEndTime = new Date('2025-01-27T05:00').toISOString();
35
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
36
36
  const expectedStartTime = new Date('2024-12-30T05:00').toISOString();
37
+ const expectedEndTime = new Date('2025-01-27T05:00').toISOString();
38
+ expect(endTime.toISOString()).toBe(expectedEndTime);
39
+ expect(startTime.toISOString()).toBe(expectedStartTime);
40
+ expect(seasonId).toBe('2025-01');
41
+ });
42
+ it('should pass October 2025', async () => {
43
+ const timestamp = new Date('2025-10-20T05:00');
44
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
45
+ const expectedEndTime = new Date('2025-11-03T05:00').toISOString();
46
+ const expectedStartTime = new Date('2025-10-06T05:00').toISOString();
47
+ expect(endTime.toISOString()).toBe(expectedEndTime);
48
+ expect(startTime.toISOString()).toBe(expectedStartTime);
49
+ expect(seasonId).toBe('2025-10');
50
+ });
51
+ it('should pass November 2025', async () => {
52
+ const timestamp = new Date('2025-11-20T05:00');
53
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
54
+ const expectedStartTime = new Date('2025-11-03T05:00').toISOString();
55
+ const expectedEndTime = new Date('2025-12-01T05:00').toISOString();
56
+ expect(startTime.toISOString()).toBe(expectedStartTime);
37
57
  expect(endTime.toISOString()).toBe(expectedEndTime);
58
+ expect(seasonId).toBe('2025-11');
59
+ });
60
+ it('should pass December 2025', async () => {
61
+ const timestamp = new Date('2025-12-01T05:00');
62
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
63
+ const expectedStartTime = new Date('2025-12-01T05:00').toISOString();
64
+ const expectedEndTime = new Date('2025-12-29T05:00').toISOString();
65
+ expect(startTime.toISOString()).toBe(expectedStartTime);
66
+ expect(endTime.toISOString()).toBe(expectedEndTime);
67
+ expect(seasonId).toBe('2025-12');
68
+ });
69
+ it('should pass Jan 2026', async () => {
70
+ const timestamp = new Date('2026-01-01T05:00');
71
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
72
+ const expectedStartTime = new Date('2025-12-29T05:00').toISOString();
73
+ const expectedEndTime = new Date('2026-01-26T05:00').toISOString();
38
74
  expect(startTime.toISOString()).toBe(expectedStartTime);
75
+ expect(endTime.toISOString()).toBe(expectedEndTime);
76
+ expect(seasonId).toBe('2026-01');
77
+ });
78
+ it('should pass Feb 2026', async () => {
79
+ const timestamp = new Date('2026-01-27T05:00');
80
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeason(timestamp);
81
+ const expectedStartTime = new Date('2026-01-26T05:00').toISOString();
82
+ const expectedEndTime = new Date('2026-02-23T05:00').toISOString();
83
+ expect(startTime.toISOString()).toBe(expectedStartTime);
84
+ expect(endTime.toISOString()).toBe(expectedEndTime);
85
+ expect(seasonId).toBe('2026-02');
39
86
  });
40
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.4.2-dev.559ce53",
3
+ "version": "3.4.3-dev.fd394cc",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",