@star-insure/sdk 4.5.0 → 4.6.0

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.
@@ -14,3 +14,7 @@ export declare function formatDate(date: Date | string | null | undefined, overr
14
14
  * Formats a dateTime to Star Insure standard format - dd/mm/yyyy hh:mm
15
15
  */
16
16
  export declare function formatDateTime(dateTime: Date | string | null | undefined, overrideFormatString?: string): string;
17
+ /**
18
+ * Attempts to create a date object from a date string
19
+ */
20
+ export declare function createDate(dateString: Date | string | null | undefined): Date | null;
@@ -125,6 +125,26 @@ function formatDateTime(dateTime, overrideFormatString) {
125
125
 
126
126
  return '';
127
127
  }
128
+ /**
129
+ * Attempts to create a date object from a date string
130
+ */
131
+
132
+ function createDate(dateString) {
133
+ // Re-use our logic from formatDateTime
134
+ var formattedDateTime = formatDateTime(dateString);
135
+
136
+ if (!formattedDateTime) {
137
+ return null;
138
+ } // Attempt to parse the formatted date to a date object
139
+
140
+
141
+ try {
142
+ return dateFns.parse(formattedDateTime, 'dd/MM/yyyy HH:mm', new Date());
143
+ } catch (error) {
144
+ console.error("Error parsing date: " + (dateString == null ? void 0 : dateString.toString()));
145
+ return null;
146
+ }
147
+ }
128
148
 
129
149
  /**
130
150
  * Safely rounds a number
@@ -3346,6 +3366,7 @@ exports.autocomplete = autocomplete;
3346
3366
  exports.calcMonthlyEnhancementPrice = calcMonthlyEnhancementPrice;
3347
3367
  exports.calcPurchaseOptionPricing = calcPurchaseOptionPricing;
3348
3368
  exports.calculateAge = calculateAge;
3369
+ exports.createDate = createDate;
3349
3370
  exports.fixRoundingError = fixRoundingError;
3350
3371
  exports.formatDate = formatDate;
3351
3372
  exports.formatDateForTable = formatDateForTable;