JerrySievert/date-utils

d.getMonthsBetween(date);

Closed this issue · 28 comments

It would be handy to have a getMonthsBetween.

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.

+1 for this action.

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

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);

@JerrySievert Let's go with that.

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

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

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

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

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

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!

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.

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.

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

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.

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?

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.

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.

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?

pushed.

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

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

@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.

@JerrySievert Ok. Got it. :)

@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.

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.

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.

@JerrySievert Ok. Standalone it is then. :)

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!