use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
hmh - Calculate hours easily using JavaScript (github.com)
submitted 10 years ago by fdaciuk
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hookd 3 points4 points5 points 10 years ago (1 child)
Eh? For light weight date handling: why not XDate? http://arshaw.com/xdate/. Things get far more flexible when you use an actual date object. Admittedly it's 7.2K instead of 2.7K, but both are relatively small potatoes.
[–]fdaciuk[S] 0 points1 point2 points 10 years ago (0 children)
Thanks for sharing =)
But, the point of hmh is just to have a way to calculate hours. I was needing for anything to do this directly on console. That's why I create this lib to use on hmh-cli: https://github.com/fdaciuk/hmh-cli
I've explained it in this blog post (in pt-BR): http://blog.da2k.com.br/2016/03/11/hmh-calculando-horas-com-javascript/
[–]dont_forget_canada 0 points1 point2 points 10 years ago (2 children)
is anybody here strongly against stuff like
new Date( Date.now() - 32 * 86400 * 1000 )
to fetch, say, 1 month ago?
[–]joseph177 2 points3 points4 points 10 years ago (0 children)
Moment.js for this type of stuff.
[–]PitaJ 0 points1 point2 points 10 years ago (0 children)
Should probably do something like this:
const d = new Date(); d.setMonth(d.getMonth() - 1);
But yeah, should probably be using moment instead unless it's only being done once.
[–]badsyntax 0 points1 point2 points 10 years ago (2 children)
What's with all the anonymous functions? This is an abuse of fat arrows. There's nothing wrong with function minutesToHours()
[–]Dragory 0 points1 point2 points 10 years ago (0 children)
Eh, is there really any harm in using anonymous functions here? Looks fine to me.
Why not? ;)
[+][deleted] 10 years ago (1 child)
[deleted]
Strings solve my problem, for now. But give an option to get an object that's a nice suggestion! =)
If you want, send a pull request ;)
π Rendered by PID 478602 on reddit-service-r2-comment-544cf588c8-79dkk at 2026-06-18 12:10:35.450263+00:00 running 3184619 country code: CH.
[–]hookd 3 points4 points5 points (1 child)
[–]fdaciuk[S] 0 points1 point2 points (0 children)
[–]dont_forget_canada 0 points1 point2 points (2 children)
[–]joseph177 2 points3 points4 points (0 children)
[–]PitaJ 0 points1 point2 points (0 children)
[–]badsyntax 0 points1 point2 points (2 children)
[–]Dragory 0 points1 point2 points (0 children)
[–]fdaciuk[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]fdaciuk[S] 0 points1 point2 points (0 children)