Coder Social home page Coder Social logo

Comments (14)

iamkun avatar iamkun commented on May 7, 2024 3

fixed thanks

from dayjs.

Imperat avatar Imperat commented on May 7, 2024 2

Fantastic! It has same results. Thank you!

from dayjs.

iamkun avatar iamkun commented on May 7, 2024

Thanks, should be a bug. Will check it soon

from dayjs.

tareqlol-zz avatar tareqlol-zz commented on May 7, 2024

I have checked other related issues mentioning that replacing the dashes and "T" will solve it for now but I guess it should be fixed !73
.replace(/-/g,'/').replace('T', ' ')
image
Just wanted to reference it in case it helps. Thanks :)

from dayjs.

Imperat avatar Imperat commented on May 7, 2024

Hi, @iamkun. I'm going to update regular expression and fix the function parseDate. But I misunderstand why we need to parse the string in ISO 8601 format in this place:

  if ((typeof date === 'string') && (reg = date.match(C.REGEX_PARSE))) {
    // 2018-08-08 or 20180808
    return new Date(
      reg[1], reg[2] - 1, reg[3] || 1,
      reg[5] || 0, reg[6] || 0, reg[7] || 0, reg[8] || 0
    )
  }

instead to pass this string into constructor directly:

if (typeof date === 'string') {
  return new Date(date);
}

Can you clarify it, please?

from dayjs.

iamkun avatar iamkun commented on May 7, 2024

The regex is used to parse date string like 2018-01-01, 2018-01 that is not in ISO format.

But in the case, this date string passed our regex, which is incorrect.

from dayjs.

Imperat avatar Imperat commented on May 7, 2024

Thank you, @iamkun. Just another question.
The last matching group from regular expression:
.?(\d{1,3})
It means amount of milliseconds?
We pass it as last argument to new Date() constructor.
I'm afraid that we have the bug in this place also.

from dayjs.

Imperat avatar Imperat commented on May 7, 2024

For example:
12:20:12.1 means 1/10 part of second - 100 milliseconds.
12:20:12.10 means 10/100 (1/10 also )
12:20:12.123 means 123 milliseconds
But I see that we take this value from string and pass it as milliseconds.
Please, let me know if I'm wrong.

from dayjs.

iamkun avatar iamkun commented on May 7, 2024

No, according to JS Date object, 12:20:12.1 means 12:20:12:001

from dayjs.

Imperat avatar Imperat commented on May 7, 2024

It's strange, because of 2018-01-02T12:20:12.1 is correct ISO 8601 string with 100 milliseconds.
Quote from Wikipedia:
Decimal fractions may be added to any of the three time elements. However, a fraction may only be added to the lowest order time element in the representation. A decimal mark, either a comma or a dot (without any preference as stated in resolution 10 of the 22nd General Conference CGPM in 2003,[24] but with a preference for a comma according to ISO 8601:2004)[25] is used as a separator between the time element and its fraction. To denote "14 hours, 30 and one half minutes", do not include a seconds figure. Represent it as "14:30,5", "1430,5", "14:30.5", or "1430.5". There is no limit on the number of decimal places for the decimal fraction. However, the number of decimal places needs to be agreed to by the communicating parties. For example, in Microsoft SQL Server, the precision of a decimal fraction is 3, i.e., "yyyy-mm-ddThh:mm:ss[.mmm]".[26]

If we write in our doc that we support standard ISO 8601, do we need to fix this behavior or not?

from dayjs.

iamkun avatar iamkun commented on May 7, 2024

That's different. We are correct. You could try it yourself before submitting comments.

from dayjs.

Imperat avatar Imperat commented on May 7, 2024

I try next code:

console.log(dayjs('2018-05-14T08:50:23.1').valueOf())
console.log(dayjs('2018-05-14T08:50:23.100').valueOf())

and it has different output:

1526273423001
1526273423100

Sorry for confusing, I just misunderstand why in Wikipedia it's written that it can be interpreted as decimal fraction (according ISO 8601), but we mean that this is just milliseconds :(

from dayjs.

iamkun avatar iamkun commented on May 7, 2024

try '2018-05-14T08:50:23.1Z' then, THIS IS ISO 8601 format.

from dayjs.

zctya avatar zctya commented on May 7, 2024

抓紧时间修复啊 @iamkun ^_^

from dayjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.