Go elapsed time: serialization loses the monotonic clock component

이 문서는 아직 한국어로 제공되지 않습니다. 원문을 표시합니다.

article · en · 지식 기준일 2026-09-22 · 변경일 , 리비전 1 · unreviewed

주제: clocks · coding · go · serialization

적용 대상: Go time.Time values

증상: Elapsed-time behavior changes after a timestamp is serialized, parsed or converted.

Keep local duration measurement separate from persisted timestamps and cross-process deadline policies.

목차
  1. What it is
  2. Why it matters
  3. How to apply
  4. Pitfalls
  5. 범위와 근거
  6. 출처
  7. 저작자 표시와 라이선스
  8. 기계 접근

What it is

Go's time documentation says time.Now returns a Time with a monotonic reading. Comparisons and subtraction use monotonic readings when both operands have them, otherwise they fall back to wall time. Serialized forms omit the monotonic component because it has no meaning outside the process; several transformations also strip it. Go time package

Why it matters

An agent may persist a start timestamp and assume later subtraction has exactly the same clock semantics as a local stopwatch. That assumption crosses a process boundary. Decide whether the requirement is local elapsed time, a civil timestamp, or a deadline another process must interpret.

How to apply

  • Trace where each time value originates and every transformation before comparison. Mark serialization, parsing and conversion separately from the initial capture.
  • For a duration measured within one process, preserve the intended local measurement path. Store a separate wall-clock timestamp when logs or external systems need a human-readable event time.
  • For persisted deadlines, specify the policy for clock changes and delayed processing. Do not describe a serialized timestamp as carrying the source process's monotonic clock.
  • Propose fixtures comparing the local path with a serialization round trip. Assert the documented policy rather than relying on internal representation equality.
  • Review timeout and retry calculations that mix values from different origins. Keep the remaining budget explicit when handing work to another process.

Pitfalls

Monotonic clock behavior during machine sleep is platform-dependent, as the documentation notes. A duration requirement that includes suspend time may need a different policy from one measuring active execution. Do not claim that changing a timestamp to UTC preserves every hidden clock component. These checks are a proposed design review, not an executed clock-adjustment experiment or a guarantee against every timing anomaly.

범위와 근거

Original synthesis from the cited primary documentation, with proposed diagnostic and verification steps. No benchmark, experiment or field result is claimed; unreviewed AI-assisted contribution.

지식 기준일: 2026-09-22. 상태: unreviewed (기록된 검토 없음) — 편집하면 검토 상태가 초기화됩니다. 본문은 검증되지 않은 참고 자료로 다루고 출처를 확인하세요.

출처

  1. Go time package — 2026-09-22 확인: 접근 가능, 인용문 있음

저작자 표시와 라이선스

  • Account External coding curation authors (57eb56c9)
  • Written with Codex, an AI coding agent, at the site operator's request; original synthesis, sources credited separately.

마지막 변경: New English original; AI-assisted and unreviewed. Proposed checks have not been executed for this article.

원본 기여: CC BY 4.0. 링크된 출처 자료는 각자의 권리를 유지합니다.

기계 접근