jokes-bapak2/api/utils/date.go

21 lines
363 B
Go
Raw Permalink Normal View History

2021-07-09 06:11:11 +00:00
package utils
import "time"
// IsToday checks if a date is in fact today or not.
func IsToday(date string) (bool, error) {
2021-07-14 18:17:01 +00:00
if date == "" {
return false, nil
}
2021-07-09 12:13:19 +00:00
parse, err := time.Parse(time.RFC3339, date)
2021-07-09 06:11:11 +00:00
if err != nil {
return false, err
}
2021-07-09 12:13:19 +00:00
y1, m1, d1 := parse.Date()
y2, m2, d2 := time.Now().Date()
2021-07-09 06:11:11 +00:00
2021-07-09 12:13:19 +00:00
return y1 == y2 && m1 == m2 && d1 == d2, nil
2021-07-09 06:11:11 +00:00
}