pingjiang / datejs

Automatically exported from code.google.com/p/datejs
Other
0 stars 0 forks source link

Feature request: Date difference #86

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A frequent need for me is to display a human-readable difference between
two dates - for example how long until Christmas?

It's easy enough to do this in days and seconds, or even weeks etc, but I'd
really like to see "3 months, 20 days" or (in terms of times, not just
dates) "3 months, 19 days, 3 hours, 7 minutes". Getting the month
calculations right is hard (not undefined, as far as I know, but certainly
complex) and it would be nice to have a library routine to use, rather than
have to reinvent the logic myself each time.

The output should probably be an object, with "years", "months", "days",
etc attributes, which can be formatted manually, rather than a preformatted
string.

Original issue reported on code.google.com by p.f.mo...@gmail.com on 5 Sep 2009 at 7:55

GoogleCodeExporter commented 9 years ago
This would be a very useful feature.

Original comment by Steve.J....@gmail.com on 13 Aug 2010 at 10:38

GoogleCodeExporter commented 9 years ago
this would be a very very useful feature!

Original comment by brad.p...@gmail.com on 10 May 2012 at 6:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Moment.js have this feature called "humanize"

Regards !

Original comment by nokioxt...@gmail.com on 12 Aug 2012 at 6:07

GoogleCodeExporter commented 9 years ago
As far as I can see, moment.js humanize() only returns an approximate answer. 
For example, today "moment([2012,8,24,2,12,36]).from(moment([2012,1,1]))" says 
"in 8 months" where as I would want "8 months, 24 days, 2 hours, 12 minutes and 
36 seconds". (Actually there's a timezone correction as well, as we're 
currently in summer time, but I wouldn't be bothered if that was ignored...)

Actually, the docs also state: "The length of a duration in months is defined 
as 30 days". That's *not* what I want :-(

Otherwise, it's a nice library - thanks for pointing it out.

Original comment by p.f.mo...@gmail.com on 24 Aug 2012 at 9:07

GoogleCodeExporter commented 9 years ago
This is in DateJS as TimePeriod. You just pass it two dates and it returns an 
object with all the things you just asked for.

It's in the SVN but it's actively maintained in my fork (I actually *just* 
fixed a small bug with it too) here: https://github.com/abritinthebay/datejs/

Original comment by darkcr...@gmail.com on 16 Sep 2013 at 7:18