(dateString, dateOnly = false)
| 95 | * @returns {string} - Formatted local date string |
| 96 | */ |
| 97 | export function utcToLocal(dateString, dateOnly = false) { |
| 98 | const utcString = dateString.replace(" ", "T") + "Z"; |
| 99 | const date = new Date(utcString); |
| 100 | |
| 101 | const pad = (n) => String(n).padStart(2, "0"); |
| 102 | |
| 103 | const year = date.getFullYear(); |
| 104 | const month = pad(date.getMonth() + 1); |
| 105 | const day = pad(date.getDate()); |
| 106 | const hours = pad(date.getHours()); |
| 107 | const minutes = pad(date.getMinutes()); |
| 108 | const seconds = pad(date.getSeconds()); |
| 109 | |
| 110 | return dateOnly |
| 111 | ? `${year}-${month}-${day}` |
| 112 | : `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| 113 | } |
no test coverage detected