Skip to content

Commit eff676f

Browse files
committed
fix: Provide equality function for date parsers
1 parent 1bc8b3d commit eff676f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/nuqs/src/parsers.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ export const parseAsBoolean = createParser({
196196
serialize: v => (v ? 'true' : 'false')
197197
})
198198

199+
function compareDates(a: Date, b: Date) {
200+
return a.valueOf() === b.valueOf()
201+
}
202+
199203
/**
200204
* Querystring encoded as the number of milliseconds since epoch,
201205
* and returned as a Date object.
@@ -208,7 +212,8 @@ export const parseAsTimestamp = createParser({
208212
}
209213
return new Date(ms)
210214
},
211-
serialize: (v: Date) => v.valueOf().toString()
215+
serialize: (v: Date) => v.valueOf().toString(),
216+
eq: compareDates
212217
})
213218

214219
/**
@@ -223,7 +228,8 @@ export const parseAsIsoDateTime = createParser({
223228
}
224229
return date
225230
},
226-
serialize: (v: Date) => v.toISOString()
231+
serialize: (v: Date) => v.toISOString(),
232+
eq: compareDates
227233
})
228234

229235
/**
@@ -242,7 +248,8 @@ export const parseAsIsoDate = createParser({
242248
}
243249
return date
244250
},
245-
serialize: (v: Date) => v.toISOString().slice(0, 10)
251+
serialize: (v: Date) => v.toISOString().slice(0, 10),
252+
eq: compareDates
246253
})
247254

248255
/**

0 commit comments

Comments
 (0)