-
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.
- Loading branch information
Ulrich Lissé
committed
Apr 4, 2019
1 parent
51ee0f9
commit adec9dd
Showing
4 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 LocalDate struct { | ||
time time.Time | ||
} | ||
|
||
func Today() LocalDate { | ||
return From(time.Now().Local()) | ||
} | ||
|
||
func From(t time.Time) LocalDate { | ||
return LocalDate{time: t} | ||
} | ||
|
||
func Parse(s string) (LocalDate, error) { | ||
t, err := time.ParseInLocation(ISO8601, s, time.Local) | ||
if err != nil { | ||
return LocalDate{}, err | ||
} | ||
|
||
return From(t), nil | ||
} | ||
|
||
func (d LocalDate) Add(years int, months int, days int) LocalDate { | ||
return LocalDate{time: d.time.AddDate(years, months, days)} | ||
} | ||
|
||
func (d LocalDate) String() string { | ||
return d.time.Format(ISO8601) | ||
} |
File renamed without changes.
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