emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
84 lines • 2.21 kB
JavaScript
/**
* Timestamp Factory Functions
*/
export const TimestampFactory = {
/**
* Create a timestamp from current time
*/
now: () => {
const date = new Date();
return {
value: date.getTime(),
isoString: date.toISOString(),
date,
isValid: true,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
};
},
/**
* Create a timestamp from a Date object
*/
fromDate: (date) => ({
value: date.getTime(),
isoString: date.toISOString(),
date,
isValid: !isNaN(date.getTime()),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
}),
/**
* Create a timestamp from milliseconds
*/
fromMilliseconds: (milliseconds) => {
const date = new Date(milliseconds);
return {
value: milliseconds,
isoString: date.toISOString(),
date,
isValid: !isNaN(date.getTime()),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
};
},
/**
* Create a timestamp from ISO string
*/
fromISOString: (isoString) => {
const date = new Date(isoString);
return {
value: date.getTime(),
isoString,
date,
isValid: !isNaN(date.getTime()),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
};
}
};
/**
* Timestamp Utility Functions
*/
export const TimestampUtils = {
/**
* Check if a timestamp is in the past
*/
isPast: (timestamp) => {
return timestamp.value < Date.now();
},
/**
* Check if a timestamp is in the future
*/
isFuture: (timestamp) => {
return timestamp.value > Date.now();
},
/**
* Get the difference between two timestamps in milliseconds
*/
difference: (timestamp1, timestamp2) => {
return Math.abs(timestamp1.value - timestamp2.value);
},
/**
* Format a timestamp for display
*/
format: (timestamp, locale = 'en-US') => {
return timestamp.date.toLocaleString(locale);
}
};
//# sourceMappingURL=Timestamp.js.map