refactor: factor out ATG and charging profiles sanity checks
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index dd6591f88bd2b27fe999a2e9c748a5029eb41383..73bb0ba927d2edce72ddf493635915a461d85051 100644 (file)
@@ -60,8 +60,8 @@ export const formatDurationSeconds = (duration: number): string => {
   return formatDurationMilliSeconds(secondsToMilliseconds(duration));
 };
 
-// More efficient date validation function than the one provided by date-fns
-export const isValidDate = (date: unknown): boolean => {
+// More efficient time validation function than the one provided by date-fns
+export const isValidTime = (date: unknown): boolean => {
   if (typeof date === 'number') {
     return !isNaN(date);
   } else if (isDate(date)) {
@@ -76,8 +76,8 @@ export const convertToDate = (
   if (isNullOrUndefined(value)) {
     return value as null | undefined;
   }
-  if (value instanceof Date) {
-    return value;
+  if (isDate(value)) {
+    return value as Date;
   }
   if (isString(value) || typeof value === 'number') {
     return new Date(value!);