Fix up expiry

This commit is contained in:
Eliot Whalan 2016-06-25 08:49:34 +10:00
parent d327895d81
commit 576b83492a
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
1 changed files with 8 additions and 11 deletions

19
main.go
View File

@ -111,31 +111,31 @@ func save(raw string, lang string, title string, expiry string) []string {
switch expiry { switch expiry {
case "5 minutes": case "5 minutes":
expiryTime = now.Add(time.Minute * 5).Format(time.RFC3339) expiryTime = now.Add(time.Minute * 5).Format("2006-01-02 15:04:05")
break break
case "1 hour": case "1 hour":
expiryTime = now.Add(time.Hour + 1).Format(time.RFC3339) expiryTime = now.Add(time.Hour + 1).Format("2006-01-02 15:04:05")
break break
case "1 day": case "1 day":
expiryTime = now.Add(time.Hour * 24 * 1).Format(time.RFC3339) expiryTime = now.Add(time.Hour * 24 * 1).Format("2006-01-02 15:04:05")
break break
case "1 week": case "1 week":
expiryTime = now.Add(time.Hour * 24 * 7).Format(time.RFC3339) expiryTime = now.Add(time.Hour * 24 * 7).Format("2006-01-02 15:04:05")
break break
case "1 month": case "1 month":
expiryTime = now.Add(time.Hour * 24 * 30).Format(time.RFC3339) expiryTime = now.Add(time.Hour * 24 * 30).Format("2006-01-02 15:04:05")
break break
case "1 year": case "1 year":
expiryTime = now.Add(time.Hour * 24 * 365).Format(time.RFC3339) expiryTime = now.Add(time.Hour * 24 * 365).Format("2006-01-02 15:04:05")
break break
default: default:
expiryTime = now.Format(time.RFC3339) expiryTime = now.Format("2006-01-02 15:04:05")
break break
} }
@ -255,10 +255,7 @@ func getPaste(paste string, lang string) (string, string) {
var expiry string var expiry string
err = db.QueryRow("select title, data, expiry from pastebin where id=?", param1).Scan(&title, &s, &expiry) err = db.QueryRow("select title, data, expiry from pastebin where id=?", param1).Scan(&title, &s, &expiry)
check(err) check(err)
fmt.Println(expiry) if time.Now().Format("2006-01-02 15:04:05") > expiry {
fmt.Println(time.Now().Format(time.RFC3339))
fmt.Println(expiry > time.Now().Format(time.RFC3339))
if expiry > time.Now().Format(time.RFC3339) {
stmt, err := db.Prepare("delete from pastebin where id=?") stmt, err := db.Prepare("delete from pastebin where id=?")
check(err) check(err)
_, err = stmt.Exec(param1) _, err = stmt.Exec(param1)