From 420eb3973b1f4b7cf10a0fe819793d0064332949 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Tue, 22 Mar 2022 14:47:34 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D0=B0=D1=80=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B0=D1=81=D1=81=D1=87=D0=B5=D1=82=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Generators/PersonalIdGenerator.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/popup/src/classes/Service/Generators/PersonalIdGenerator.ts b/popup/src/classes/Service/Generators/PersonalIdGenerator.ts index 4b832e8..4e1987b 100644 --- a/popup/src/classes/Service/Generators/PersonalIdGenerator.ts +++ b/popup/src/classes/Service/Generators/PersonalIdGenerator.ts @@ -8,11 +8,16 @@ export class PersonalIdGenerator { * @param person */ generate (person: Person) { - const year = this.getYearPart(person.birthday.year) + let fullYear = person.birthday.year + if (!fullYear) { + const e = (new Date()).getFullYear() + fullYear = BigInt(randomGenerator.generate(e - 5, e - 55)) + } + const year = this.getYearPart(fullYear) const month = this.getMonthPart(person.birthday.month) const day = this.getDayPart(person.birthday.day) const o = this.getIdNumPart() - const a = this.getGenderPart(person.country, person.gender) + const a = this.getGenderPart(person.country, person.gender, fullYear) const l = this.getControlSum(person.country, year, month, day, o, a) const l2 = this.getChecksum(a + year + month + day + o) @@ -25,12 +30,7 @@ export class PersonalIdGenerator { return String(Iu.generate(e - 25, e - 55)).substring(2, 4) }, */ - getYearPart (year: bigint | null) { - if (!year) { - const e = (new Date()).getFullYear() - year = BigInt(randomGenerator.generate(e - 25, e - 55)) - } - + getYearPart (year: bigint) { return String(year).substring(2, 4) } @@ -80,9 +80,11 @@ export class PersonalIdGenerator { }, * @param country * @param gender + * @param year */ - getGenderPart (country: Country, gender: Gender) { + getGenderPart (country: Country, gender: Gender, year: bigint) { console.log(country, gender) + let tempGender = Gender.MALE switch (country) { case Country.POLAND: console.log(country) @@ -91,7 +93,11 @@ export class PersonalIdGenerator { : String(2 * randomGenerator.generate(1, 4)) default: console.log(gender, Gender.MALE === gender) - return Gender.MALE === gender ? '3' : '4' + if (Gender.RANDOM === gender) { + tempGender = randomGenerator.generate(1, 999) > 500 ? Gender.FEMALE : Gender.MALE + } + console.log(year, 'year', typeof year) + return Gender.MALE === tempGender ? (year > 2000 ? '3' : '5') : (year < 2000 ? '4' : '6') } }