export function getAgeBirth(strBirthday) {
let returnAge
const strBirthdayArr = strBirthday.split('-')
const birthYear = strBirthdayArr[0]
const birthMonth = strBirthdayArr[1]
const birthDay = strBirthdayArr[2]
const d = new Date()
const nowYear = d.getFullYear()
const nowMonth = d.getMonth() + 1
const nowDay = d.getDate()
if (nowYear === birthYear) {
returnAge = 0
} else {
const ageDiff = nowYear - birthYear
if (ageDiff > 0) {
if (nowMonth === birthMonth) {
const dayDiff = nowDay - birthDay
if (dayDiff < 0) {
returnAge = ageDiff - 1
} else {
returnAge = ageDiff
}
} else {
const monthDiff = nowMonth - birthMonth
if (monthDiff < 0) {
returnAge = ageDiff - 1
} else {
returnAge = ageDiff
}
}
} else {
returnAge = '0'
}
}
return returnAge
}
export function timeForMat(count) {
const date = new Date()
const nowDate = processingTime()
const LDate = new Date(date - 1000 * 60 * 60 * 24 * count)
const year = LDate.getFullYear()
const month = LDate.getMonth() + 1
const day = LDate.getDate()
const temp = {
startTime: year + '/' + (month < 10 ? '0' + month : month) + '/' + (day < 10 ? '0' + day : day),
endTime: nowDate
}
return temp
}
export function go(val) {
const iden = val
let sex = null
let birth = null
if (val.length === 18) {
sex = iden.substring(16, 17)
birth = iden.substring(6, 10) + '/' + iden.substring(10, 12) + '/' + iden.substring(12, 14)
}
if (val.length === 15) {
sex = iden.substring(13, 14)
birth = '19' + iden.substring(6, 8) + '/' + iden.substring(8, 10) + '/' + iden.substring(10, 12)
}
if (sex % 2 === 0) { sex = '女' } else { sex = '男' }
return {
sex,
birth
}
}
function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
}
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]'
}
export function equalsObj(oldData, newData) {
if (oldData === newData) return true
if (isObject(oldData) && isObject(newData) && Object.keys(oldData).length === Object.keys(newData).length) {
for (const key in oldData) {
if (oldData.hasOwnProperty(key)) {
if (!equalsObj(oldData[key], newData[key])) {
return false
}
}
}
} else if (isArray(oldData) && isArray(newData) && oldData.length === newData.length) {
for (let i = 0, length = oldData.length; i < length; i++) {
if (!equalsObj(oldData[i], newData[i])) {
return false
}
}
} else {
return false
}
return true
}