type DateFilter = {
hours?: number;
days?: number;
};
/**
* Converts a given date filter to a Unix timestamp.
* @param {DateFilter} [date] - The date filter object specifying hours or days.
* @returns {number} The Unix timestamp representing the converted date.
*/
export function convertDateToUnixTimestamp(date?: DateFilter): number {
if (date?.hours) {
// Convert hours to seconds and add to current Unix timestamp
return Math.floor(new Date().getTime() / 1000) + date.hours * 3600;
} else if (date?.days) {
// Convert days to seconds and add to current Unix timestamp
return Math.floor(new Date().getTime() / 1000) + date.days * 24 * 3600;
} else {
// If no date is provided, default to one year in the future
return Math.floor(new Date().getTime() / 1000) + 365 * 24 * 3600;
}
}
This function takes an optional DateFilter object as input, which specifies either the number of hours or days. It returns a Unix timestamp representing the given date. If no date is provided, it defaults to one year in the future.
convertUnixTimestampToDate
/**
* Converts a Unix timestamp to a JavaScript Date object.
* @param {number} unixTimestamp - The Unix timestamp to convert.
* @returns {Date} The JavaScript Date object representing the converted timestamp.
*/
export function convertUnixTimestampToDate(unixTimestamp: number): Date {
// Convert Unix timestamp to milliseconds and create a Date object
return new Date(unixTimestamp * 1000);
}
This function takes a Unix timestamp as input and returns a JavaScript Date object representing the converted timestamp. It multiplies the Unix timestamp by 1000 to convert it from seconds to milliseconds, as JavaScript Date objects operate in milliseconds.
This function takes an order object and an array of token objects as parameters and returns an object containing human-readable order information. It converts amounts from their raw form to their respective token units using token decimals, and it also converts the expiration timestamp to a human-readable date format.