在这里,我有一个日程安排网页,我们可以按日安排一个人的日程表,就像有一个人一样,他/她说它会对Sunday 07(month)-01(day)-2018(year) 08:00AM to 10:00AM
起作用,然后一段时间之后它说全部都工作了 7月的周日08:00 AM至10:00 AM 因此有一个开始日期和结束日期表示开始日期为 07-01-2018至07-31-2018 ,同时保存记录它将验证这意味着如果当天存在相同的工作时间然后它会提示更新它们然后我会点击更新然后它只会更新现有日期的_id
它不会保存工人说的所有日期。我怎么能忍受它,任何人都可以帮助我。我使用的代码如下: -
验证当天: -
conditions := bson.M{"provider":schedule.Provider, "day":day}
data, err := models.GetSchedulingListing(conditions)
for i := range data {
// id := data[i].Id
start_time := data[i].StartTime
end_time := data[i].EndTime
start_working_hours := time.Unix(start_time,0)
end_working_hours := time.Unix(end_time,0)
db_start_seconds := start_working_hours.Hour() * 60 * 60 + start_working_hours.Minute() * 60 + start_working_hours.Second()
db_end_seconds := end_working_hours.Hour() * 60 * 60 + end_working_hours.Minute() * 60 + end_working_hours.Second()
selected_start_time := time.Unix(schedule.StartTime,0).Hour() * 60 * 60 + time.Unix(schedule.StartTime,0).Minute() * 60 +time.Unix(schedule.StartTime,0).Second()
selected_end_time := time.Unix(schedule.EndTime,0).Hour() * 60 * 60 + time.Unix(schedule.EndTime,0).Minute() * 60 +time.Unix(schedule.EndTime,0).Second()
if selected_start_time == db_start_seconds && selected_end_time >= db_end_seconds{
errMsg = "This schedule is set ."
return
}
if selected_end_time == db_end_seconds && selected_start_time <= db_start_seconds {
errMsg = "This schedule is set ."
return
}
if selected_start_time == db_end_seconds && selected_end_time > db_start_seconds {
errMsg = "This schedule is set ."
return
}
for i = selected_start_time ; i < selected_end_time ; i++ {
if selected_start_time <= db_start_seconds && selected_end_time >= db_end_seconds {
errMsg = "This schedule is set ."
return
}
}
var array1 []int
var array2 []int
for i = db_start_seconds ; i < db_end_seconds-1 ; i++ {
if selected_start_time == db_start_seconds || selected_end_time == db_start_seconds {
array1 = append(array1, db_start_seconds)
array2 = append(array2, db_end_seconds)
// fmt.Println(array1)
errMsg = "This schedule is set ."
return
}
db_start_seconds = db_start_seconds + 1
}
for i = selected_start_time ; i > selected_end_time ; i++ {
if selected_start_time == db_start_seconds || selected_start_time == db_end_seconds {
array1 = append(array1, db_start_seconds)
array2 = append(array2, db_end_seconds)
fmt.Println(array1)
errMsg = "This schedule is set ."
return
}
selected_start_time = selected_start_time - 1
}
}
保存日期和时间: -
days:= time.Unix(to.Unix(),0).Sub(time.Unix(from.Unix(),0)).Hours() / 24
fmt.Println(days)
var array []string
for i := 1; i <= int(days+1); i++ {
if day == time.Unix(start_date,0).Weekday().String() {
fmt.Println("Match")
schedule.StartDate = start_date
schedule.EndDate = start_date
schedule.Day = day
schedule.Location = c.PostForm("selectedlocation")
schedule.Occurence = "repeat"
// schedule.StartTime
// schedule.EndTime
schedule.AddedOn = time.Now().Unix()
result, err := models.GetAutoIncrementCounter(config.ScheduleCounterId, config.ScheduleCollection)
schedule.Id = result
reqBody := new(models.Schedule)
err = c.Bind(reqBody)
if err != nil {
fmt.Println(err)
}
fmt.Println(array)
err = models.AddSchedule(&schedule)
}
start_date = start_date + 86400
}
更新ID: -
value := c.Query("code")
fmt.Println(value)
response := ResponseController{}
stringSlice := strings.Split(value, ",")
for i := 0; i < len(stringSlice); i++ {
id, err := strconv.Atoi(stringSlice[i])
fmt.Println(id)
start_hour,_:= strconv.ParseInt(c.PostForm("Starthour"),10,64)
start_minutes,_ := strconv.ParseInt(c.PostForm("startminute"),10,64)
start_time := (start_hour-5)*60*60 + (start_minutes-30)*60
end_hour,_ := strconv.ParseInt(c.PostForm("endhour"),10,64)
end_minutes,_ := strconv.ParseInt(c.PostForm("endminute"),10,64)
end_time := (end_hour-5)*60*60 + (end_minutes-30)*60
schedule.Occurence = "repeat"
schedule.UpdatedOn = time.Now().Unix()
reqBody := new(models.Schedule)
err = c.Bind(reqBody)
if err != nil {
fmt.Println(err)
}
fmt.Println(&schedule)
var errMsg string
if err := models.UpdateScheduleID(id, bson.M{"$set": bson.M{"start_time": start_time, "end_time":end_time}}); err == nil {
successMsg := "The schedule has been updated successfully!"
}else{
ereMsg:= "There is any error"
}
}
return
}
虽然还有另一天,但我如何添加星期日或一周中任何其他日期的月份日期 我使用Mongodb数据库 。< / p>