GithubHelp home page GithubHelp logo

Dates and ISO 8601 about hermes HOT 4 CLOSED

facebook avatar facebook commented on April 25, 2024
Dates and ISO 8601

from hermes.

Comments (4)

Boris-c avatar Boris-c commented on April 25, 2024

Just for clarity, a simpler example of the parsing bug:

new Date('2019-08-07T00:00:00.5Z') gives 2019-08-07T00:00:00.005Z

5 milliseconds is wrong, should be 500 milliseconds

from hermes.

avp avatar avp commented on April 25, 2024

Thanks for the bug report. We'll work on fixing this.

from hermes.

Boris-c avatar Boris-c commented on April 25, 2024

Just in case someone would like to find a JavaScript workaround for the bug, here is mine (I don't pretend it's universal, but it can be a starting point for others to wait for your fix instead of simply avoiding to use Hermes).

Just call that once at app startup:

if (__DEV__ || (new Date('2019-08-07T00:00:00.5Z')).getMilliseconds() === 5) {
  const millisDate = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d+)Z$/
  const _Date = Date;

  function MockDate(y, m, d, h, M, s, ms) {
    let date = undefined;

    switch (arguments.length) {
      case 0: return new _Date();
      case 1:
        if (typeof y === 'string') {
          const matches = y.match(millisDate);
          if (matches) {
            const [_, yy, mm, dd, hh, MM, ss, mmss] = matches;
            const fixed = Math.floor(new Number('.' + mmss) * 1000);
            const fixedStr = `${fixed}`.padStart(3, '0');
            return new _Date(`${yy}-${mm}-${dd}T${hh}:${MM}:${ss}.${fixed}Z`);
          }
        }
        return new _Date(y);
      default: return new _Date(y, m, d, h, M, s, ms);
    }
  }

  Object.setPrototypeOf(MockDate, _Date);
  Date = MockDate;
}

from hermes.

avp avatar avp commented on April 25, 2024

Fixed in a084c4d

from hermes.

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.