diff options
author | Andinus <andinus@nand.sh> | 2020-03-24 19:52:43 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-24 19:52:43 +0530 |
commit | e6b0afd6b97b2402e218583e7c22551b383712df (patch) | |
tree | 51b2f620a0dac0698ed70045e0584974060352c6 /apod/randomdate.go | |
parent | a5f291028dbcc11bd54aa610e4c64270c6a3d022 (diff) | |
download | cetus-e6b0afd6b97b2402e218583e7c22551b383712df.tar.gz |
Add apod package
Diffstat (limited to 'apod/randomdate.go')
-rw-r--r-- | apod/randomdate.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/apod/randomdate.go b/apod/randomdate.go new file mode 100644 index 0000000..743b447 --- /dev/null +++ b/apod/randomdate.go @@ -0,0 +1,31 @@ +package apod + +import ( + "math/rand" + "time" +) + +// RandDate returns a random date between 1995-06-16 & today. +func RandDate() string { + var ( + min int64 + max int64 + sec int64 + delta int64 + date string + ) + min = time.Date(1995, 6, 16, 0, 0, 0, 0, time.UTC).Unix() + + // We are taking max from UTC but it could fail if the + // timezone on NASA APOD server is any different. They don't + // mention the timezone api server uses so we use UTC & the + // probability of this function failing because of this issue + // is very low. + max = time.Now().UTC().Unix() + delta = max - min + + sec = rand.Int63n(delta) + min + date = time.Unix(sec, 0).Format("2006-01-02") + + return date +} |