I'm making a cron job for the booking charge automatic. The admin set the automatic charge after 2 hour of booking completion then I Get all the booking completed before 2 hours from the current time and charge them automatic. But the problem arise in the end of the day is that current_date= 10/10/2018 current_time= 1:00AM
and automatic_charge_hours= 2
(hours) means it will get all the bookings which are completed 2 hours before the current_time and current_date. In 24hour format it will get all the bookings of the 23 hours(11:00PM of date 09/10/2018) of the previous date . But in my condition it will turn it into zero below is my condition:-
package main
import (
"fmt"
"time"
"strings"
)
func main() {
timeZone, _ := time.LoadLocation("America/New_York")
currDate := time.Now().In(timeZone).Format("2006-01-02 00:00:00 -0000")
onlyDate := strings.Split(currDate, " ")
hours, _ := 1, 0
if hours-int(2) < 0 {
hours = 0
} else {
hours = hours - int(2)
}
fmt.Println(hours, onlyDate[0])
}
playground link https://play.golang.org/p/w7LIoTp9xN0
How will I change it. Any suggestions please.