Code Monkey home page Code Monkey logo

Comments (6)

knowledgecode avatar knowledgecode commented on June 11, 2024

The code you tried is this?

date.parse('1/1/1', 'DD/MM/Y');

In the latest version, this code will return Invalid Date. That is, error. Are you using the latest version?

from date-and-time.

demigor avatar demigor commented on June 11, 2024

from date-and-time.

knowledgecode avatar knowledgecode commented on June 11, 2024

Could you show reproducible code here?

and 1/1/0 or 1/1/00 cannot be parsed at all.

It's in the specifications.

from date-and-time.

demigor avatar demigor commented on June 11, 2024

What pattern should I use to parse as following:

1/1/1 -> 1 January 2001
1/1/0 -> 1 January 2000
1/1/20 -> 1 January 2020
1/1/75 -> 1 January 1975

Current version seems lost this distinctive feature, the only reason we have chosen date-and-time package.

from date-and-time.

knowledgecode avatar knowledgecode commented on June 11, 2024

I doubt it is parsed 1/1/1 as 1/1/1901. Cannot reproduce it.

Hm...

Anyway, to get this library to do what you want, you need to override the default behavior of it. For example like this:

var date = require('date-and-time');

// Override the default behavior of the YY token.
date.extend({
    parser: {
        YY: function (str) {
            var result = this.exec(/^\d{1,2}/, str);
            result.value += result.value < 70 ? 2000 : result.value < 100 ? 1900 : 0;
            return result;
        }
    }
})

// Use the YY token instead of the Y.
date.parse('1/1/1', 'D/M/YY');  // => 1/1/2001
date.parse('1/1/0', 'D/M/YY');  // => 1/1/2000
date.parse('1/1/20', 'D/M/YY'); // => 1/1/2020
date.parse('1/1/75', 'D/M/YY'); // => 1/1/1975

from date-and-time.

demigor avatar demigor commented on June 11, 2024

So we have to downgrade to 0.6.3 version, which successfully parses 1/1/1, 1/1/0, etc.

Usually package breaking changes do not introduce degradation in functionality, what is not the case here.

from date-and-time.

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.