rename to DateUtils

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-17 23:17:56 -04:00
parent 2b97659a33
commit 05bb015047
2 changed files with 5 additions and 5 deletions

30
src/dateUtils.ts Normal file
View File

@@ -0,0 +1,30 @@
export namespace DateUtils {
/**
* Get date time string.
*
* Example: Oct 17, 2024, 11:26:47 PM EDT
*/
export function getDateString(value?: string) {
const date = value ? new Date(value) : new Date();
return date.toLocaleString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: "numeric",
hour12: true,
timeZoneName: 'short'
});
}
/**
* Get time duration in seconds.
*/
export function getTimeDuration(startValue: string, endValue: string) {
const start = new Date(startValue).getTime();
const end = new Date(endValue).getTime();
return ((end - start) / 1000).toFixed(0).toString();
}
}