// @flow export const convertTimestampToDate = (timestamp: number) => { let monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ]; let date = new Date(timestamp); let day = date.getDate(); let monthIndex = date.getMonth(); let month = monthNames[monthIndex]; let year = date.getFullYear(); let hours = date.getHours() || 0; let cleanHours; if (hours === 0) { cleanHours = 12; // if timestamp is between midnight and 1am, show 12:XX am } else { cleanHours = hours > 12 ? hours - 12 : hours; // else show proper am/pm -- todo: support 24hr time } let minutes = date.getMinutes(); minutes = minutes >= 10 ? minutes : '0' + minutes.toString(); // turns 4 minutes into 04 minutes let ampm = hours >= 12 ? 'pm' : 'am'; // todo: support 24hr time return `${month} ${day}, ${year} at ${cleanHours}:${minutes}${ampm}`; }; export const convertTimestampToTime = (timestamp: Date) => { let date = new Date(timestamp); let hours = date.getHours() || 0; let cleanHours; if (hours === 0) { cleanHours = 12; // if timestamp is between midnight and 1am, show 12:XX am } else { cleanHours = hours > 12 ? hours - 12 : hours; // else show proper am/pm -- todo: support 24hr time } let minutes = date.getMinutes(); minutes = minutes >= 10 ? minutes : '0' + minutes.toString(); // turns 4 minutes into 04 minutes let ampm = hours >= 12 ? 'pm' : 'am'; // todo: support 24hr time return `${cleanHours}:${minutes}${ampm}`; };