fix(server): IdService.parseを全てのidタイプに対応させるように (#10533)
* wip fix-id
* ✌️
* fix import
This commit is contained in:
parent
7a33c5d2ee
commit
d76220cc80
7 changed files with 92 additions and 7 deletions
|
|
@ -1,5 +1,8 @@
|
|||
const CHARS = '0123456789abcdef';
|
||||
|
||||
// same as meid
|
||||
export const objectIdRegExp = /^[0-9a-f]{24}$/;
|
||||
|
||||
function getTime(time: number) {
|
||||
if (time < 0) time = 0;
|
||||
if (time === 0) {
|
||||
|
|
@ -24,3 +27,9 @@ function getRandom() {
|
|||
export function genObjectId(date: Date): string {
|
||||
return getTime(date.getTime()) + getRandom();
|
||||
}
|
||||
|
||||
export function parseObjectId(id: string): { date: Date; } {
|
||||
return {
|
||||
date: new Date(parseInt(id.slice(0, 8), 16) * 1000),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue