Skip to content

Commit

Permalink
feat(dayjs): Optimize performance by reducing unnecessary computation…
Browse files Browse the repository at this point in the history
…s and memory usage
  • Loading branch information
Jerry965 committed Nov 30, 2024
1 parent 72f2aa3 commit 418a184
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ class Dayjs {
if (!this.isValid()) return locale.invalidDate || C.INVALID_DATE_STRING

const str = formatStr || C.FORMAT_DEFAULT
const zoneStr = Utils.z(this)
const { $H, $m, $M } = this
const {
weekdays, months, meridiem
Expand Down Expand Up @@ -330,15 +329,19 @@ class Dayjs {
return Utils.s(this.$s, 2, '0')
case 'SSS':
return Utils.s(this.$ms, 3, '0')
case 'Z':
return zoneStr // 'ZZ' logic below
case 'ZZ':
case 'Z': {
const zoneStr = Utils.z(this)
if (match === 'ZZ') return zoneStr.replace(':', '')
return zoneStr
}
default:
break
}
return null
}

return str.replace(C.REGEX_FORMAT, (match, $1) => $1 || matches(match) || zoneStr.replace(':', '')) // 'ZZ'
return str.replace(C.REGEX_FORMAT, (match, $1) => $1 || matches(match))
}

utcOffset() {
Expand Down

0 comments on commit 418a184

Please sign in to comment.