diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-23 11:43:26 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-23 11:43:26 +0200 |
| commit | 3bbc28806f43c323b21d9053a9e25c89614d5f60 (patch) | |
| tree | 58765389496b737cfc50f07f408ca17ff9388b89 /sqlite.go | |
| parent | 404386194b9492b29b03d4e1e65558c545a70b51 (diff) | |
Frames and Timedebug0.3.2
Diffstat (limited to 'sqlite.go')
| -rw-r--r-- | sqlite.go | 258 |
1 files changed, 164 insertions, 94 deletions
@@ -176,10 +176,10 @@ func setPauseTask(id int) { pausetask = id } -func newTaskTime(proj int, tim string) { +func newTaskTime(tim string) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Start Project at ", tim)) + fmt.Println(frame(boldGreen("Starting Task at ", tim),true)) if opentask.id == 0 { timstr := "1791-09-30 19:07" //zone, _ := time.Now().Zone() @@ -191,26 +191,29 @@ func newTaskTime(proj int, tim string) { timstr = currdate + " " + getTime(tim) //timst = timstr+" "+zone } else { - fmt.Println(tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") + fmt.Println(nli,tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") + fmt.Println(frame(negR(),false)) return //os.Exit(0) } stmt, err := db.Prepare("INSERT INTO timetable(project, start, task, checkout) values(?, datetime(?,'utc'), ?, ?)") - fmt.Println(timstr) - task := getInterInput("Specify Task: ") + fmt.Println(nli+timstr) + task := getInterInput(sli+"Specify Task: ") checkErr(err) - if proj == 0 { - _, err = stmt.Exec(currproject.id, timstr, task, 0) - } else { - _, err = stmt.Exec(proj, timstr, task, 0) - } + //if proj == 0 { + _, err = stmt.Exec(currproject.id, timstr, task, 0) + //} else { + // _, err = stmt.Exec(proj, timstr, task, 0) + //} checkErr(err) - fmt.Println("...new task inserted into", currproject.name, ": ", task) + fmt.Println(nli+"...new task inserted into", currproject.name, ": ", task) + fmt.Println(frame(posR(),false)) getOpenTask() updateProject(currproject.id) } else { - fmt.Println(boldRed("Another Task is already Open")) + fmt.Println(nli+boldRed("Another Task is already Open")) + fmt.Println(frame("Close Task First",false)) showOpenTask() } @@ -220,34 +223,42 @@ func newTask(resume bool) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() task := "" + if resume { + fmt.Println(frame(boldGreen("Resuming Task"),true)) + }else{ + fmt.Println(frame(boldGreen("Starting Task Now"),true)) + } if opentask.id > 0 { - fmt.Println(boldRed("Another Task is already Open")) - showOpenTask() + fmt.Println(nli+boldRed("Another Task is already Open")) + //showOpenTask() + fmt.Println(frame(negR(),false)) return } if resume { if pausetask == 0 { - fmt.Println(boldRed("No Task was Paused")) + fmt.Println(nli+boldRed("No Task was Paused")) + fmt.Println(frame(negR(),false)) return } else { idx := []int{pausetask} tsks := getSelectedTasks(idx) fulltask := tsks[0] - fmt.Println(boldGreen("Resuming Task ", pausetask, " - ", fulltask.taskname)) + fmt.Println(nli+"Resuming Task ", pausetask, " - ", fulltask.taskname) //fmt.Println() task = fulltask.taskname } } else { - fmt.Println(boldGreen("Starting new Task")) - task = getInterInput("Specify Task: ") + //fmt.Println(boldGreen("Starting new Task")) + task = getInterInput(sli+"Specify Task: ") } stmt, err := db.Prepare("INSERT INTO timetable(project, task, checkout) values(?, ?, ?)") checkErr(err) _, err = stmt.Exec(currproject.id, task, 0) checkErr(err) if !resume { - fmt.Println("...New Task inserted into", currproject.name, ": ", task) + fmt.Println(nli+"...New Task inserted into", currproject.name, ": ", task) } + fmt.Println(frame(posR(),false)) getOpenTask() updateProject(currproject.id) } @@ -255,37 +266,39 @@ func newTask(resume bool) { func newBill(proj int) (int, string) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() //boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Creating New Bill")) //Show 5 recent bills showLastBills(5) - invno := getInterInput("Invoice Number: ") + fmt.Println(frame(boldGreen("Creating New Bill"),true)) + invno := getInterInput(sli+"Invoice Number: ") stmt, err := db.Prepare("INSERT INTO bills (identity, project, date) values(?, ?, datetime('now'))") checkErr(err) answ, err := stmt.Exec(invno, proj) checkErr(err) lid, _ := answ.LastInsertId() - fmt.Println("Bill", invno, "Created with ID", lid) + //fmt.Println(frame("Bill "+ invno+" Created with ID "+lid),false) + fmt.Println(nli+"Bill", invno, "Created with ID", lid) return int(lid), invno } func saveBill(in bill) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() tasks, times, hours, moneys := items2strings(in.items) - fmt.Println(boldGreen("Saving Bill"), in.id) + fmt.Println(nli+boldGreen("Saving Bill"), in.id) stmt, err := db.Prepare("UPDATE bills SET identity = ?, timerange = ?, tasks = ?, times = ?, hours = ?, moneys = ? WHERE id = ?") checkErr(err) _, err = stmt.Exec(in.identity, in.timerange, tasks, times, hours, moneys, in.id) checkErr(err) + fmt.Println(frame(posR(),false)) } func showLastBills(count int) { boldRed := color.New(color.FgRed, color.Bold).SprintFunc() boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() - cn := "all" - if count > 0 { - cn = fmt.Sprint(count) - } - fmt.Printf(boldGreen("Loading %s Bills\n"), cn) + //cn := "all" + //if count > 0 { + // cn = fmt.Sprint(count) + //} + //fmt.Printf(boldGreen("Loading %s Bills\n"), cn) rows, err := db.Query("SELECT * FROM timetable") if count == 0 { rows, err = db.Query("SELECT * FROM bills ORDER BY date ASC") @@ -301,9 +314,11 @@ func showLastBills(count int) { //fmt.Println("___Open Task________________") if count == 0 { - fmt.Print("___All Previous Bills_______\n") + fmt.Println(frame(boldGreen("All Bills"),true)) + //fmt.Print("___All Previous Bills_______\n") } else { - fmt.Printf("___Previous %v Bills________\n", count) + str := fmt.Sprintf("Previous %v Bills", count) + fmt.Println(frame(boldGreen(str),true)) } i := 0 for rows.Next() { @@ -313,7 +328,7 @@ func showLastBills(count int) { prn, _ := getProjectName(proj) hsum := sumFloatArray(string2FloatArray(hourstr, ";")) msum := sumFloatArray(string2FloatArray(moneystr, ";")) - fmt.Printf(" %v:%s - %s (%v) %.1f[h]: %.2f[€] - ", id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum) + fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[€] - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum) p := fmt.Sprintf("%v", paid) if p == "1791-09-30 19:07:00 +0000 UTC" { fmt.Print(boldRed("OPEN\n")) @@ -322,9 +337,10 @@ func showLastBills(count int) { } } if i == 0 { - fmt.Println(boldRed("\n NONE")) + fmt.Println(nli+"\n"+nli,boldRed(" NONE")) } - fmt.Println(" ") + fmt.Println(nli) + fmt.Println(frame("",false)) } func loadBills(in []int) (out []bill) { @@ -379,10 +395,14 @@ func items2strings(in []billitem) (tasks, times, hours, moneys string) { func closeTaskTime(tim string) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname)) + //fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname)) + fmt.Println(frame(boldGreen("Stoping Task"),true)) if opentask.id == 0 { - fmt.Println(boldRed("There is no Open Task")) + fmt.Println(nli+boldRed("There is no Open Task")) + fmt.Println(frame(negR(),false)) return + }else{ + fmt.Println(nli,"ID ",opentask.id, ":", opentask.taskname) } //timt,err := time.Parse("2006-01-02 15:04",tim) timst, timstr := "1791-09-30 19:07", "1791-09-30 19:07" @@ -394,7 +414,8 @@ func closeTaskTime(tim string) { timstr = time.Now().Local().Format("2006-01-02") + " " + getTime(tim) timst = timstr + " " + zone } else { - fmt.Println(tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") + fmt.Println(nli,tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") + fmt.Println(frame(negR(),false)) return //os.Exit(0) @@ -406,18 +427,21 @@ func closeTaskTime(tim string) { if timt.After(opentask.start) { //timstr := timt.UTC().Format("2006-01-02 15:04") com := "" - if isInterSure("Do You Want to enter a Comment?") { - com = getInterMultiInput("Comment:") + if isInterSure(sli+"Do You Want to enter a Comment?") { + com = getInterMultiInput(nli+"Comment:") } - fmt.Println("...Closing Task", opentask.id, "at", timst) + fmt.Println(nli,"...Closing Task", opentask.id, "at", timst) stmt, err := db.Prepare("UPDATE timetable SET stop = datetime(?,'utc'), comment = ? WHERE id = ?") checkErr(err) _, err = stmt.Exec(timstr, com, opentask.id) checkErr(err) opentask.id = 0 updateProject(opentask.projectid) + fmt.Println(frame(posR(),false)) } else { - fmt.Println(boldRed("Cannot Stop before the Beginning!")) + fmt.Println(nli,boldRed("Cannot Stop before the Beginning!")) + fmt.Println(frame(negR(),false)) + return } //fmt.Println(tim,timt) } @@ -426,19 +450,28 @@ func closeTask(loud bool) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() if loud { - fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname)) - } - if opentask.id == 0 { - fmt.Println(boldRed("There is no Open Task")) - return + fmt.Println(frame(boldGreen("Stoping Task"),true)) + if opentask.id == 0 { + fmt.Println(nli,boldRed("There is no Open Task")) + fmt.Println(frame(negR(),false)) + return + }else{ + fmt.Println(nli,"ID ",opentask.id, ":", opentask.taskname) + } + //fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname)) + }else{ + if opentask.id == 0 { + fmt.Println(boldRed("There is no Open Task")) + } } if time.Now().After(opentask.start.Local()) { com := "" if loud { - if isInterSure("Do You Want to enter a Comment?") { - com = getInterMultiInput("Comment:") + if isInterSure(sli+"Do You Want to enter a Comment?") { + com = getInterMultiInput(nli+"Comment:") } - fmt.Println("...Closing Task", opentask.id) + fmt.Println(nli+"...Closing Task", opentask.id) + fmt.Println(frame(posR(),false)) } stmt, err := db.Prepare("UPDATE timetable SET stop = datetime('now'), comment = ? WHERE id = ?") checkErr(err) @@ -447,7 +480,12 @@ func closeTask(loud bool) { opentask.id = 0 updateProject(opentask.projectid) } else { - fmt.Println(boldRed("Cannot Stop before the Beginning!")) + if loud { + fmt.Println(nli,boldRed("Cannot Stop before the Beginning!")) + fmt.Println(frame(negR(),false)) + }else{ + fmt.Println(boldRed("Cannot Stop before the Begining!")) + } } } @@ -455,9 +493,10 @@ func checkBill(bid int) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() var custid int - + fmt.Println(frame(boldGreen("Checking Bill"),true)) if !isBill(bid) { - fmt.Println(bid, boldRed("is not a known bill ID")) + fmt.Println(nli,bid, boldRed("is not a known bill ID")) + fmt.Println(frame(negR(),false)) return } @@ -465,16 +504,18 @@ func checkBill(bid int) { bill := loadBills(bar) if len(bill) < 1 { + fmt.Println(nli, boldRed("The Bill cannot be loaded.")) + fmt.Println(frame(negR(),false)) return } else { pr, cu := getProjectName(bill[0].project) custid = getCustomerId(bill[0].project) //fmt.Println(bill[0]) - fmt.Println(boldGreen("Checking Bill ", bid, " as Paid:\n", bill[0].identity), "\n For", cu, " :", pr) + fmt.Println(nli+"Marking Bill ", bid, " as Paid:\n"+nli, bill[0].identity, "\n"+nli+" For", cu, " :", pr) _, _, ho, ma := items2strings(bill[0].items) hsum := sumFloatArray(string2FloatArray(ho, ";")) msum := sumFloatArray(string2FloatArray(ma, ";")) - fmt.Printf(" Date: %s Hours: %.1f[h] Sum: %.2f[€]\n", bill[0].date.Local().Format("2006-01-02"), hsum, msum) + fmt.Printf(nli+" Date: %s Hours: %.1f[h] Sum: %.2f[€]\n"+nli, bill[0].date.Local().Format("2006-01-02"), hsum, msum) //fmt.Println(ta) } @@ -482,7 +523,7 @@ func checkBill(bid int) { //zone, _ := time.Now().Zone() timstr := "1791-09-30 19:07" - timin := getInterInput("Specify Date (YYYY-MM-DD): ") + timin := getInterInput(sli+"Specify Date (YYYY-MM-DD): ") if isDateTime(timin) { timstr = getDateTime(timin) @@ -490,10 +531,11 @@ func checkBill(bid int) { //currdate := time.Now().Local().Format("2006-01-02") timstr = getDate(timin) + " 12:00" } else { - fmt.Println(timin, boldRed("is Not a Valid Datestring!"), "use: 'YYYY-MM-DD'") + fmt.Println(nli+timin, boldRed("is Not a Valid Datestring!"), "use: 'YYYY-MM-DD'") + fmt.Println(frame(negR(),false)) return } - fmt.Println(boldGreen(timstr)) + fmt.Println(nli+boldGreen(timstr)) stmt, err := db.Prepare("UPDATE bills SET paid = datetime(?,'utc') WHERE id = ?") checkErr(err) _, err = stmt.Exec(timstr, bid) @@ -502,6 +544,7 @@ func checkBill(bid int) { checkErr(err) _, err = stmt.Exec(timstr, custid) checkErr(err) + fmt.Println(frame(posR(),false)) } func checkTasks(in []int, billid int) { @@ -1213,7 +1256,7 @@ func deleteTask(id int) { func editCustomer(id int) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Editing Customer ", id)) + fmt.Println(frame(boldGreen("Editing Customer ", id),true)) var comp, name, addr string var satz float64 rows, err := db.Query("SELECT company, name, address, satz FROM customers WHERE id = $1", id) @@ -1222,7 +1265,7 @@ func editCustomer(id int) { err = rows.Scan(&comp, &name, &addr, &satz) checkErr(err) } else { - fmt.Println(boldRed("There Is No Customer"), id) + fmt.Println(nli+boldRed("There Is No Customer"), id) return //os.Exit(0) } @@ -1234,25 +1277,25 @@ func editCustomer(id int) { if in!=""{ comp=in }*/ - comp = getNewInterInput("New Company Name: ", comp) + comp = getNewInterInput("New Company Name: ", comp, nli) /*fmt.Println("Old Name:",name) in = getInterInput("Enter New:") if in!=""{ name=in }*/ - name = getNewInterInput("New Customer Name: ", name) + name = getNewInterInput("New Customer Name: ", name, nli) /*fmt.Println("Old Adress:",addr) in = getInterInput("Enter New:") if in!=""{ addr=in }*/ - addr = getNewInterInput("New Adress: ", addr) + addr = getNewInterInput("New Adress: ", addr, nli) //fmt.Println("Old Hourly Rate:",satz) for { - satzstr := getNewInterInput("New Hourly Rate: ", fmt.Sprintf("%.2f", satz)) + satzstr := getNewInterInput("New Hourly Rate: ", fmt.Sprintf("%.2f", satz), nli) satz, err = strconv.ParseFloat(satzstr, 64) if err != nil { - fmt.Println(satzstr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X") + fmt.Println(nli,satzstr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X") //os.Exit(0) } else { break @@ -1270,13 +1313,14 @@ func editCustomer(id int) { checkErr(err) _, err = stmt.Exec(comp, name, addr, satz, id) checkErr(err) - fmt.Println("...Customer", id, "Updated") + fmt.Println(nli,"...Customer", id, "Updated") + fmt.Println(frame("",false)) } func editTask(id int) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Edit Task ", id)) + fmt.Println(frame(boldGreen("Edit Task ", id),true)) var chk, prj int var start, stop time.Time var task, startstr, stopstr, comm string @@ -1286,7 +1330,7 @@ func editTask(id int) { err = rows.Scan(&prj, &start, &stop, &task, &comm, &chk) checkErr(err) } else { - fmt.Println(boldRed("There Is No Task"), id) + fmt.Println(nli,boldRed("There Is No Task"), id) return //os.Exit(0) } @@ -1297,14 +1341,14 @@ func editTask(id int) { if in!=""{ task=in }*/ - task = getNewInterInput("New Task Name: ", task) + task = getNewInterInput("New Task Name: ", task, nli) startstr = start.Local().Format("2006-01-02 15:04") stopstr = stop.Local().Format("2006-01-02 15:04") for { - newstartstr := getNewInterInput("New Start time: ", startstr) + newstartstr := getNewInterInput("New Start time: ", startstr, nli) if !isDateTime(newstartstr) { - fmt.Println(newstartstr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") + fmt.Println(nli, newstartstr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") } else { startstr = newstartstr break @@ -1312,41 +1356,42 @@ func editTask(id int) { } //fmt.Println("Old End:",stopstr) for { - newend := getNewInterInput("New Stop time: ", stopstr) + newend := getNewInterInput("New Stop time: ", stopstr, nli) if isDateTime(newend) { stopstr = newend break } else { - fmt.Println(newend, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") + fmt.Println(nli, newend, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'") } } //fmt.Println("Old Project:",prj) for { - newprj := getNewInterInput("New Project id: ", fmt.Sprint(prj)) + newprj := getNewInterInput("New Project id: ", fmt.Sprint(prj), nli) prj, err = strconv.Atoi(newprj) if err != nil { - fmt.Println(newprj, boldRed("is Not a Valid id."), "Try an Integer instead") + fmt.Println(nli,newprj, boldRed("is Not a Valid id."), "Try an Integer instead") } if !isProject(prj) { - fmt.Println(boldRed("There is no project"), prj) + fmt.Println(nli, boldRed("There is no project"), prj) } else { break } } - comm = getNewInterMultiInput("New Comment: ", comm) + comm = getNewInterMultiInput("New Comment: ", comm, nli) stmt, err := db.Prepare("UPDATE timetable SET task = ?, comment = ?, start = datetime(?,'utc'), stop = datetime(?,'utc'), project = ? WHERE id = ?") checkErr(err) _, err = stmt.Exec(task, comm, startstr, stopstr, prj, id) checkErr(err) updateProject(prj) - fmt.Println("...Task", id, "Updated") + fmt.Println(nli, "...Task", id, "Updated") + fmt.Println(frame("",false)) } func editProject(id int) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() - fmt.Println(boldGreen("Edit Project ", id)) + fmt.Println(frame(boldGreen("Edit Project ", id),true)) var fin, cust int var first time.Time var name, nfirst, comm string @@ -1356,13 +1401,13 @@ func editProject(id int) { err = rows.Scan(&name, &comm, &first, &fin, &cust) checkErr(err) - name = getNewInterInput("New Name: ", name) + name = getNewInterInput("New Name: ", name, nli) nfirst = first.Local().Format("2006-01-02 15:04") // Get New PRoject Begin Date for { - newfirststr := getNewInterInput("New Begin time: ", nfirst) + newfirststr := getNewInterInput("New Begin time: ", nfirst, nli) if !isDateTime(newfirststr) { - fmt.Println(newfirststr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") + fmt.Println(nli,newfirststr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") } else { nfirst = newfirststr break @@ -1370,21 +1415,22 @@ func editProject(id int) { } // Get New Customer for { - newcu := getNewInterInput("New Customer id: ", fmt.Sprint(cust)) + newcu := getNewInterInput("New Customer id: ", fmt.Sprint(cust), nli) icust, err := strconv.Atoi(newcu) if err != nil { - fmt.Println(newcu, boldRed("is Not a Valid id."), "Try an Integer instead") + fmt.Println(nli,newcu, boldRed("is Not a Valid id."), "Try an Integer instead") } else if !isCustomer(icust) { - fmt.Println(boldRed("There is no Customer"), icust) + fmt.Println(nli,boldRed("There is no Customer"), icust) } else { cust = icust break } } // Get Comment - comm = getNewInterMultiInput("New Comment: ", comm) + comm = getNewInterMultiInput("New Comment: ", comm, nli) } else { - fmt.Println(boldRed("There Is No Project"), id) + fmt.Println(nli,boldRed("There Is No Project"), id) + fmt.Println(frame(negR(),false)) return //os.Exit(0) } @@ -1394,7 +1440,8 @@ func editProject(id int) { _, err = stmt.Exec(name, comm, nfirst, cust, id) checkErr(err) updateProject(id) - fmt.Println("...Project", id, "Updated") + fmt.Println(nli,"...Project", id, "Updated") + fmt.Println(frame("",false)) } func isBill(id int) bool { @@ -1446,32 +1493,55 @@ func isCustomer(id int) bool { func getDateTime(in string) string { r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`) + //r := regexp.MustCompile(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1]) ([01]?[0-9]|2[0-3]):[0-5][0-9]`) return r.FindString(in) } func getDate(in string) string { - r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})`) + //r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})`) + r := regexp.MustCompile(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1])`) return r.FindString(in) } func getTime(in string) string { - r := regexp.MustCompile(`(\d{2}):(\d{2})`) + //r := regexp.MustCompile(`(\d{2}):(\d{2})`) + r := regexp.MustCompile(`([01]?[0-9]|2[0-3]):[0-5][0-9]`) return r.FindString(in) } func isDateTime(in string) bool { - match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`, in) - return match + //match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`, in) + //match, _ := regexp.MatchString(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1]) ([01]?[0-9]|2[0-3]):[0-5][0-9]`, in) + const form = "2006-01-02 15:04" + _,err := time.Parse(form,in) + if err == nil { + return true + } + return false } func isDate(in string) bool { - match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2})`, in) - return match + //match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2})`, in) + //match, _ := regexp.MatchString(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1])`, in) + //return match + const form = "2006-01-02" + _,err := time.Parse(form,in) + if err == nil { + return true + } + return false } func isTime(in string) bool { - match, _ := regexp.MatchString(`(\d{2}):(\d{2})`, in) - return match + //match, _ := regexp.MatchString(`(\d{2}):(\d{2})`, in) + //match, _ := regexp.MatchString(`([01]?[0-9]|2[0-3]):[0-5][0-9]`, in) + //return match + const form = "15:04" + _,err := time.Parse(form,in) + if err == nil { + return true + } + return false } /* |
