You've already forked pocketbase
							
							
				mirror of
				https://github.com/pocketbase/pocketbase.git
				synced 2025-10-31 00:27:41 +02:00 
			
		
		
		
	minor types.DateTime optimizations to minimize time.Time value copies
This commit is contained in:
		| @@ -45,10 +45,11 @@ func (d DateTime) IsZero() bool { | |||||||
| // | // | ||||||
| // The zero value is serialized to an empty string. | // The zero value is serialized to an empty string. | ||||||
| func (d DateTime) String() string { | func (d DateTime) String() string { | ||||||
| 	if d.IsZero() { | 	t := d.Time() | ||||||
|  | 	if t.IsZero() { | ||||||
| 		return "" | 		return "" | ||||||
| 	} | 	} | ||||||
| 	return d.Time().UTC().Format(DefaultDateLayout) | 	return t.UTC().Format(DefaultDateLayout) | ||||||
| } | } | ||||||
|  |  | ||||||
| // MarshalJSON implements the [json.Marshaler] interface. | // MarshalJSON implements the [json.Marshaler] interface. | ||||||
| @@ -74,12 +75,10 @@ func (d DateTime) Value() (driver.Value, error) { | |||||||
| // into the current DateTime instance. | // into the current DateTime instance. | ||||||
| func (d *DateTime) Scan(value any) error { | func (d *DateTime) Scan(value any) error { | ||||||
| 	switch v := value.(type) { | 	switch v := value.(type) { | ||||||
| 	case DateTime: |  | ||||||
| 		d.t = v.Time() |  | ||||||
| 	case time.Time: | 	case time.Time: | ||||||
| 		d.t = v | 		d.t = v | ||||||
| 	case int, int64, int32, uint, uint64, uint32: | 	case DateTime: | ||||||
| 		d.t = cast.ToTime(v) | 		d.t = v.Time() | ||||||
| 	case string: | 	case string: | ||||||
| 		if v == "" { | 		if v == "" { | ||||||
| 			d.t = time.Time{} | 			d.t = time.Time{} | ||||||
| @@ -91,6 +90,8 @@ func (d *DateTime) Scan(value any) error { | |||||||
| 			} | 			} | ||||||
| 			d.t = t | 			d.t = t | ||||||
| 		} | 		} | ||||||
|  | 	case int, int64, int32, uint, uint64, uint32: | ||||||
|  | 		d.t = cast.ToTime(v) | ||||||
| 	default: | 	default: | ||||||
| 		str := cast.ToString(v) | 		str := cast.ToString(v) | ||||||
| 		if str == "" { | 		if str == "" { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user