Coder Social home page Coder Social logo

Comments (28)

bebraw avatar bebraw commented on July 17, 2024

There's a possible implementation over at Stack Overflow.

I've settled for something like this myself:

function getMonthsBetween(from, to) {
    var toYear = to.getYear();
    var fromYear = from.getYear();
    var toMonth = to.getMonth();
    var fromMonth = from.getMonth();

    return (toYear - fromYear) * 12 + (toMonth - fromMonth);
}

There is no one clear way to define the difference apparently so I guess you would just have to pick one convention and document it.

from date-utils.

sonisaurabh19 avatar sonisaurabh19 commented on July 17, 2024

+1 for this action.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Would you accept a PR for this? Does the function I proposed look reasonable to you?

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

i would accept a pull request, but i also wonder if:

var d1 = new Date();
var d2 = new Date().add({ months: 2});
d1.getMonthsBetween(d2);

might also be good - essentially calling Date.getMonthsBetween(this, that);

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Let's go with that.

How do you generate the minified version? I don't see a build script around.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

i build it by hand. the library much predates grunt and companions - at some point i will add grunt and a true minifier.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Ok. What if I set up a gulp build for you in a separate PR?

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

i normally stick with grunt, but would happily accept a gulp pull request.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert I made PR for gulp build. Once that's merged, I'll implement this one.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

Hey, I realized there's actually getMonthsBetween as a polyfill already. Demo:

require('date-utils);

var a = new Date(2013, 2, 30);
var b = new Date(2013, 4, 30);

console.log(a.getMonthsBetween(b)); // 2.00215

That's in test spec too.

Please mention this at README amongst instance methods and close the issue. Thanks!

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

ultimately, the README is not the best place for any of this. the code should really be documented all the way through, and exported as a github site.

i can start that up.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

ultimately, the README is not the best place for any of this. the code should really be documented all the way through, and exported as a github site.

Ok, cool!

Keep in mind having a clear README is important as it's the entry point for users that come through NPM.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

agreed, but the project is big enough now that it needs a lot better documentation than it currently has.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

agreed, but the project is big enough now that it needs a lot better documentation than it currently has.

Sure! Let me know if you need something in terms of tooling etc.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

sorry for taking so long to get back - been slammed with my "day job" for the last couple of weeks.

i'd prefer jsdoc (javascript version), and see that there is a gulp plugin for it - do you want to start, and i can jump in with more docs as my weekend opens up?

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

sorry for taking so long to get back - been slammed with my "day job" for the last couple of weeks.

No probs. That's completely understandable. Given it's Summer time things can take longer than usual. :)

i'd prefer jsdoc (javascript version), and see that there is a gulp plugin for it - do you want to start, and i can jump in with more docs as my weekend opens up?

What are your thoughts on v2 (#37)? To make it easier to document we could look into reducing API surface area. Personally I dislike Doxygen style docs that state the obvious. If we can get a tight design on the API, it's easier to document, and more importantly, to use.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

been updating documentation - seem to have run into a bug in either gulp-jsdoc or its documentation.

either way, at least getting a bit of the functionality documented.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

been updating documentation - seem to have run into a bug in either gulp-jsdoc or its documentation.

Can you push the branch up so I can have a look?

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

pushed.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

also added complexity - should be very helpful during a refactor for v2

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Not seeing it yet. Maybe you need to do something along git push origin docs.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

@bebraw https://github.com/JerrySievert/node-date-utils/blob/master/gulpfile.js#L20-L23

pushed to master, since it's 0 code change to the library itself.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Ok. Got it. :)

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Does a standalone jsdoc build work for you? If we can't get the plugin to work, maybe we could skip it and patch something together using something like gulp-shell.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

standalone jsdoc works like a charm - looks like other people are having the same issue with gulp-jsdoc, so it might be an issue with the package itself.

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

looks like gulp-jsdoc is not going to work. it now has a disclaimer that it doesn't work and is now unmaintained for the time being. standalone should be fine.

from date-utils.

bebraw avatar bebraw commented on July 17, 2024

@JerrySievert Ok. Standalone it is then. :)

from date-utils.

JerrySievert avatar JerrySievert commented on July 17, 2024

i added a ton of documentation and set up gulp-shell for doc creation. i also added a gh-pages branch.

i will make another doc pass and finish up sometime after world cup (that may not be today).

i also marked a ton of things deprecated, to help get ready for a version 2.

all of that said, going to close this ticket, it's been a fun one!

from date-utils.

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.