MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / normalizeBrazilianDate

Function normalizeBrazilianDate

util/normalizeBrazilianDate.js:8–27  ·  view source on GitHub ↗
(
  date,
  separator = '/',
  hasHour = true
)

Source from the content-addressed store, hash-verified

6 * @returns Date
7 */
8export 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}

Callers 2

formatMetarFunction · 0.85
getSwellDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected