law-common 14.0.3-beta.12 → 14.0.3-beta.14

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.
@@ -51,33 +51,11 @@ export declare class TimesheetEntityModel extends BaseEntityModel<EntityEnum.TIM
51
51
  get latestStatusFromHistory(): TimesheetStatusEnum | undefined;
52
52
  getDateCodeDay(): number;
53
53
  getClassificationDeadline(config: IClassificationWindowConfig): Date;
54
- /**
55
- * IST point-in-time AUTO-CLASSIFY trigger. Returns the classification window
56
- * whose `endDay + bufferDays + 1 == today` (IST) — i.e. it fires on a SINGLE day
57
- * per window (the auto-classify cron runs at 01:00 IST each morning).
58
- * Trailing window (endDay === null) evaluates against the PREVIOUS month's EOM.
59
- *
60
- * "today" is `getTodayInIST()` (IST calendar day). Concrete per getTodayInIST()
61
- * rollover rule: endDay 13 + buffer 3 -> trigger IST day 17; that 01:00 IST IS
62
- * UTC 19:30 the PREVIOUS day, so a UTC-default container reads getDate() = 16 ->
63
- * 17 !== 16 -> returns null -> auto-classification silently no-ops.
64
- */
65
54
  static getTimesheetAutoClassificationDateCodeRange(config: IClassificationWindowConfig): {
66
55
  windowStart: string;
67
56
  windowEnd: string;
68
57
  } | null;
69
- /**
70
- * Resolves the classification window that contains `now` (used by the reminder).
71
- * `now` defaults to the IST calendar day (getTodayInIST()).
72
- *
73
- * Boundary examples per getTodayInIST() rollover rule (IST < 05:30 -> UTC prev day):
74
- * IST day 1 00:xx -> UTC last day of the PREVIOUS month
75
- * (a UTC clock would skip the day-1-3 spillover onto the
76
- * prev-month 21-EOM window);
77
- * IST day 21 00:30 -> UTC day 20
78
- * (a UTC clock would miss the current-month 21-EOM tail).
79
- */
80
- static getActiveClassificationWindowRange(config: IClassificationWindowConfig, now?: Date): {
58
+ static getActiveClassificationWindowRange(config: IClassificationWindowConfig): {
81
59
  windowStart: string;
82
60
  windowEnd: string;
83
61
  } | null;
@@ -227,21 +227,10 @@ class TimesheetEntityModel extends base_entity_model_1.BaseEntityModel {
227
227
  d.setHours(23, 59, 59, 999);
228
228
  return d;
229
229
  }
230
- /**
231
- * IST point-in-time AUTO-CLASSIFY trigger. Returns the classification window
232
- * whose `endDay + bufferDays + 1 == today` (IST) — i.e. it fires on a SINGLE day
233
- * per window (the auto-classify cron runs at 01:00 IST each morning).
234
- * Trailing window (endDay === null) evaluates against the PREVIOUS month's EOM.
235
- *
236
- * "today" is `getTodayInIST()` (IST calendar day). Concrete per getTodayInIST()
237
- * rollover rule: endDay 13 + buffer 3 -> trigger IST day 17; that 01:00 IST IS
238
- * UTC 19:30 the PREVIOUS day, so a UTC-default container reads getDate() = 16 ->
239
- * 17 !== 16 -> returns null -> auto-classification silently no-ops.
240
- */
241
230
  static getTimesheetAutoClassificationDateCodeRange(config) {
242
231
  var _a;
243
232
  const { bufferDays, windows } = config;
244
- const today = (0, utils_1.getTodayInIST)();
233
+ const today = new Date();
245
234
  for (const window of windows) {
246
235
  // Last window (endDay === null) belongs to the previous month
247
236
  const targetDate = window.endDay === null ? (0, date_fns_1.subMonths)(today, 1) : today;
@@ -258,54 +247,35 @@ class TimesheetEntityModel extends base_entity_model_1.BaseEntityModel {
258
247
  }
259
248
  return null;
260
249
  }
261
- /**
262
- * Resolves the classification window that contains `now` (used by the reminder).
263
- * `now` defaults to the IST calendar day (getTodayInIST()).
264
- *
265
- * Boundary examples per getTodayInIST() rollover rule (IST < 05:30 -> UTC prev day):
266
- * IST day 1 00:xx -> UTC last day of the PREVIOUS month
267
- * (a UTC clock would skip the day-1-3 spillover onto the
268
- * prev-month 21-EOM window);
269
- * IST day 21 00:30 -> UTC day 20
270
- * (a UTC clock would miss the current-month 21-EOM tail).
271
- */
272
- static getActiveClassificationWindowRange(config, now = (0, utils_1.getTodayInIST)()) {
273
- const { bufferDays, windows } = config; // bufferDays = 3
274
- const year = now.getFullYear(); // now = Oct 1 2026 -> year = 2026
275
- const month = now.getMonth(); // month = 9 (Oct)
276
- // Spillover check: does `now` still fall within the PREVIOUS month's trailing
277
- // window (21-EOM) plus its buffer? If so, that window is still pending
278
- // classification and takes priority over the current month's own windows.
279
- const lastWindow = windows[windows.length - 1]; // lastWindow = { startDay: 21, endDay: null }
280
- if ((lastWindow === null || lastWindow === void 0 ? void 0 : lastWindow.endDay) === null) {
281
- const prevMonthDate = (0, date_fns_1.subMonths)(new Date(year, month, 1), 1); // prevMonthDate = Sep 1 2026
282
- const prevYear = prevMonthDate.getFullYear(); // prevYear = 2026
283
- const prevMonth = prevMonthDate.getMonth(); // prevMonth = 8 (Sep)
284
- const prevMonthEom = (0, date_fns_1.lastDayOfMonth)(prevMonthDate).getDate(); // prevMonthEom = 30
285
- const prevWindowStartDate = new Date(prevYear, prevMonth, lastWindow.startDay); // Sep 21 2026
286
- prevWindowStartDate.setHours(0, 0, 0, 0); // Sep 21 2026 00:00:00.000
287
- const prevWindowEndDate = new Date(prevYear, prevMonth, prevMonthEom); // Sep 30 2026
288
- prevWindowEndDate.setHours(23, 59, 59, 999); // Sep 30 2026 23:59:59.999
289
- const prevWindowEndDateWithBuffer = (0, date_fns_1.addDays)(new Date(prevYear, prevMonth, prevMonthEom), bufferDays); // Sep30 + 3 -> Oct 3 2026
290
- prevWindowEndDateWithBuffer.setHours(23, 59, 59, 999); // Oct 3 2026 23:59:59.999
291
- if (now.getTime() >= prevWindowStartDate.getTime() && now.getTime() <= prevWindowEndDateWithBuffer.getTime()) {
292
- // Oct1 >= Sep21 -> true, Oct1 <= Oct3 -> true, so this branch matches and returns here
293
- return {
294
- windowStart: (0, date_fns_1.format)(prevWindowStartDate, "yyyyMMdd"), // "20260921"
295
- windowEnd: (0, date_fns_1.format)(prevWindowEndDate, "yyyyMMdd"), // "20260930"
296
- };
297
- }
298
- }
250
+ static getActiveClassificationWindowRange(config) {
251
+ var _a;
252
+ const { bufferDays, windows } = config;
253
+ const today = new Date();
254
+ const day = today.getDate();
255
+ const year = today.getFullYear();
256
+ const month = today.getMonth();
299
257
  for (const window of windows) {
300
- const windowStartDate = new Date(year, month, window.startDay);
301
- windowStartDate.setHours(0, 0, 0, 0);
302
- const windowEndDate = window.endDay === null ? (0, date_fns_1.lastDayOfMonth)(new Date(year, month, 1)) : new Date(year, month, window.endDay);
303
- windowEndDate.setHours(23, 59, 59, 999);
304
- if (now.getTime() >= windowStartDate.getTime() && now.getTime() <= windowEndDate.getTime()) {
305
- // not reached for Oct 1 -- spillover branch already returned above
258
+ // last window (21–end) belongs to previous month
259
+ const targetDate = window.endDay === null ? (0, date_fns_1.subMonths)(today, 1) : today;
260
+ const targetYear = targetDate.getFullYear();
261
+ const targetMonth = targetDate.getMonth();
262
+ const actualEndDay = (_a = window.endDay) !== null && _a !== void 0 ? _a : (0, date_fns_1.lastDayOfMonth)(targetDate).getDate();
263
+ const windowStartDay = window.startDay;
264
+ const windowEndDay = actualEndDay;
265
+ // check if today falls within this window's active period
266
+ // active period = from windowStart until triggerDate (endDay + bufferDays)
267
+ const triggerDate = (0, date_fns_1.addDays)(new Date(targetYear, targetMonth, actualEndDay), bufferDays);
268
+ const triggerDay = triggerDate.getDate();
269
+ const triggerMonth = triggerDate.getMonth();
270
+ const triggerYear = triggerDate.getFullYear();
271
+ const todayTime = today.getTime();
272
+ const windowOpenDate = new Date(targetYear, targetMonth, windowStartDay);
273
+ const windowCloseDate = new Date(triggerYear, triggerMonth, triggerDay);
274
+ windowCloseDate.setHours(23, 59, 59, 999);
275
+ if (todayTime >= windowOpenDate.getTime() && todayTime <= windowCloseDate.getTime()) {
306
276
  return {
307
- windowStart: (0, date_fns_1.format)(windowStartDate, "yyyyMMdd"),
308
- windowEnd: (0, date_fns_1.format)(windowEndDate, "yyyyMMdd"),
277
+ windowStart: (0, date_fns_1.format)(new Date(targetYear, targetMonth, windowStartDay), "yyyyMMdd"),
278
+ windowEnd: (0, date_fns_1.format)(new Date(targetYear, targetMonth, windowEndDay), "yyyyMMdd"),
309
279
  };
310
280
  }
311
281
  }
@@ -1,22 +1,3 @@
1
1
  export declare function compareDates(recordDate: string, buffer: number): boolean;
2
2
  export declare function epochToDateStringFormat(epoch: number, format?: string): string;
3
3
  export declare function convertDateCodeToFormat(dateString: string, toFormat: string): string;
4
- /**
5
- * Current calendar date resolved in Asia/Kolkata (IST).
6
- *
7
- * TIMEZONE RULE: IST = UTC + 5:30 (fixed offset, no DST).
8
- * Converting IST -> UTC: subtract 5:30.
9
- * - If IST time < 05:30 -> UTC date is the PREVIOUS calendar day.
10
- * - If IST time >= 05:30 -> UTC date is the SAME calendar day.
11
- *
12
- * Example: IST 01:00 -> UTC 19:30 (prev day).
13
- *
14
- * Why this matters: the production container (node:20.10-alpine) sets no TZ,
15
- * so it defaults to UTC. A bare `new Date().getDate()` at 01:00 IST would read
16
- * UTC's date (still "yesterday"), causing classification jobs to target the
17
- * wrong day or silently miss their trigger window.
18
- *
19
- * This function returns a Date whose local getFullYear()/getMonth()/getDate()
20
- * always equal the IST calendar date, regardless of container timezone.
21
- */
22
- export declare function getTodayInIST(): Date;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compareDates = compareDates;
4
4
  exports.epochToDateStringFormat = epochToDateStringFormat;
5
5
  exports.convertDateCodeToFormat = convertDateCodeToFormat;
6
- exports.getTodayInIST = getTodayInIST;
7
6
  const date_fns_1 = require("date-fns");
8
7
  const date_code_model_util_1 = require("./models/date-code.model.util");
9
8
  function compareDates(recordDate, buffer) {
@@ -17,31 +16,3 @@ function convertDateCodeToFormat(dateString, toFormat) {
17
16
  const dateObj = new date_code_model_util_1.DateCodeModel(dateString);
18
17
  return dateObj.toStringFormat(toFormat);
19
18
  }
20
- /**
21
- * Current calendar date resolved in Asia/Kolkata (IST).
22
- *
23
- * TIMEZONE RULE: IST = UTC + 5:30 (fixed offset, no DST).
24
- * Converting IST -> UTC: subtract 5:30.
25
- * - If IST time < 05:30 -> UTC date is the PREVIOUS calendar day.
26
- * - If IST time >= 05:30 -> UTC date is the SAME calendar day.
27
- *
28
- * Example: IST 01:00 -> UTC 19:30 (prev day).
29
- *
30
- * Why this matters: the production container (node:20.10-alpine) sets no TZ,
31
- * so it defaults to UTC. A bare `new Date().getDate()` at 01:00 IST would read
32
- * UTC's date (still "yesterday"), causing classification jobs to target the
33
- * wrong day or silently miss their trigger window.
34
- *
35
- * This function returns a Date whose local getFullYear()/getMonth()/getDate()
36
- * always equal the IST calendar date, regardless of container timezone.
37
- */
38
- function getTodayInIST() {
39
- const parts = new Intl.DateTimeFormat("en-GB", {
40
- timeZone: "Asia/Kolkata",
41
- year: "numeric",
42
- month: "numeric",
43
- day: "numeric",
44
- }).formatToParts(new Date());
45
- const get = (type) => { var _a, _b; return Number((_b = (_a = parts.find((part) => part.type === type)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); };
46
- return new Date(get("year"), get("month") - 1, get("day"));
47
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "14.0.3-beta.12",
3
+ "version": "14.0.3-beta.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [