рефакторинг года

master
Sipachev Igor 3 years ago
parent 4e7a1adf56
commit 3411794a08
  1. 14
      popup/src/classes/Service/Generators/PersonalIdGenerator.ts

@ -8,11 +8,7 @@ export class PersonalIdGenerator {
* @param person * @param person
*/ */
generate (person: Person) { generate (person: Person) {
let fullYear = person.birthday.year const fullYear = this.grabFullYear(person.birthday.year)
if (!fullYear) {
const e = (new Date()).getFullYear()
fullYear = BigInt(randomGenerator.generate(e - 5, e - 55))
}
const year = this.getYearPart(fullYear) const year = this.getYearPart(fullYear)
const month = this.getMonthPart(person.birthday.month) const month = this.getMonthPart(person.birthday.month)
const day = this.getDayPart(person.birthday.day) const day = this.getDayPart(person.birthday.day)
@ -24,6 +20,14 @@ export class PersonalIdGenerator {
return a + year + month + day + o + l2 return a + year + month + day + o + l2
} }
grabFullYear (year: bigint | null): bigint {
if (!year) {
const e = (new Date()).getFullYear()
year = BigInt(randomGenerator.generate(e - 5, e - 55))
}
return year
}
/** /**
* e.getYearPart = function () { * e.getYearPart = function () {
var e = (new Date).getFullYear(); var e = (new Date).getFullYear();

Loading…
Cancel
Save