mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 09:34:54 +00:00
feat: implement date formatting function and enhance PowerClampService with space-based data retrieval
This commit is contained in:
14
libs/common/src/helper/date-format.ts
Normal file
14
libs/common/src/helper/date-format.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export function toDDMMYYYY(dateString?: string | null): string | null {
|
||||
if (!dateString) return null;
|
||||
|
||||
// Ensure dateString is valid format YYYY-MM-DD
|
||||
const regex = /^\d{4}-\d{2}-\d{2}$/;
|
||||
if (!regex.test(dateString)) {
|
||||
throw new Error(
|
||||
`Invalid date format: ${dateString}. Expected format is YYYY-MM-DD`,
|
||||
);
|
||||
}
|
||||
|
||||
const [year, month, day] = dateString.split('-');
|
||||
return `${day}-${month}-${year}`;
|
||||
}
|
||||
Reference in New Issue
Block a user