Skip to content

Commit

Permalink
fixed bug in difference as float and readme update (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kofoworola authored Apr 30, 2019
1 parent da9aa2a commit 0e0c619
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ Sun Apr 28 17:53:11 +0000 UTC 2019
## Methods
```
now := godate.Now(time.UTC)
now.IsAfter(now.Add(1,godate.DAYS)) //false
now.IsAfter(now.Sub(1,godate.DAYS)) //true
now.IsBefore(now.Add(1,godate.DAYS)) //true
now.IsBefore(now.Sub(1,godate.DAYS)) //false
now.IsAfter(now.Add(1,godate.DAY)) //false
now.IsAfter(now.Sub(1,godate.DAY)) //true
now.IsBefore(now.Add(1,godate.DAY)) //true
now.IsBefore(now.Sub(1,godate.DAY)) //false
```

The `Add()` and `Sub()` methods takes two parameters, the `count` and the
`unit` to add which is any of the constants
```
SECONDS
MINUTES
HOURS
DAYS
WEEKS
MONTHS
YEARS
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
YEAR
```


### Difference
```
now := godate.Now(time.UTC)
now.Difference(now.Sub(1,godate.DAYS),godate.DAYS) //1
now.Difference(now.Add(7,godate.DAYS),godate.WEEKS) //-1
now.Difference(now.Sub(1,godate.DAY),godate.DAY) //1
now.Difference(now.Add(7,godate.DAY),godate.WEEK) //-1
```

The `Difference()` method returns the difference of the passed `godate`
Expand Down
2 changes: 1 addition & 1 deletion godate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (d GoDate) Difference(compare *GoDate, unit Unit) int {
//Get the difference as a float
func (d GoDate) DifferenceAsFloat(compare *GoDate, unit Unit) float64 {
duration := d.DifferenceAsDuration(compare)
return float64(duration / time.Duration(unit))
return float64(duration) / float64(time.Duration(unit))
}

//Gets the difference between the relative to the date value in the form of
Expand Down

0 comments on commit 0e0c619

Please sign in to comment.