Skip to content

Commit

Permalink
fix: Provide equality function for date parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jan 8, 2025
1 parent aedf413 commit 3118cdf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/nuqs/src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export const parseAsBoolean = createParser({
serialize: v => (v ? 'true' : 'false')
})

function compareDates(a: Date, b: Date) {
return a.valueOf() === b.valueOf()
}

/**
* Querystring encoded as the number of milliseconds since epoch,
* and returned as a Date object.
Expand All @@ -197,7 +201,8 @@ export const parseAsTimestamp = createParser({
}
return new Date(ms)
},
serialize: (v: Date) => v.valueOf().toString()
serialize: (v: Date) => v.valueOf().toString(),
eq: compareDates
})

/**
Expand All @@ -212,7 +217,8 @@ export const parseAsIsoDateTime = createParser({
}
return date
},
serialize: (v: Date) => v.toISOString()
serialize: (v: Date) => v.toISOString(),
eq: compareDates
})

/**
Expand All @@ -231,7 +237,8 @@ export const parseAsIsoDate = createParser({
}
return date
},
serialize: (v: Date) => v.toISOString().slice(0, 10)
serialize: (v: Date) => v.toISOString().slice(0, 10),
eq: compareDates
})

/**
Expand Down

0 comments on commit 3118cdf

Please sign in to comment.