Skip to content

Commit

Permalink
fixup! rename to parseOptionalDate
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
bajtos committed Dec 5, 2023
1 parent ce09d7e commit 4be8473
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ const createMeasurement = async (req, res, client, getCurrentRound) => {
measurement.protocol,
measurement.participantAddress,
measurement.timeout || false,
parseDateStringOrNull(measurement.startAt),
parseOptionalDate(measurement.startAt),
measurement.statusCode,
parseDateStringOrNull(measurement.firstByteAt),
parseDateStringOrNull(measurement.endAt),
parseOptionalDate(measurement.firstByteAt),
parseOptionalDate(measurement.endAt),
measurement.byteLength,
measurement.attestation,
inetGroup,
Expand Down Expand Up @@ -286,7 +286,17 @@ export const createHandler = async ({
}
}

const parseDateStringOrNull = (strOrNull) => {
if (strOrNull === undefined || strOrNull === null) return undefined
return new Date(strOrNull)
/**
* Parse a date string field that may be `undefined` or `null`.
*
* - undefined -> undefined
* - null -> undefined
* - "iso-date-string" -> new Date("iso-date-string")
*
* @param {string | null | undefined} str
* @returns {Date | undefined}
*/
const parseOptionalDate = (str) => {
if (str === undefined || str === null) return undefined
return new Date(str)
}

0 comments on commit 4be8473

Please sign in to comment.