better date formatting

This commit is contained in:
Ruidy 2024-06-29 09:28:51 +02:00
parent 6bff5ccc18
commit ee3674e12f
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 7 additions and 3 deletions

View file

@ -51,7 +51,10 @@ func (bs Service) Create(From time.Time, To time.Time, Name string, PhoneNumber
PlatformFees: PlatformFees,
ExternalId: externalId,
}
_ = bs.db.Create(b)
err := bs.db.Create(b)
if err != nil {
log.Println(err)
}
return b
}
@ -248,7 +251,6 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) {
item := extractString(`Maison 1 Chambre \((T2|T3) -`, content)
externalId := extractString(`Numéro de réservation : \n\s+(\d+)`, content)
standardRate := extractFloat(`Standard Rate\n\s+€ (\d+)`, content)
taxQty := (totalAmount - standardRate*float64(stayLength)) / 1.5
b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, externalId)
@ -313,10 +315,11 @@ func formatDate(date string) *time.Time {
"sep": "09", "oct": "10", "nov": "11", "déc": "12",
}
parts := strings.Split(date, " ")
dateString := fmt.Sprintf("%s-%s-%s", parts[2], months[parts[1]], parts[0])
dateString := fmt.Sprintf("%s-%02s-%02s", parts[2], months[parts[1]], parts[0])
t, err := time.Parse(time.DateOnly, dateString)
if err != nil {
log.Println(err)
return nil
}
return &t

View file

@ -12,6 +12,7 @@ import (
func handleSync(bs *booking.Service) echo.HandlerFunc {
return func(c echo.Context) error {
log.Info("received booking sync request from booking")
x := c.Request().Body
body, err := io.ReadAll(x)
if err != nil {