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

fix: #2744 parcing logic while using 'Dayjs', 'Date', 'number' types in 'customParseFormat' plugin #2745

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<img width="70" src="https://github.com/user-attachments/assets/b3203350-34c1-4637-b8b1-d9b8bab346d3">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/alan-eu" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/18175329?s=52&v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
</a>
Expand Down
7 changes: 4 additions & 3 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function correctHours(time) {
}
}

function makeParser(format) {
function makeParser(format, dayjs) {
format = u(format, locale && locale.formats)
const array = format.match(formattingTokens)
const { length } = array
Expand All @@ -158,7 +158,8 @@ function makeParser(format) {
array[i] = token.replace(/^\[|\]$/g, '')
}
}
return function (input) {
return function (incomingInput) {
let input = typeof incomingInput === 'string' ? incomingInput : dayjs(incomingInput).format()
const time = {}
for (let i = 0, start = 0; i < length; i += 1) {
const token = array[i]
Expand All @@ -181,7 +182,7 @@ function makeParser(format) {
const parseFormattedInput = (input, format, utc, dayjs) => {
try {
if (['x', 'X'].indexOf(format) > -1) return new Date((format === 'X' ? 1000 : 1) * input)
const parser = makeParser(format)
const parser = makeParser(format, dayjs)
const {
year, month, day, hours, minutes, seconds, milliseconds, zone, week
} = parser(input)
Expand Down