Comments (28)
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.
+1 for this action.
from date-utils.
@JerrySievert Would you accept a PR for this? Does the function I proposed look reasonable to you?
from date-utils.
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.
@JerrySievert Let's go with that.
How do you generate the minified version? I don't see a build script around.
from date-utils.
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.
@JerrySievert Ok. What if I set up a gulp
build for you in a separate PR?
from date-utils.
i normally stick with grunt
, but would happily accept a gulp
pull request.
from date-utils.
@JerrySievert I made PR for gulp
build. Once that's merged, I'll implement this one.
from date-utils.
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.
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.
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.
agreed, but the project is big enough now that it needs a lot better documentation than it currently has.
from date-utils.
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.
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.
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.
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.
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.
pushed.
from date-utils.
also added complexity - should be very helpful during a refactor for v2
from date-utils.
@JerrySievert Not seeing it yet. Maybe you need to do something along git push origin docs
.
from date-utils.
@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.
@JerrySievert Ok. Got it. :)
from date-utils.
@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.
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.
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.
@JerrySievert Ok. Standalone it is then. :)
from date-utils.
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)
- How do you feel about... ? HOT 1
- subtract instance methods HOT 10
- Version 2 Feature Discussion HOT 14
- Add `remove` to README
- error in the parsing of the weekday HOT 1
- getDaysBetween returns wrong number HOT 3
- No bower versions HOT 3
- How to set one special Date() object? HOT 1
- Browser support? HOT 2
- Number of Days between HOT 3
- site.flatly.css contains a broken import according to cssmin
- Property 'jui' redefine problem HOT 1
- Official typescript typings HOT 3
- getMonthsBetween inconsitency HOT 7
- Method getMonthAbbrNameFromNumber doesn't exists
- SCRIPT1046: Multiple definitions of a property not allowed in strict mode
- Cannot find module 'date-utils' HOT 2
- Function add/addMonths compute error HOT 3
- on node v10,Do I still need this polyfill ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from date-utils.