(birth, now)
| 1316 | } |
| 1317 | |
| 1318 | const yearsSinceMonth = function (birth, now) { |
| 1319 | if (!birth) { return undefined } |
| 1320 | // Should probably review this logic, written quickly and haven't tested any edge cases |
| 1321 | if (_.isString(birth)) { |
| 1322 | if (!/^\d{4}-\d{1,2}(-\d{1,2})?$/.test(birth)) { return undefined } |
| 1323 | if (birth.split('-').length === 2) { |
| 1324 | birth = birth + '-28' // Assume near the end of the month, don't let timezones mess it up, skew younger in interpretation |
| 1325 | } |
| 1326 | const dates = birth.split('-') |
| 1327 | birth = new Date(+dates[0], +dates[1] - 1, +dates[2]) |
| 1328 | } |
| 1329 | if (!_.isDate(birth)) { return undefined } |
| 1330 | |
| 1331 | let birthYear = birth.getFullYear() |
| 1332 | if (birth.getMonth() > 7) { birthYear += 1 } // getMonth start from 0 # child birth after 9.1 should join school in next year |
| 1333 | const season = currentSeason() |
| 1334 | if (now == null) { now = new Date() } |
| 1335 | let schoolYear = now.getFullYear() |
| 1336 | |
| 1337 | const seasonAfterSep = +(season.start.split('-')[0]) >= 9 |
| 1338 | if (seasonAfterSep) { schoolYear += 1 } // school year comes into a new year after 9.1 |
| 1339 | return schoolYear - birthYear |
| 1340 | } |
| 1341 | |
| 1342 | // Keep in sync with the copy in background-processor |
| 1343 | const ageBrackets = [ |
nothing calls this directly
no test coverage detected