( date, separator = '/', hasHour = true )
| 6 | * @returns Date |
| 7 | */ |
| 8 | export default function normalizeBrazilianDate( |
| 9 | date, |
| 10 | separator = '/', |
| 11 | hasHour = true |
| 12 | ) { |
| 13 | const dateObj = new Date(); |
| 14 | const fullDateParts = date.split(' '); // Split hours from date |
| 15 | const dateParts = fullDateParts[0].split(separator); |
| 16 | |
| 17 | dateObj.setFullYear(dateParts[2]); |
| 18 | dateObj.setMonth(dateParts[1] - 1); |
| 19 | dateObj.setDate(dateParts[0]); |
| 20 | if (hasHour) { |
| 21 | const hourParts = fullDateParts[1].split(':'); |
| 22 | dateObj.setHours(hourParts[0]); |
| 23 | dateObj.setMinutes(hourParts[1]); |
| 24 | dateObj.setSeconds(hourParts[2]); |
| 25 | } |
| 26 | return dateObj; |
| 27 | } |
no outgoing calls
no test coverage detected