diff --git a/src/handlers/annotations.go b/src/handlers/annotations.go index b1570ce..87b8838 100644 --- a/src/handlers/annotations.go +++ b/src/handlers/annotations.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "sheetless-server/database" "sheetless-server/models" @@ -17,6 +18,27 @@ type AnnotationRequest struct { Annotations string `json:"annotations" binding:"required"` } +// parseFlexibleTime parses time strings in various ISO8601/RFC3339 formats +func parseFlexibleTime(s string) (time.Time, error) { + // Try multiple formats that Dart/Flutter might send + formats := []string{ + time.RFC3339, + time.RFC3339Nano, + "2006-01-02T15:04:05.999999999", // Dart ISO8601 without timezone + "2006-01-02T15:04:05.999999", // Dart ISO8601 with microseconds + "2006-01-02T15:04:05.999", // Dart ISO8601 with milliseconds + "2006-01-02T15:04:05", // Dart ISO8601 without fractional seconds + } + + for _, format := range formats { + if t, err := time.Parse(format, s); err == nil { + return t, nil + } + } + + return time.Time{}, fmt.Errorf("unable to parse time: %s", s) +} + // GetAnnotations returns all annotations for a sheet // GET /api/sheets/:uuid/annotations func GetAnnotations(c *gin.Context) { @@ -65,10 +87,10 @@ func UpdateAnnotation(c *gin.Context) { return } - // Parse lastModified timestamp - lastModified, err := time.Parse(time.RFC3339, req.LastModified) + // Parse lastModified timestamp (flexible format to support Dart/Flutter) + lastModified, err := parseFlexibleTime(req.LastModified) if err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid lastModified format, expected RFC3339"}) + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid lastModified format: " + err.Error()}) return } diff --git a/src/handlers/changes.go b/src/handlers/changes.go index f62ccef..430015c 100644 --- a/src/handlers/changes.go +++ b/src/handlers/changes.go @@ -4,7 +4,6 @@ import ( "net/http" "sheetless-server/database" "sheetless-server/models" - "time" "github.com/gin-gonic/gin" "github.com/google/uuid" @@ -59,8 +58,8 @@ func SyncChanges(c *gin.Context) { continue // Skip invalid UUIDs } - // Parse createdAt timestamp - createdAt, err := time.Parse(time.RFC3339, change.CreatedAt) + // Parse createdAt timestamp (flexible format to support Dart/Flutter) + createdAt, err := parseFlexibleTime(change.CreatedAt) if err != nil { continue // Skip invalid timestamps }