Download spectrum/shared/time-formatting.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/shared/time-formatting.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/shared/time-formatting.js
-
curl -L -o time-formatting.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/shared/time-formatting.js
1.6 kB
| // @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}`; | |
| }; | |