func ShowAll() { scheduleObjs := util.ReadObj() for i := 0; i < len(scheduleObjs.Schedules); i++ { scheduleObj := scheduleObjs.Schedules[i] parsedTime, _ := time.Parse(util.SaveTimeFormat, scheduleObj.Deadline) fmt.Println(scheduleObj.Id, "\t", parsedTime.Format(util.ShowTimeFormat), "\t", scheduleObj.Todo) } }
func Delete(id int) { scheduleList := util.ReadObj() newScheduleList := util.ScheduleList{scheduleList.MaxId, []util.Schedule{}} for i := 0; i < len(scheduleList.Schedules); i++ { if id != scheduleList.Schedules[i].Id { newScheduleList.Schedules = append(newScheduleList.Schedules, scheduleList.Schedules[i]) } } scheduleJson, _ := json.Marshal(newScheduleList) util.Write(string(scheduleJson)) }
// Add simply add single todo data with given title and deadline. func Add(title string, deadline time.Time) { scheduleObjs := util.ReadObj() id := 0 if len(scheduleObjs.Schedules) > 0 { id = scheduleObjs.MaxId + 1 } else { scheduleObjs = util.ScheduleList{id, []util.Schedule{}} } now := time.Now() schedule := util.Schedule{id, title, now.Format(util.SaveTimeFormat), deadline.Format(util.SaveTimeFormat)} scheduleObjs.MaxId = id scheduleObjs.Schedules = append(scheduleObjs.Schedules, schedule) scheduleJson, _ := json.Marshal(scheduleObjs) util.Write(string(scheduleJson)) }
func ShowBetween(beforeStr string, afterStr string) { before, beforeErr := time.Parse(util.SaveTimeFormat, beforeStr) after, afterErr := time.Parse(util.SaveTimeFormat, afterStr) todo := util.ReadObj() for i := 0; i < len(todo.Schedules); i++ { schedule := todo.Schedules[i] deadline, err := time.Parse(util.SaveTimeFormat, schedule.Deadline) if err != nil { continue } if len(beforeStr) > 0 && (beforeErr != nil || deadline.After(before)) { continue } if len(afterStr) > 0 && (afterErr != nil || deadline.Before(after)) { continue } parsedTime, _ := time.Parse(util.SaveTimeFormat, schedule.Deadline) fmt.Println(schedule.Id, "\t", parsedTime.Format(util.ShowTimeFormat), "\t", schedule.Todo) } }