2022-05-26 08:35:39 +02:00
|
|
|
package date_range
|
2022-05-11 15:57:56 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
2022-05-26 08:35:39 +02:00
|
|
|
|
|
|
|
"github.com/golang-module/carbon/v2"
|
2022-05-11 15:57:56 +02:00
|
|
|
)
|
|
|
|
|
2022-05-26 08:35:39 +02:00
|
|
|
func ParseDateRange(q url.Values) (string, string) {
|
2022-05-11 15:57:56 +02:00
|
|
|
var from, to string
|
|
|
|
|
|
|
|
qFrom := q.Get("from")
|
|
|
|
qTo := q.Get("to")
|
|
|
|
|
|
|
|
parseFrom := carbon.Parse(qFrom)
|
|
|
|
parseTo := carbon.Parse(qTo)
|
|
|
|
|
|
|
|
if parseFrom.Error != nil || parseTo.Error != nil || qFrom == "" || qTo == "" {
|
|
|
|
from = carbon.Now().StartOfMonth().ToDateString()
|
|
|
|
to = carbon.Now().EndOfMonth().ToDateString()
|
|
|
|
} else {
|
|
|
|
from = parseFrom.ToDateString()
|
|
|
|
to = parseTo.ToDateString()
|
|
|
|
}
|
|
|
|
|
|
|
|
return from, to
|
|
|
|
}
|