@bash-app/bash-common 29.44.1 → 29.44.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash-app/bash-common",
3
- "version": "29.44.1",
3
+ "version": "29.44.2",
4
4
  "description": "Common data and scripts to use on the frontend and backend",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -19,7 +19,7 @@ export const TIME_FORMAT_AM_PM = "h:mm A";
19
19
  export interface ITime {
20
20
  hours: number;
21
21
  minutes: number;
22
- ampm: string;
22
+ ampm: 'AM' | 'PM';
23
23
  }
24
24
 
25
25
  export function formatDateRange(startDateTimeArg: Date | null, endDateTimeArg: Date | null): string {
@@ -42,21 +42,16 @@ export function ensureIsDateTime(possiblyADate: DateTimeArgType): Date | undefin
42
42
  export function normalizeDate(validDate: Date | string | undefined | null): Date | undefined {
43
43
  if (!validDate) return undefined;
44
44
 
45
- // Convert to Date object if it's a string
46
- const date = typeof validDate === "string" ? new Date(validDate) : validDate;
45
+ const date = new Date(validDate);
47
46
 
48
- // Check if the date is valid
49
47
  if (isNaN(date.getTime())) {
50
48
  console.error("Invalid date provided:", validDate);
51
49
  return undefined;
52
50
  }
53
51
 
54
- // Use dayjs to normalize the date and convert to UTC
55
- const normalizedDate = dayjs(date).utc().startOf("minute").toDate();
56
-
57
- return normalizedDate;
52
+ // Normalize to UTC and start of minute
53
+ return dayjs(date).utc().startOf("minute").toDate();
58
54
  }
59
-
60
55
  export function normalizeDates(dates: (Date | string | undefined | null)[]): Date[] {
61
56
  return dates
62
57
  .map((date) => normalizeDate(date)) // Normalize each date
@@ -178,12 +173,16 @@ export function setDateButPreserveTime(
178
173
  }
179
174
 
180
175
 
181
- export function setTimeOnDate(date: DateType | Date | undefined, parsedTime: ITime): Date {
182
- const dateTime = new Date(date ?? Date.now());
183
- const parsedTimeDate = new Date();
184
- parsedTimeDate.setHours(parsedTime.hours, parsedTime.minutes, 0); // Will change the date depending on time; corrected later
185
- const correctTimeOnDate = setDateButPreserveTime(dateTime, parsedTimeDate);
186
- return correctTimeOnDate;
176
+ export function setTimeOnDate(date: DateType | Date | undefined, parsedTime: ITime | null): Date {
177
+ const isValidDate = dayjs(date).isValid();
178
+ const dateTime = new Date(isValidDate && date ? date : Date.now());
179
+ if (parsedTime) {
180
+ const parsedTimeDate = new Date();
181
+ parsedTimeDate.setHours(parsedTime.hours, parsedTime.minutes, 0); // Will change the date depending on time; corrected later
182
+ const correctTimeOnDate = setDateButPreserveTime(dateTime, parsedTimeDate);
183
+ return correctTimeOnDate;
184
+ }
185
+ return dateTime;
187
186
  }
188
187
 
189
188
  export function ensureDateTimeIsLocalDateTime(dateArg: DateType | Dayjs | undefined): Dayjs {
@@ -232,4 +231,4 @@ export function localDateToUTC(date: Date): Date {
232
231
  date.getUTCMinutes(), date.getUTCSeconds());
233
232
 
234
233
  return newDate;
235
- }
234
+ }