@tmlmobilidade/dates 20260410.1049.29 → 20260411.1243.43

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.
@@ -23,17 +23,3 @@ export declare function buildRuleSummary(rule: ScheduleRule, options: {
23
23
  events?: Event[];
24
24
  periods?: YearPeriod[];
25
25
  }): RuleSummary;
26
- /**
27
- * GTFS-oriented rule token:
28
- * - FER_DU
29
- * - VER_SAB
30
- * - ESC_DOM
31
- * - ALL
32
- * - ALL_DU
33
- * - VER-FER_SAB-DOM
34
- * - Rock in Rio_VER_DU
35
- */
36
- export declare function buildRuleSummaryGtfs(rule: ScheduleRule, options: {
37
- events?: Event[];
38
- periods?: YearPeriod[];
39
- }): string;
@@ -1,6 +1,6 @@
1
1
  import { Dates } from '../../../dates.js';
2
2
  import { FORMATS } from '../../../format.js';
3
- import { MONTH_OPTIONS, WEEKDAY_OPTIONS, } from '@tmlmobilidade/types';
3
+ import { WEEKDAY_OPTIONS, } from '@tmlmobilidade/types';
4
4
  import { buildMonthsPart, buildWeekdaysPart, buildYearPeriodsPart } from './common.js';
5
5
  /**
6
6
  * Builds human-readable summaries of a scheduling rule.
@@ -63,19 +63,10 @@ function buildRuleSummaryShort(rule, options) {
63
63
  }
64
64
  if (rule.kind === 'manual' && rule.event_id) {
65
65
  const title = getEventForManualRule(rule, options?.events)?.title ?? '';
66
- const parts = [];
67
- if (title)
68
- parts.push(title);
69
- const periodPart = buildYearPeriodsPart(rule, options, { mode: 'short', omitIfAll: true });
70
- if (periodPart)
71
- parts.push(periodPart);
72
- const monthsPart = buildMonthsPart(rule, { mode: 'short', omitIfAll: true });
73
- if (monthsPart)
74
- parts.push(monthsPart);
75
- const weekdayPart = buildWeekdaysPart(rule, { mode: 'short', omitIfAll: true });
76
- if (weekdayPart)
77
- parts.push(weekdayPart);
78
- return parts.join(' · ');
66
+ if (!rule.weekdays?.length)
67
+ return title;
68
+ const weekdayPart = buildWeekdaysPart(rule, { mode: 'short' });
69
+ return [title, weekdayPart].filter(Boolean).join(' · ');
79
70
  }
80
71
  // manual
81
72
  const parts = [];
@@ -104,19 +95,10 @@ function buildRuleSummaryLong(rule, options) {
104
95
  }
105
96
  if (rule.kind === 'manual' && rule.event_id) {
106
97
  const title = getEventForManualRule(rule, options?.events)?.title ?? '';
107
- const parts = [];
108
- if (title)
109
- parts.push(title);
110
- const periodPart = buildYearPeriodsPart(rule, options, { mode: 'long', omitIfAll: true });
111
- if (periodPart)
112
- parts.push(periodPart);
113
- const monthsPart = buildMonthsPart(rule, { mode: 'long', omitIfAll: true });
114
- if (monthsPart)
115
- parts.push(monthsPart);
116
- const weekdayPart = buildWeekdaysPart(rule, { mode: 'long', omitIfAll: true });
117
- if (weekdayPart)
118
- parts.push(weekdayPart);
119
- return parts.join(', ');
98
+ if (!rule.weekdays?.length)
99
+ return title;
100
+ const weekdayPart = buildWeekdaysPart(rule, { mode: 'long' });
101
+ return [title, weekdayPart].filter(Boolean).join(', ');
120
102
  }
121
103
  // manual
122
104
  const parts = [];
@@ -199,100 +181,3 @@ function buildRuleSummaryTooltip(rule, options) {
199
181
  }
200
182
  return '';
201
183
  }
202
- /**
203
- * TEMP:
204
- * Maps year period ids/names into GTFS abbreviations.
205
- * Replace with a persisted abbreviation/code field when available.
206
- */
207
- function mapPeriodsToGtfsAbbreviation(periodIds) {
208
- if (!periodIds?.length)
209
- return 'ALL';
210
- const map = {
211
- '2KIUJ': 'FER',
212
- '99H2R': 'ESC',
213
- 'UW2U0': 'VER',
214
- };
215
- const abbreviations = periodIds.map((id) => {
216
- const abbr = map[id];
217
- if (!abbr)
218
- throw new Error(`Unknown period id: ${id}`);
219
- return abbr;
220
- });
221
- const unique = [...new Set(abbreviations)];
222
- const allSet = new Set(['ESC', 'FER', 'VER']);
223
- // If all three are present, return 'ALL'
224
- if (unique.length === 3 && unique.every(x => allSet.has(x))) {
225
- return 'ALL';
226
- }
227
- return unique.join('-');
228
- }
229
- function mapWeekdaysToGtfsAbbreviation(weekdays) {
230
- if (!weekdays?.length)
231
- return 'ALL';
232
- const sorted = [...new Set(weekdays)].sort((a, b) => a - b);
233
- const joined = sorted.join('-');
234
- // Special cases
235
- if (joined === '1-2-3-4-5')
236
- return 'DU';
237
- if (joined === '1-2-3-4-5-6-7')
238
- return 'ALL';
239
- const map = {
240
- 1: 'SEG',
241
- 2: 'TER',
242
- 3: 'QUA',
243
- 4: 'QUI',
244
- 5: 'SEX',
245
- 6: 'SAB',
246
- 7: 'DOM',
247
- };
248
- return sorted.map(day => map[day] || String(day)).join('-');
249
- }
250
- function mapMonthsToGtfsAbbreviation(months) {
251
- if (!months?.length)
252
- return null;
253
- const sorted = [...months].sort((a, b) => a - b);
254
- return sorted
255
- .map(m => MONTH_OPTIONS.find(o => o.value === m)?.label.toUpperCase() ?? String(m))
256
- .join('-');
257
- }
258
- /**
259
- * GTFS-oriented rule token:
260
- * - FER_DU
261
- * - VER_SAB
262
- * - ESC_DOM
263
- * - ALL
264
- * - ALL_DU
265
- * - VER-FER_SAB-DOM
266
- * - Rock in Rio_VER_DU
267
- */
268
- export function buildRuleSummaryGtfs(rule, options) {
269
- if (isEventRestriction(rule) || isEventReplacement(rule)) {
270
- return rule.event?.title ?? rule.name ?? rule._id;
271
- }
272
- const periodIds = rule.year_period_ids ?? [];
273
- const weekdays = rule.weekdays ?? [];
274
- const periodPart = mapPeriodsToGtfsAbbreviation(periodIds);
275
- const weekdayPart = mapWeekdaysToGtfsAbbreviation(weekdays);
276
- const monthsPart = mapMonthsToGtfsAbbreviation(rule.months);
277
- if (rule.kind === 'manual' && rule.event_id) {
278
- const title = getEventForManualRule(rule, options?.events)?.title ?? rule.name ?? rule._id;
279
- const tokenParts = [];
280
- if (periodPart !== 'ALL')
281
- tokenParts.push(periodPart);
282
- if (monthsPart)
283
- tokenParts.push(monthsPart);
284
- if (weekdayPart !== 'ALL')
285
- tokenParts.push(weekdayPart);
286
- if (!tokenParts.length)
287
- return title;
288
- return `${title}_${tokenParts.join('_')}`;
289
- }
290
- const tokenParts = [periodPart];
291
- if (monthsPart)
292
- tokenParts.push(monthsPart);
293
- if (weekdayPart !== 'ALL')
294
- tokenParts.push(weekdayPart);
295
- if (tokenParts.length === 1 && tokenParts[0] === 'ALL')
296
- return 'ALL';
297
- return tokenParts.join('_');
298
- }
@@ -65,17 +65,6 @@ export function getManualRuleAffectedDates(rule, ctx) {
65
65
  if (!rule.weekdays.includes(weekday))
66
66
  continue;
67
67
  }
68
- // If year periods are specified, narrow event dates to matching periods only
69
- if (rule.year_period_ids?.length) {
70
- if (!isInPeriod(rule, key, ctx))
71
- continue;
72
- }
73
- // If months are specified, narrow event dates to matching months only
74
- if (rule.months?.length) {
75
- const month = Number(key.slice(5, 7));
76
- if (!rule.months.includes(month))
77
- continue;
78
- }
79
68
  affected.push(key);
80
69
  }
81
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/dates",
3
- "version": "20260410.1049.29",
3
+ "version": "20260411.1243.43",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"