@rocketlink/crm-model 1.0.124 → 1.0.126

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './util/constants';
2
- export * from './util/dateUtils';
3
- export { isDateString, dateToString, stringToDate, getCurrentDateCompacted, FORMATS } from './util/dateUtils';
2
+ export * from './util/dateUtil';
3
+ export { isDateString, dateToString, stringToDate, getCurrentDateCompacted, FORMATS } from './util/dateUtil';
4
4
  export * from './util/numberUtils';
5
5
  export * from './dtos/common/base.request.dto';
6
6
  export * from './dtos/common/paginated.request.dto';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9G,cAAc,oBAAoB,CAAC;AAGnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAE1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,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AAGjE,cAAc,sDAAsD,CAAC;AACrE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,wDAAwD,CAAC;AAGvE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0CAA0C,CAAC;AACzD,cAAc,iDAAiD,CAAC;AAChE,cAAc,8CAA8C,CAAC"}
package/dist/index.js CHANGED
@@ -17,13 +17,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.FORMATS = exports.getCurrentDateCompacted = exports.stringToDate = exports.dateToString = exports.isDateString = void 0;
18
18
  // Export constants
19
19
  __exportStar(require("./util/constants"), exports);
20
- __exportStar(require("./util/dateUtils"), exports);
21
- var dateUtils_1 = require("./util/dateUtils");
22
- Object.defineProperty(exports, "isDateString", { enumerable: true, get: function () { return dateUtils_1.isDateString; } });
23
- Object.defineProperty(exports, "dateToString", { enumerable: true, get: function () { return dateUtils_1.dateToString; } });
24
- Object.defineProperty(exports, "stringToDate", { enumerable: true, get: function () { return dateUtils_1.stringToDate; } });
25
- Object.defineProperty(exports, "getCurrentDateCompacted", { enumerable: true, get: function () { return dateUtils_1.getCurrentDateCompacted; } });
26
- Object.defineProperty(exports, "FORMATS", { enumerable: true, get: function () { return dateUtils_1.FORMATS; } });
20
+ __exportStar(require("./util/dateUtil"), exports);
21
+ var dateUtil_1 = require("./util/dateUtil");
22
+ Object.defineProperty(exports, "isDateString", { enumerable: true, get: function () { return dateUtil_1.isDateString; } });
23
+ Object.defineProperty(exports, "dateToString", { enumerable: true, get: function () { return dateUtil_1.dateToString; } });
24
+ Object.defineProperty(exports, "stringToDate", { enumerable: true, get: function () { return dateUtil_1.stringToDate; } });
25
+ Object.defineProperty(exports, "getCurrentDateCompacted", { enumerable: true, get: function () { return dateUtil_1.getCurrentDateCompacted; } });
26
+ Object.defineProperty(exports, "FORMATS", { enumerable: true, get: function () { return dateUtil_1.FORMATS; } });
27
27
  __exportStar(require("./util/numberUtils"), exports);
28
28
  // Export all DTOs
29
29
  __exportStar(require("./dtos/common/base.request.dto"), exports);
@@ -1,12 +1,8 @@
1
- export declare const INTERVAL_UNIT: {
2
- readonly DAYS: "DAYS";
3
- readonly MONTHS: "MONTHS";
4
- };
5
- export type INTERVAL_UNIT = (typeof INTERVAL_UNIT)[keyof typeof INTERVAL_UNIT];
1
+ import * as dateUtil from "../util/dateUtil";
6
2
  export interface RecurringSettingConfig {
7
3
  id?: number;
8
4
  name?: string;
9
- intervalUnit?: INTERVAL_UNIT;
5
+ intervalUnit?: dateUtil.INTERVAL_UNIT;
10
6
  intervalPeriod?: number;
11
7
  maxTriesAfterFailure?: number;
12
8
  maxDelayPeriod?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"recurringSettingConfig.model.d.ts","sourceRoot":"","sources":["../../src/model/recurringSettingConfig.model.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB"}
1
+ {"version":3,"file":"recurringSettingConfig.model.d.ts","sourceRoot":"","sources":["../../src/model/recurringSettingConfig.model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAE7C,MAAM,WAAW,sBAAsB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB"}
@@ -1,7 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INTERVAL_UNIT = void 0;
4
- exports.INTERVAL_UNIT = {
5
- DAYS: "DAYS",
6
- MONTHS: "MONTHS",
7
- };
@@ -0,0 +1,2 @@
1
+ export declare const getCountryCode: (country: string) => string;
2
+ //# sourceMappingURL=countryUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countryUtil.d.ts","sourceRoot":"","sources":["../../src/util/countryUtil.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAEhD,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCountryCode = void 0;
4
+ const getCountryCode = (country) => {
5
+ return "DE";
6
+ };
7
+ exports.getCountryCode = getCountryCode;
@@ -6,10 +6,16 @@ export declare const FORMATS: {
6
6
  readonly COMPACT_DATETIME: "yyyyMMddHHmmss";
7
7
  readonly COMPACT_DATE: "yyyyMMdd";
8
8
  };
9
- export declare function dateToString(date: Date, formatString?: string): string;
10
- export declare function dateToYYYYMMDD(date: Date): string;
11
- export declare function dateToTZ(date: Date): string;
12
- export declare function dateToMinutes(date: Date): string;
9
+ export declare const INTERVAL_UNIT: {
10
+ readonly DAYS: "DAYS";
11
+ readonly MONTHS: "MONTHS";
12
+ };
13
+ export type INTERVAL_UNIT = (typeof INTERVAL_UNIT)[keyof typeof INTERVAL_UNIT];
14
+ export declare function dateToString(date?: Date, formatString?: string): string;
15
+ export declare function dateToYYYYMMDD(date?: Date): string;
16
+ export declare function dateToTZ(date?: Date): string;
17
+ export declare function dateToMinutes(date?: Date): string;
18
+ export declare function dateToMinutesSeconds(date?: Date): string;
13
19
  export declare function getCurrentDateCompacted(): string;
14
20
  export declare function isDateString(value: string): boolean;
15
21
  export declare function stringToDate(value: string): Date;
@@ -22,4 +28,11 @@ export declare function addDaysToDate(date: Date, days: number): Date;
22
28
  export declare function subtractDaysFromDate(date: Date, days: number): Date;
23
29
  export declare function addDaysToDateString(value: string, days: number, formatString?: string): string;
24
30
  export declare function subtractDaysFromDateString(value: string, days: number, formatString?: string): string;
25
- //# sourceMappingURL=dateUtils.d.ts.map
31
+ export declare function addMonthsToDate(date: Date, months: number): Date;
32
+ export declare function addPeriodToDate(date: Date, period: number, unit: INTERVAL_UNIT): Date;
33
+ export type UiDateInput = Date | string;
34
+ export type FormatDateForUiOptions = {
35
+ includeSeconds?: boolean;
36
+ };
37
+ export declare function formatDateForUi(value: UiDateInput | null | undefined, options?: FormatDateForUiOptions): string;
38
+ //# sourceMappingURL=dateUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateUtil.d.ts","sourceRoot":"","sources":["../../src/util/dateUtil.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO;;;;;;;CAOV,CAAC;AAEX,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAK/E,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,GAAE,MAAyB,GAAG,MAAM,CAKzF;AAED,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAElD;AAED,wBAAgB,QA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AAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAUrF;AAMD,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,MAAM,CAAC;AAwDxC,MAAM,MAAM,sBAAsB,GAAG;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EACrC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CA8BR"}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FORMATS = void 0;
3
+ exports.INTERVAL_UNIT = exports.FORMATS = void 0;
4
4
  exports.dateToString = dateToString;
5
5
  exports.dateToYYYYMMDD = dateToYYYYMMDD;
6
6
  exports.dateToTZ = dateToTZ;
7
7
  exports.dateToMinutes = dateToMinutes;
8
+ exports.dateToMinutesSeconds = dateToMinutesSeconds;
8
9
  exports.getCurrentDateCompacted = getCurrentDateCompacted;
9
10
  exports.isDateString = isDateString;
10
11
  exports.stringToDate = stringToDate;
@@ -17,6 +18,9 @@ exports.addDaysToDate = addDaysToDate;
17
18
  exports.subtractDaysFromDate = subtractDaysFromDate;
18
19
  exports.addDaysToDateString = addDaysToDateString;
19
20
  exports.subtractDaysFromDateString = subtractDaysFromDateString;
21
+ exports.addMonthsToDate = addMonthsToDate;
22
+ exports.addPeriodToDate = addPeriodToDate;
23
+ exports.formatDateForUi = formatDateForUi;
20
24
  const date_fns_1 = require("date-fns");
21
25
  exports.FORMATS = {
22
26
  ISO_DATE: 'yyyy-MM-dd', // "2026-01-07"
@@ -26,12 +30,16 @@ exports.FORMATS = {
26
30
  COMPACT_DATETIME: 'yyyyMMddHHmmss', // "20260107143000"
27
31
  COMPACT_DATE: 'yyyyMMdd', // "20260107"
28
32
  };
33
+ exports.INTERVAL_UNIT = {
34
+ DAYS: "DAYS",
35
+ MONTHS: "MONTHS",
36
+ };
29
37
  // ============================================
30
38
  // Date → String formatted conversions
31
39
  // ============================================
32
40
  function dateToString(date, formatString = exports.FORMATS.ISO_DATE) {
33
41
  if (!date || !(0, date_fns_1.isValid)(date)) {
34
- throw new Error('Invalid date: ' + date);
42
+ return undefined;
35
43
  }
36
44
  return (0, date_fns_1.format)(date, formatString);
37
45
  }
@@ -44,6 +52,9 @@ function dateToTZ(date) {
44
52
  function dateToMinutes(date) {
45
53
  return dateToString(date, exports.FORMATS.ISO_DATE_TIME_MINUTES);
46
54
  }
55
+ function dateToMinutesSeconds(date) {
56
+ return dateToString(date, exports.FORMATS.ISO_DATE_TIME_SECONDS);
57
+ }
47
58
  function getCurrentDateCompacted() {
48
59
  return dateToYYYYMMDD(new Date()); // "20260107143000"
49
60
  }
@@ -112,3 +123,92 @@ function subtractDaysFromDateString(value, days, formatString = exports.FORMATS.
112
123
  const newDate = (0, date_fns_1.subDays)(date, days);
113
124
  return (0, date_fns_1.format)(newDate, formatString);
114
125
  }
126
+ function addMonthsToDate(date, months) {
127
+ if (!date || !(0, date_fns_1.isValid)(date)) {
128
+ throw new Error('Invalid date: ' + date);
129
+ }
130
+ return (0, date_fns_1.addMonths)(date, months);
131
+ }
132
+ function addPeriodToDate(date, period, unit) {
133
+ if (!date || !(0, date_fns_1.isValid)(date)) {
134
+ throw new Error('Invalid date: ' + date);
135
+ }
136
+ if (unit === exports.INTERVAL_UNIT.MONTHS) {
137
+ date = addMonthsToDate(date, period);
138
+ }
139
+ else if (unit === exports.INTERVAL_UNIT.DAYS) {
140
+ date = addDaysToDate(date, period);
141
+ }
142
+ return date;
143
+ }
144
+ //"15 Jan 2024, 10:30:40" or "15 Jan 2024, 10:30" or just "15 Jan 2024".
145
+ const parseUiDate = (value) => {
146
+ if (value instanceof Date) {
147
+ const d = value;
148
+ if (Number.isNaN(d.getTime()))
149
+ return null;
150
+ const hasTime = d.getHours() !== 0 ||
151
+ d.getMinutes() !== 0 ||
152
+ d.getSeconds() !== 0 ||
153
+ d.getMilliseconds() !== 0;
154
+ return { date: d, hasTime };
155
+ }
156
+ const raw = String(value).trim();
157
+ if (!raw)
158
+ return null;
159
+ // Explicit "dd.MM.yyyy" (e.g. "31.07.2024") -> date-only
160
+ const dotDateMatch = raw.match(/^(\d{2})\.(\d{2})\.(\d{4})$/);
161
+ if (dotDateMatch) {
162
+ const [, dd, mm, yyyy] = dotDateMatch;
163
+ const d = new Date(Number(yyyy), Number(mm) - 1, Number(dd));
164
+ if (Number.isNaN(d.getTime()))
165
+ return null;
166
+ return { date: d, hasTime: false };
167
+ }
168
+ // Plain ISO date "YYYY-MM-DD" -> date-only
169
+ const isoDateOnlyMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
170
+ if (isoDateOnlyMatch) {
171
+ const [, yyyy, mm, dd] = isoDateOnlyMatch;
172
+ const d = new Date(Number(yyyy), Number(mm) - 1, Number(dd));
173
+ if (Number.isNaN(d.getTime()))
174
+ return null;
175
+ return { date: d, hasTime: false };
176
+ }
177
+ // Fallback to native parser for ISO timestamps and other formats.
178
+ const d = new Date(raw);
179
+ if (Number.isNaN(d.getTime()))
180
+ return null;
181
+ // If the original string clearly contained a time (has 'T' or an HH:MM),
182
+ // treat it as having a time component, otherwise fall back to midnight check.
183
+ const explicitTime = /T\d\d?:\d\d/.test(raw) || /\d{1,2}:\d{2}/.test(raw);
184
+ const hasTime = explicitTime ||
185
+ d.getHours() !== 0 ||
186
+ d.getMinutes() !== 0 ||
187
+ d.getSeconds() !== 0 ||
188
+ d.getMilliseconds() !== 0;
189
+ return { date: d, hasTime };
190
+ };
191
+ function formatDateForUi(value, options) {
192
+ if (!value) {
193
+ return '-';
194
+ }
195
+ const parsed = parseUiDate(value);
196
+ if (!parsed) {
197
+ return '-';
198
+ }
199
+ const { date, hasTime } = parsed;
200
+ const includeSeconds = options?.includeSeconds ?? false;
201
+ const day = String(date.getDate()).padStart(2, '0');
202
+ const monthShort = date.toLocaleString('en-US', { month: 'short' });
203
+ const year = date.getFullYear();
204
+ const base = `${day} ${monthShort} ${year}`;
205
+ if (!hasTime) {
206
+ return base;
207
+ }
208
+ const hours = String(date.getHours()).padStart(2, '0');
209
+ const minutes = String(date.getMinutes()).padStart(2, '0');
210
+ const time = includeSeconds
211
+ ? `${hours}:${minutes}:${String(date.getSeconds()).padStart(2, '0')}`
212
+ : `${hours}:${minutes}`;
213
+ return `${base}, ${time}`;
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocketlink/crm-model",
3
- "version": "1.0.124",
3
+ "version": "1.0.126",
4
4
  "description": "Shared DTOs and Models for CRM Rocketlink",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Export constants
2
2
  export * from './util/constants';
3
- export * from './util/dateUtils';
4
- export { isDateString, dateToString, stringToDate, getCurrentDateCompacted, FORMATS } from './util/dateUtils';
3
+ export * from './util/dateUtil';
4
+ export { isDateString, dateToString, stringToDate, getCurrentDateCompacted, FORMATS } from './util/dateUtil';
5
5
  export * from './util/numberUtils';
6
6
 
7
7
  // Export all DTOs
@@ -1,13 +1,9 @@
1
- export const INTERVAL_UNIT = {
2
- DAYS: "DAYS",
3
- MONTHS: "MONTHS",
4
- } as const;
5
- export type INTERVAL_UNIT = (typeof INTERVAL_UNIT)[keyof typeof INTERVAL_UNIT];
1
+ import * as dateUtil from "../util/dateUtil";
6
2
 
7
3
  export interface RecurringSettingConfig {
8
4
  id?: number;
9
5
  name?: string;
10
- intervalUnit?: INTERVAL_UNIT;
6
+ intervalUnit?: dateUtil.INTERVAL_UNIT;
11
7
  intervalPeriod?: number;
12
8
  maxTriesAfterFailure?: number;
13
9
  maxDelayPeriod?: number;
@@ -0,0 +1,3 @@
1
+ export const getCountryCode = (country: string): string => {
2
+ return "DE";
3
+ };
@@ -0,0 +1,238 @@
1
+ import { addDays, addMonths, format, isValid, parseISO, subDays } from 'date-fns';
2
+
3
+ export const FORMATS = {
4
+ ISO_DATE: 'yyyy-MM-dd', // "2026-01-07"
5
+ ISO_DATE_TIME_TZ: "yyyy-MM-dd'T'HH:mm", // "2026-01-07T14:30"
6
+ ISO_DATE_TIME_MINUTES: 'yyyy-MM-dd HH:mm', // "2026-01-07 14:30
7
+ ISO_DATE_TIME_SECONDS: 'yyyy-MM-dd HH:mm:ss', // "2026-01-07 14:30:23,
8
+ COMPACT_DATETIME: 'yyyyMMddHHmmss', // "20260107143000"
9
+ COMPACT_DATE: 'yyyyMMdd', // "20260107"
10
+ } as const;
11
+
12
+ export const INTERVAL_UNIT = {
13
+ DAYS: "DAYS",
14
+ MONTHS: "MONTHS",
15
+ } as const;
16
+ export type INTERVAL_UNIT = (typeof INTERVAL_UNIT)[keyof typeof INTERVAL_UNIT];
17
+
18
+ // ============================================
19
+ // Date → String formatted conversions
20
+ // ============================================
21
+ export function dateToString(date?: Date, formatString: string = FORMATS.ISO_DATE): string {
22
+ if (!date || !isValid(date)) {
23
+ return undefined!;
24
+ }
25
+ return format(date, formatString);
26
+ }
27
+
28
+ export function dateToYYYYMMDD(date?: Date): string {
29
+ return dateToString(date, FORMATS.COMPACT_DATETIME);
30
+ }
31
+
32
+ export function dateToTZ(date?: Date): string {
33
+ return dateToString(date, FORMATS.ISO_DATE_TIME_TZ);
34
+ }
35
+
36
+ export function dateToMinutes(date?: Date): string {
37
+ return dateToString(date, FORMATS.ISO_DATE_TIME_MINUTES);
38
+ }
39
+
40
+ export function dateToMinutesSeconds(date?: Date): string {
41
+ return dateToString(date, FORMATS.ISO_DATE_TIME_SECONDS);
42
+ }
43
+
44
+ export function getCurrentDateCompacted(): string {
45
+ return dateToYYYYMMDD(new Date()); // "20260107143000"
46
+ }
47
+
48
+ // Checks if a string matches a date pattern
49
+ export function isDateString(value: string): boolean {
50
+ const datePattern = /^\d{4}-\d{2}-\d{2}(T|\s)\d{2}:\d{2}:\d{2}/;
51
+ return datePattern.test(value);
52
+ }
53
+
54
+ // ============================================
55
+ // String → Date conversions
56
+ // ============================================
57
+ export function stringToDate(value: string): Date {
58
+ if (!value) {
59
+ throw new Error('Date string cannot be empty');
60
+ }
61
+ const date = parseISO(value);
62
+ if (!isValid(date)) {
63
+ throw new Error('Invalid date string: ' + value);
64
+ }
65
+ return date;
66
+ }
67
+
68
+ // ============================================
69
+ // String → String formatted conversions
70
+ // ============================================
71
+ export function formatDateString(value: string, formatString: string = FORMATS.ISO_DATE): string {
72
+ if (!value) {
73
+ return '';
74
+ }
75
+ const date = stringToDate(value);
76
+ return format(date, formatString);
77
+ }
78
+
79
+ export function formatDateAs_yyyymmdd(value: string): string {
80
+ return formatDateString(value, FORMATS.ISO_DATE);
81
+ }
82
+
83
+ export function formatDateAs_tz(value: string): string {
84
+ return formatDateString(value, FORMATS.ISO_DATE_TIME_TZ);
85
+ }
86
+
87
+ export function formatDateAs_minutes(value: string): string {
88
+ return formatDateString(value, FORMATS.ISO_DATE_TIME_MINUTES);
89
+ }
90
+
91
+ export function formatDateAs_seconds(value: string): string {
92
+ return formatDateString(value, FORMATS.ISO_DATE_TIME_SECONDS);
93
+ }
94
+
95
+ // ============================================
96
+ // Date manipulation
97
+ // ============================================
98
+ export function addDaysToDate(date: Date, days: number): Date {
99
+ if (!date || !isValid(date)) {
100
+ throw new Error('Invalid date: ' + date);
101
+ }
102
+ return addDays(date, days);
103
+ }
104
+
105
+ export function subtractDaysFromDate(date: Date, days: number): Date {
106
+ if (!date || !isValid(date)) {
107
+ throw new Error('Invalid date: ' + date);
108
+ }
109
+ return subDays(date, days);
110
+ }
111
+
112
+ export function addDaysToDateString(value: string, days: number, formatString: string = FORMATS.ISO_DATE): string {
113
+ const date = stringToDate(value);
114
+ const newDate = addDays(date, days);
115
+ return format(newDate, formatString);
116
+ }
117
+
118
+ export function subtractDaysFromDateString(value: string, days: number, formatString: string = FORMATS.ISO_DATE): string {
119
+ const date = stringToDate(value);
120
+ const newDate = subDays(date, days);
121
+ return format(newDate, formatString);
122
+ }
123
+
124
+ export function addMonthsToDate(date: Date, months: number): Date {
125
+ if (!date || !isValid(date)) {
126
+ throw new Error('Invalid date: ' + date);
127
+ }
128
+ return addMonths(date, months);
129
+ }
130
+
131
+ export function addPeriodToDate(date: Date, period: number, unit: INTERVAL_UNIT): Date {
132
+ if (!date || !isValid(date)) {
133
+ throw new Error('Invalid date: ' + date);
134
+ }
135
+ if (unit === INTERVAL_UNIT.MONTHS) {
136
+ date = addMonthsToDate(date, period);
137
+ } else if (unit === INTERVAL_UNIT.DAYS) {
138
+ date = addDaysToDate(date, period);
139
+ }
140
+ return date;
141
+ }
142
+
143
+ // ============================================
144
+ // UI-friendly formatting (used by admin-ts)
145
+ // ============================================
146
+
147
+ export type UiDateInput = Date | string;
148
+
149
+ //"15 Jan 2024, 10:30:40" or "15 Jan 2024, 10:30" or just "15 Jan 2024".
150
+
151
+ const parseUiDate = (
152
+ value: UiDateInput
153
+ ): { date: Date; hasTime: boolean } | null => {
154
+ if (value instanceof Date) {
155
+ const d = value;
156
+ if (Number.isNaN(d.getTime())) return null;
157
+ const hasTime =
158
+ d.getHours() !== 0 ||
159
+ d.getMinutes() !== 0 ||
160
+ d.getSeconds() !== 0 ||
161
+ d.getMilliseconds() !== 0;
162
+ return { date: d, hasTime };
163
+ }
164
+
165
+ const raw = String(value).trim();
166
+ if (!raw) return null;
167
+
168
+ // Explicit "dd.MM.yyyy" (e.g. "31.07.2024") -> date-only
169
+ const dotDateMatch = raw.match(/^(\d{2})\.(\d{2})\.(\d{4})$/);
170
+ if (dotDateMatch) {
171
+ const [, dd, mm, yyyy] = dotDateMatch;
172
+ const d = new Date(Number(yyyy), Number(mm) - 1, Number(dd));
173
+ if (Number.isNaN(d.getTime())) return null;
174
+ return { date: d, hasTime: false };
175
+ }
176
+
177
+ // Plain ISO date "YYYY-MM-DD" -> date-only
178
+ const isoDateOnlyMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
179
+ if (isoDateOnlyMatch) {
180
+ const [, yyyy, mm, dd] = isoDateOnlyMatch;
181
+ const d = new Date(Number(yyyy), Number(mm) - 1, Number(dd));
182
+ if (Number.isNaN(d.getTime())) return null;
183
+ return { date: d, hasTime: false };
184
+ }
185
+
186
+ // Fallback to native parser for ISO timestamps and other formats.
187
+ const d = new Date(raw);
188
+ if (Number.isNaN(d.getTime())) return null;
189
+
190
+ // If the original string clearly contained a time (has 'T' or an HH:MM),
191
+ // treat it as having a time component, otherwise fall back to midnight check.
192
+ const explicitTime = /T\d\d?:\d\d/.test(raw) || /\d{1,2}:\d{2}/.test(raw);
193
+ const hasTime =
194
+ explicitTime ||
195
+ d.getHours() !== 0 ||
196
+ d.getMinutes() !== 0 ||
197
+ d.getSeconds() !== 0 ||
198
+ d.getMilliseconds() !== 0;
199
+
200
+ return { date: d, hasTime };
201
+ };
202
+
203
+ export type FormatDateForUiOptions = { includeSeconds?: boolean };
204
+
205
+ export function formatDateForUi(
206
+ value: UiDateInput | null | undefined,
207
+ options?: FormatDateForUiOptions
208
+ ): string {
209
+ if (!value) {
210
+ return '-';
211
+ }
212
+
213
+ const parsed = parseUiDate(value);
214
+ if (!parsed) {
215
+ return '-';
216
+ }
217
+
218
+ const { date, hasTime } = parsed;
219
+ const includeSeconds = options?.includeSeconds ?? false;
220
+
221
+ const day = String(date.getDate()).padStart(2, '0');
222
+ const monthShort = date.toLocaleString('en-US', { month: 'short' });
223
+ const year = date.getFullYear();
224
+ const base = `${day} ${monthShort} ${year}`;
225
+
226
+ if (!hasTime) {
227
+ return base;
228
+ }
229
+
230
+ const hours = String(date.getHours()).padStart(2, '0');
231
+ const minutes = String(date.getMinutes()).padStart(2, '0');
232
+ const time =
233
+ includeSeconds
234
+ ? `${hours}:${minutes}:${String(date.getSeconds()).padStart(2, '0')}`
235
+ : `${hours}:${minutes}`;
236
+
237
+ return `${base}, ${time}`;
238
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"dateUtils.d.ts","sourceRoot":"","sources":["../../src/util/dateUtils.ts"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B,GAAG,MAAM,CAIvH"}
@@ -1,98 +0,0 @@
1
- import { format, isValid, parseISO, addDays, subDays } from 'date-fns';
2
-
3
- export const FORMATS = {
4
- ISO_DATE: 'yyyy-MM-dd', // "2026-01-07"
5
- ISO_DATE_TIME_TZ: "yyyy-MM-dd'T'HH:mm", // "2026-01-07T14:30"
6
- ISO_DATE_TIME_MINUTES: 'yyyy-MM-dd HH:mm', // "2026-01-07 14:30
7
- ISO_DATE_TIME_SECONDS: 'yyyy-MM-dd HH:mm:ss', // "2026-01-07 14:30:23,
8
- COMPACT_DATETIME: 'yyyyMMddHHmmss', // "20260107143000"
9
- COMPACT_DATE: 'yyyyMMdd', // "20260107"
10
- } as const;
11
- // ============================================
12
- // Date → String formatted conversions
13
- // ============================================
14
- export function dateToString(date: Date, formatString: string = FORMATS.ISO_DATE): string {
15
- if (!date || !isValid(date)) {
16
- throw new Error('Invalid date: ' + date);
17
- }
18
- return format(date, formatString);
19
- }
20
- export function dateToYYYYMMDD(date: Date): string {
21
- return dateToString(date, FORMATS.COMPACT_DATETIME);
22
- }
23
- export function dateToTZ(date: Date): string {
24
- return dateToString(date, FORMATS.ISO_DATE_TIME_TZ);
25
- }
26
- export function dateToMinutes(date: Date): string {
27
- return dateToString(date, FORMATS.ISO_DATE_TIME_MINUTES);
28
- }
29
- export function getCurrentDateCompacted(): string {
30
- return dateToYYYYMMDD(new Date()); // "20260107143000"
31
- }
32
-
33
- // Checks if a string matches a date pattern
34
- export function isDateString(value: string): boolean {
35
- const datePattern = /^\d{4}-\d{2}-\d{2}(T|\s)\d{2}:\d{2}:\d{2}/;
36
- return datePattern.test(value);
37
- }
38
- // ============================================
39
- // String → Date conversions
40
- // ============================================
41
- export function stringToDate(value: string): Date {
42
- if (!value) {
43
- throw new Error('Date string cannot be empty');
44
- }
45
- const date = parseISO(value);
46
- if (!isValid(date)) {
47
- throw new Error('Invalid date string: ' + value);
48
- }
49
- return date;
50
- }
51
- // ============================================
52
- // String → String formatted conversions
53
- // ============================================
54
- export function formatDateString(value: string, formatString: string = FORMATS.ISO_DATE): string {
55
- if (!value) {
56
- return '';
57
- }
58
- const date = stringToDate(value);
59
- return format(date, formatString);
60
- }
61
- export function formatDateAs_yyyymmdd(value: string): string {
62
- return formatDateString(value, FORMATS.ISO_DATE);
63
- }
64
- export function formatDateAs_tz(value: string): string {
65
- return formatDateString(value, FORMATS.ISO_DATE_TIME_TZ);
66
- }
67
- export function formatDateAs_minutes(value: string): string {
68
- return formatDateString(value, FORMATS.ISO_DATE_TIME_MINUTES);
69
- }
70
- export function formatDateAs_seconds(value: string): string {
71
- return formatDateString(value, FORMATS.ISO_DATE_TIME_SECONDS);
72
- }
73
-
74
- // ============================================
75
- // Date manipulation
76
- // ============================================
77
- export function addDaysToDate(date: Date, days: number): Date {
78
- if (!date || !isValid(date)) {
79
- throw new Error('Invalid date: ' + date);
80
- }
81
- return addDays(date, days);
82
- }
83
- export function subtractDaysFromDate(date: Date, days: number): Date {
84
- if (!date || !isValid(date)) {
85
- throw new Error('Invalid date: ' + date);
86
- }
87
- return subDays(date, days);
88
- }
89
- export function addDaysToDateString(value: string, days: number, formatString: string = FORMATS.ISO_DATE): string {
90
- const date = stringToDate(value);
91
- const newDate = addDays(date, days);
92
- return format(newDate, formatString);
93
- }
94
- export function subtractDaysFromDateString(value: string, days: number, formatString: string = FORMATS.ISO_DATE): string {
95
- const date = stringToDate(value);
96
- const newDate = subDays(date, days);
97
- return format(newDate, formatString);
98
- }