-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
# Conflicts: # mite/time_entry.go
- Loading branch information
Showing
4 changed files
with
53 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package date | ||
|
||
import "time" | ||
|
||
const ISO8601 = "2006-01-02" | ||
|
||
type Date struct { | ||
time time.Time | ||
} | ||
|
||
func Today() Date { | ||
return From(time.Now()) | ||
} | ||
|
||
func From(time time.Time) Date { | ||
return Date{time: time} | ||
} | ||
|
||
func Parse(date string) (Date, error) { | ||
t, err := time.Parse(ISO8601, date) | ||
if err != nil { | ||
return Date{}, err | ||
} | ||
|
||
return From(t), nil | ||
} | ||
|
||
func (d Date) Add(years int, months int, days int) Date { | ||
return Date{time: d.time.AddDate(years, months, days)} | ||
} | ||
|
||
func (d Date) String() string { | ||
return d.time.Format(ISO8601) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters