12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package mgo
- import (
- "eta/eta_chart_lib/utils"
- "go.mongodb.org/mongo-driver/bson"
- "time"
- )
- func BuildDateCondition(start, end string) (condition bson.M, err error) {
- var startDateTime, endDateTime time.Time
- if start != "" {
-
- startDateTime, err = time.ParseInLocation(utils.FormatDate, start, time.Local)
- if err != nil {
- return
- }
- }
- if end != "" {
-
- endDateTime, err = time.ParseInLocation(utils.FormatDate, end, time.Local)
- if err != nil {
- return
- }
- }
- return BuildDateTimeCondition(startDateTime, endDateTime)
- }
- func BuildDateTimeCondition(startDateTime, endDateTime time.Time) (condition bson.M, err error) {
- if !startDateTime.IsZero() && !endDateTime.IsZero() {
- condition = bson.M{utils.DateConvMysqlConvMongo(">="): startDateTime, utils.DateConvMysqlConvMongo("<="): endDateTime}
- } else if !startDateTime.IsZero() {
- cond := utils.DateConvMysqlConvMongo(">=")
- condition = bson.M{cond: startDateTime}
- } else if !endDateTime.IsZero() {
- cond := utils.DateConvMysqlConvMongo("<=")
- condition = bson.M{cond: endDateTime}
- }
- return
- }
|