feat(app) lab 3 implemented

This commit is contained in:
imadev
2026-10-30 18:11:30 +03:00
parent f731f9b460
commit 48a616e910
57 changed files with 1390 additions and 303 deletions
+4 -13
View File
@@ -5,19 +5,15 @@ import (
"time"
)
// storageTimePrecision is the maximum precision shared by PostgreSQL
// timestamptz columns and the JSON representation. PostgreSQL stores
// microseconds, so keeping the same boundary in Go prevents a create response
// from showing more precision than a later read can reproduce.
// PostgreSQL stores microseconds, so keeping the same boundary in Go
// prevents a create response from showing more precision
// than a later read can reproduce.
const storageTimePrecision = time.Microsecond
type RFCFormTime time.Time
func (t RFCFormTime) MarshalJSON() ([]byte, error) {
// RFC 3339 permits an optional fractional second. Use all six digits that
// PostgreSQL can store, and omit the fraction only for an exact second.
// A fixed six-digit fraction is also accepted by strict consumers that only
// understand 3- or 6-digit fractions (for example Python 3.9's parser).
// RFC 3339 permits an optional fractional second.
utc := time.Time(t).UTC().Truncate(storageTimePrecision)
layout := "2006-01-02T15:04:05Z"
if utc.Nanosecond() != 0 {
@@ -27,10 +23,5 @@ func (t RFCFormTime) MarshalJSON() ([]byte, error) {
}
func NowUTC() RFCFormTime {
// AGENT: The API used to truncate timestamps to whole seconds to keep
// keyset ordering consistent with JSON. RFC 3339 supports fractional seconds
// and PostgreSQL has microsecond precision, so use that precision end to end:
// timestamps remain ordered after serialization without discarding sub-second
// information.
return RFCFormTime(time.Now().UTC().Truncate(storageTimePrecision))
}