Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dayjs): Optimize performance by reducing unnecessary computation… #2780

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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