Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar changes #133

Merged
merged 4 commits into from
Aug 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions chapters/dates_and_times/days-between-two-dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ chapter: Dates and Times
---
## Problem

You need to find how much seconds minutes, hours, days, months or years has passed between two dates.
You need to find how many seconds, minutes, hours, days, months or years have passed between two dates.

## Solution

Use JavaScript's Date function getTime(). Which provides how much time in milliseconds has passed since 01/01/1970:
Use JavaScript's Date function getTime(). Which provides how much time in milliseconds have passed since 01/01/1970:

{% highlight coffeescript %}
DAY = 1000 * 60 * 60 * 24
Expand All @@ -22,12 +22,10 @@ days_passed = Math.round((d2.getTime() - d1.getTime()) / DAY)

## Discussion

Using milliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how much milliseconds has a day.
Then, given two distinct dates, just get the difference in milliseconds between two dates and then divide by how much milliseconds has a
day. It will get you the days between two distinct dates.
Using milliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how many milliseconds are in a day.
Then, given two distinct dates, get the difference in milliseconds between two dates and then divide by how many milliseconds are in a day. It will return the days between two distinct dates.

If you'd like to calculate the hours between two date objects, you can do that just by dividing the difference in milliseconds by the
conversion of milliseconds to hours. The same goes for minutes and seconds.
If you'd like to calculate the hours between two date objects, you can do that by dividing the difference in milliseconds by the conversion of milliseconds to hours. The same goes for minutes and seconds.

{% highlight coffeescript %}
HOUR = 1000 * 60 * 60
Expand Down