Files
mtusi2026lab5/app/internal/api/http/dto/timestamp.go
T

21 lines
733 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dto
import "time"
const timestampLayout = "2006-01-02T15:04:05.000000Z"
// Timestamp сериализуется в UTC всегда с 6 цифрами дробной части. Стандартный формат
// time.Time отбрасывает нули в конце (…17.95188Z): это корректный RFC 3339, но такое значение
// не разбирает datetime.fromisoformat в Python 3.9–3.10, на которых идут публичные тесты.
type Timestamp struct {
time.Time
}
func NewTimestamp(t time.Time) Timestamp {
return Timestamp{Time: t}
}
func (t Timestamp) MarshalJSON() ([]byte, error) {
return []byte(`"` + t.UTC().Format(timestampLayout) + `"`), nil
}