fixed dateLayout, fixed variable order in call to ParseInLocation, code formatting

This commit is contained in:
Alex H
2023-04-17 21:10:31 -04:00
parent 785ff9a089
commit e9812e7e27

View File

@@ -1,6 +1,7 @@
package service package service
import ( import (
"fmt"
"hammond/db" "hammond/db"
"hammond/models" "hammond/models"
"time" "time"
@@ -9,11 +10,12 @@ import (
func GenericParseRefuelings(content []models.ImportFillup, user *db.User, vehicle *db.Vehicle, timezone string) ([]db.Fillup, []string) { func GenericParseRefuelings(content []models.ImportFillup, user *db.User, vehicle *db.Vehicle, timezone string) ([]db.Fillup, []string) {
var errors []string var errors []string
var fillups []db.Fillup var fillups []db.Fillup
dateLayout := "2023-04-16T04:41:25.682Z" dateLayout := "2006-01-02T15:04:05.000Z"
loc, _ := time.LoadLocation(timezone) loc, _ := time.LoadLocation(timezone)
for _, record := range content { for _, record := range content {
date, err := time.ParseInLocation(record.Date, dateLayout, loc) date, err := time.ParseInLocation(dateLayout, record.Date, loc)
if err != nil { if err != nil {
fmt.Println(err)
date = time.Date(2000, time.December, 0, 0, 0, 0, 0, loc) date = time.Date(2000, time.December, 0, 0, 0, 0, 0, loc)
} }