Faas semi worfking
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -53,29 +54,58 @@ func (d *Duration) Scan(value interface{}) error {
|
||||
case []uint8:
|
||||
// Handle PostgreSQL interval format (e.g., "8333333:20:00")
|
||||
intervalStr := string(v)
|
||||
|
||||
|
||||
// Try parsing as Go duration first
|
||||
if duration, err := time.ParseDuration(intervalStr); err == nil {
|
||||
d.Duration = duration
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// If that fails, try parsing PostgreSQL interval format
|
||||
// Convert PostgreSQL interval "HH:MM:SS" to Go duration
|
||||
if strings.Contains(intervalStr, ":") {
|
||||
parts := strings.Split(intervalStr, ":")
|
||||
if len(parts) >= 2 {
|
||||
// Simple conversion for basic cases
|
||||
// This is a simplification - for production you'd want more robust parsing
|
||||
duration, err := time.ParseDuration("30s") // Default to 30s for now
|
||||
if err != nil {
|
||||
return err
|
||||
// Parse hours, minutes, seconds format
|
||||
var hours, minutes, seconds int64
|
||||
var err error
|
||||
|
||||
// Handle the case where we might have days as well (e.g., "8333333:20:00")
|
||||
// or just hours:minutes:seconds
|
||||
switch len(parts) {
|
||||
case 2: // MM:SS
|
||||
minutes, err = parseNumber(parts[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse minutes from interval: %s", intervalStr)
|
||||
}
|
||||
seconds, err = parseNumber(parts[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse seconds from interval: %s", intervalStr)
|
||||
}
|
||||
case 3: // HH:MM:SS
|
||||
hours, err = parseNumber(parts[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse hours from interval: %s", intervalStr)
|
||||
}
|
||||
minutes, err = parseNumber(parts[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse minutes from interval: %s", intervalStr)
|
||||
}
|
||||
seconds, err = parseNumber(parts[2])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse seconds from interval: %s", intervalStr)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported interval format: %s", intervalStr)
|
||||
}
|
||||
d.Duration = duration
|
||||
|
||||
// Convert to duration
|
||||
totalSeconds := hours*3600 + minutes*60 + seconds
|
||||
d.Duration = time.Duration(totalSeconds) * time.Second
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fmt.Errorf("cannot parse PostgreSQL interval format: %s", intervalStr)
|
||||
default:
|
||||
return fmt.Errorf("cannot scan %T into Duration", value)
|
||||
@ -90,7 +120,7 @@ func ParseDuration(s string) (Duration, error) {
|
||||
}
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
|
||||
duration, err := time.ParseDuration(s)
|
||||
if err != nil {
|
||||
return Duration{}, fmt.Errorf("failed to parse duration '%s': %v", s, err)
|
||||
@ -113,4 +143,10 @@ func (d Duration) Minutes() float64 {
|
||||
|
||||
func (d Duration) Hours() float64 {
|
||||
return d.Duration.Hours()
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to parse number from string, handling potential whitespace
|
||||
func parseNumber(s string) (int64, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
return strconv.ParseInt(s, 10, 64)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user