Calendar / Specifications / QP-EXAMPLE-001
METHOD PAPER · QP-EXAMPLE-001 · VERSION 1.0.0

Reference Method for Determining a Civil Day Boundary

Phương pháp tham chiếu xác định ranh giới ngày dân sự
Quizzman Research & Engineering Team (Quizzman Research) [ORCID] · 1 October 2026 · Version 1.0.0 · ● Stable

Abstract

Background / Problem: In lunisolar calendar calculations and astronomical computing within the Quizzman ecosystem, determining the local midnight civil day boundary is an indispensable prerequisite for demarcating the first day of the lunar month (astronomical new moon) and solar term transitions. Inconsistencies between reference timezones and time scales can lead to whole-day calendar discrepancies.
Method: This paper formalizes a normative mathematical reference method for determining civil day transitions based on local clock time bound to a reference meridian, adhering to ISO 8601 principles and Meeus's dynamical time reduction algorithms.
Results: The proposed algorithm was benchmarked against the CAL-BENCH-001 dataset (version 1.2.0) across 139 edge test cases, achieving exact correspondence with empirical ground truth.
Conclusion: This method is approved as the authoritative source of truth for the @quizzman/qm-calendar package and associated calendar computation services in the Quizzman ecosystem.


1 Scope

This document specifies the mathematical method and normative algorithmic rules to:

  1. Determine the start and end instants of a civil day in a local time scale.
  2. Convert Unix timestamps (in milliseconds UTC) into discrete integer civil day indices.
  3. Establish a standard interface between astronomical ephemeris computing layers and civil calendar representation layers.

The scope applies to all computation engines in the Quizzman architecture, specifically modules synchronizing Vietnamese lunisolar calendars (standard timezone UTC+07:00) and international calendar standards.

2 Normative references

The following referenced documents are indispensable for the application of this method:

  • ISO 8601-1:2019 [1], Date and time — Representations for information interchange — Part 1: Basic rules.
  • Jean Meeus (1998) [2], Astronomical Algorithms, 2nd Edition, Willmann-Bell.
  • E. M. Standish (1998) [3], JPL Planetary and Lunar Ephemerides, DE405/LE405.
  • Quizzman Calendar Engine Specification [4], Quizzman Lunisolar Engine Core Specification.
  • Hồ Ngọc Đức (2000) [5], Lunisolar Calendar Calculations and Vietnamese Standard Meridian.

3 Terms and definitions

For the purposes of this document, the following terms and definitions apply:

3.1 civil day

Continuous duration spanning exactly 86,400 standard solar seconds (or equivalent duration after accounting for leap seconds, if any), starting at midnight (00:00:00) and terminating at 24:00:00 of the same day in local civil time.

3.2 midnight transition

Instantaneous transition boundary between two consecutive civil days, corresponding to 00:00:00.00000:00:00.000 local time.

3.3 governing timezone offset

Standard time displacement in minutes or seconds between the legal time of a jurisdiction and Coordinated Universal Time (UTC).

4 Symbols and abbreviated terms

  • TutcT_{utc}: Timestamp in milliseconds since the Unix Epoch (1970-01-01T00:00:00Z).
  • ZZ: Reference timezone offset in minutes (e.g. +420+420 for UTC+07:00).
  • TlocalT_{local}: Local timestamp in milliseconds after applying offset ZZ.
  • DcivilD_{civil}: Continuous integer civil day index (Julian Day Number or Days since Epoch).
  • ΔT\Delta T: Difference between Terrestrial Time (TT) and Universal Time (UT1).

5 Conventions and assumptions

  1. Master Time Reference: All raw input timestamps at the distributed core layer of Quizzman SHALL be represented in UTC.
  2. Standard Reference Meridian: The traditional Vietnamese lunisolar calendar observes the 105∘E105^\circ\text{E} meridian, corresponding to legal timezone offset Z=+420Z = +420 minutes (see [5]).
  3. Rounding Convention: When converting continuous time to discrete calendar days, the floor operation (floor) SHALL be applied to the local time axis.

6 Background

Lunisolar calendars rely on two fundamental celestial phenomena: the astronomical new moon to demarcate the first day of the lunar month, and solar equinoxes/solstices to establish the 24 solar terms [2]. Because new moon conjunction occurs globally at an absolute instant in time, the civil date of the 1st lunar day depends entirely on whether this instant falls before or after local midnight. A slight error in handling midnight transitions can shift the entire lunar month by one full civil day.

7 Sources and materials

This reference method inherits fundamental principles from:

  1. ISO 8601 international date and time representations [1].
  2. Terrestrial Time reductions and planetary coordinates from JPL DE405 [3].
  3. Vietnamese lunisolar meridian research by Hồ Ngọc Đức [5].

8 Methodology

The methodology comprises three discrete computation steps:

  1. Ingest raw timestamp TutcT_{utc} and reference timezone identifier.
  2. Project TutcT_{utc} onto the local time axis via a linear translation with offset ZZ.
  3. Partition the local time axis into disjoint intervals of duration 86,400,000 ms86,400,000\text{ ms}, with origin at midnight 1970-01-01.

9 Formal model

Let Tutc∈ZT_{utc} \in \mathbb{Z} be milliseconds since the UTC epoch. Let Z∈[−720,840]Z \in [-720, 840] be timezone offset in minutes.

Local time TlocalT_{local} is defined as:

Tlocal=Tutc+(Z×60 000)T_{local} = T_{utc} + (Z \times 60,000)

The continuous civil day index DcivilD_{civil} (days since local 1970-01-01) is evaluated via the floor function:

Dcivil=⌊Tlocal86 400 000⌋D_{civil} = \left\lfloor \frac{T_{local}}{86,400,000} \right\rfloor

Midnight marking the start of a civil day corresponds to values of TlocalT_{local} satisfying:

Tlocal(mod86 400 000)=0T_{local} \pmod{86,400,000} = 0

10 Algorithm or rules

10.1 Rule R001: Civil Midnight Ingestion Rule

  • Rule ID: CAL-R001
  • Classification: Normative (Mandatory)
  • Preconditions:
    1. TutcT_{utc} is a valid integer representing milliseconds.
    2. ZZ is a valid integer in the range [−720,840][-720, 840].
  • Rule Content: All Quizzman calendar processing systems SHALL determine the start of a new civil day at instant Tlocal≡0(mod86 400 000)T_{local} \equiv 0 \pmod{86,400,000}. If a celestial event (e.g. astronomical new moon) occurs at Tlocal=86 399 999 msT_{local} = 86,399,999\text{ ms}, that event SHALL be assigned to day DcivilD_{civil}. If the event occurs at Tlocal=86 400 000 msT_{local} = 86,400,000\text{ ms}, it SHALL be assigned to day Dcivil+1D_{civil} + 1.
  • Prohibited Behavior: Software implementations SHALL NOT use standard floating-point rounding (Math.round) to avoid one-millisecond boundary errors.

11 Implementation

This standard is implemented in the canonical @quizzman/qm-calendar package [4], module src/core/civil-day.ts:

export function getCivilDateFromTimestamp(
  utcTimestampMs: number,
  timezoneOffsetMinutes: number
): { civilDate: string; civilDayIndex: number } {
  const localMs = utcTimestampMs + timezoneOffsetMinutes * 60_000;
  const civilDayIndex = Math.floor(localMs / 86_400_000);
  const localDate = new Date(localMs);
  
  const year = localDate.getUTCFullYear();
  const month = String(localDate.getUTCMonth() + 1).padStart(2, '0');
  const day = String(localDate.getUTCDate()).padStart(2, '0');
  
  return {
    civilDate: `<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>y</mi><mi>e</mi><mi>a</mi><mi>r</mi></mrow><mo>−</mo></mrow><annotation encoding="application/x-tex">{year}-</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.7778em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.0359em;">y</span><span class="mord mathnormal">e</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.0278em;">r</span></span><span class="mord">−</span></span></span></span>{month}-${day}`,
    civilDayIndex
  };
}

12 Validation

Method validity was audited through automated test suites against dataset CAL-BENCH-001 (version 1.2.0), comprising:

  1. 100 pseudo-random timestamps spanning from year 1900 to 2100.
  2. 39 boundary-sensitive timestamps: instants 23:59:59.99923:59:59.999, 00:00:00.00000:00:00.000, and 00:00:00.00100:00:00.001 on leap month and leap year transitions.

13 Results

In formal benchmark comparisons against CAL-BENCH-001:

  • Evaluated test vectors: 139 / 139 cases.
  • Exact matches: 139 / 139 cases (100% of benchmark suite).
  • Discrepancies: 0 cases.
  • Mean execution duration: 0.0002 ms per conversion operation under Node.js 20.x runtime.

14 Discussion

Empirical results corroborate the arithmetic stability of the integer floor function (floor). Decoupling legal timezone offset ZZ from pure UTC time eliminates Daylight Saving Time (DST) edge effects, guaranteeing the strict determinism required for state synchronization across distributed architectures.

15 Limitations

The method is subject to the following documented constraints:

  1. Time Representation Range: The algorithm relies on JavaScript IEEE 754 64-bit safe integers (safe bounds from −8,640,000,000,000,000 ms-8,640,000,000,000,000\text{ ms} to +8,640,000,000,000,000 ms+8,640,000,000,000,000\text{ ms}, covering approximately years −271821-271821 to +275760+275760). Beyond this span, representation errors may occur.
  2. Historical Timezone Variations: The method assumes offset ZZ is a known constant for the queried epoch. For dates prior to the 20th century without standardized international timezones, supplementary historical offset tables must be consulted rather than a static constant ZZ.
  3. Validation Scope: Passing 139 test cases in CAL-BENCH-001 validates consistency within the benchmark domain, but does not substitute for jurisdiction-specific legal timezone transition rules in idiosyncratic territories.

16 Conclusion

Reference method QP-EXAMPLE-001 for determining civil day boundaries demonstrates mathematical rigor and full conformance with ISO 8601 international standards. This document is approved as a canonical stable reference specification across all applications in the Quizzman ecosystem.

Bibliography

[1] International Organization for Standardization. ISO 8601-1:2019 Date and time — Representations for information interchange. Geneva: ISO, 2019.
[2] Jean Meeus. Astronomical Algorithms. 2nd edition. Richmond: Willmann-Bell, 1998.
[3] E. Myles Standish. JPL Planetary and Lunar Ephemerides, DE405/LE405. JPL IOM 312.F, 1998.
[4] Quizzman Research & Engineering. Quizzman Calendar Engine Specification. Version 2.1.0, 2026.
[5] Hồ Ngọc Đức. Lunisolar Calendar Calculations and Vietnamese Standard Meridian. Leipzig University, 2000.

Annex A — Algorithms (Normative)

Reference implementation of civil boundary evaluation and temporal indexing:

export interface CivilDayResult {
  readonly timestampLocalMs: number;
  readonly civilDayIndex: number;
  readonly isExactMidnight: boolean;
}

export function evaluateCivilBoundary(
  utcMs: number,
  offsetMinutes: number
): CivilDayResult {
  const timestampLocalMs = utcMs + offsetMinutes * 60_000;
  const civilDayIndex = Math.floor(timestampLocalMs / 86_400_000);
  const remainder = ((timestampLocalMs % 86_400_000) + 86_400_000) % 86_400_000;
  
  return {
    timestampLocalMs,
    civilDayIndex,
    isExactMidnight: remainder === 0
  };
}

Annex B — Test vectors (Informative)

Sample test vectors extracted from CAL-BENCH-001 (see artifacts/test-vectors.json for complete suite):

Test ID UTC ISO Timestamp Timezone (ZZ) Local ISO Timestamp Expected Civil Date Result
CAL-R001-T01 2026-09-30T23:59:59.000Z +420 (VN) 2026-10-01T06:59:59.000+07:00 2026-10-01 PASS
CAL-R001-T02 2026-09-30T07:59:59.999Z +420 (VN) 2026-09-30T14:59:59.999+07:00 2026-09-30 PASS
CAL-R001-T03 2026-10-01T01:00:00.000Z +420 (VN) 2026-10-01T08:00:00.000+07:00 2026-10-01 PASS

Bibliography (ISO 690 Profile)

  1. [1] International Organization for Standardization. ISO 8601-1:2019 Date and time — Representations for information interchange — Part 1: Basic rules. ISO, 2019. [URL] (Governing standard for civil date boundaries and 24-hour midnight representation.)
  2. [2] Meeus, Jean. Astronomical Algorithms. Edition 2. Willmann-Bell, Inc., 1998. (Foundational reference for solar and dynamical time reductions.)
  3. [3] Standish, E. Myles. JPL Planetary and Lunar Ephemerides, DE405/LE405. In: JPL Interoffice Memorandum. 1998. [URL] (High-precision reference ephemeris for celestial coordinate transformations.)
  4. [4] Quizzman Research & Engineering. Quizzman Calendar Engine. 2026. [URL] (Reference TypeScript implementation for civil and lunisolar conversions.)
  5. [5] Ho, Ngoc Duc. Lunisolar Calendar Calculations and Vietnamese Standard Meridian. Leipzig University Technical Reports, 2000. [URL] (Pioneering mathematical formulation for UTC+7 standard meridian lunisolar conversion.)
  6. [*] IANA Time Zone Database Contributor Group. Time Zone Database (tzdb). 2026. [URL] (Definitive historical and present time zone rules and leap second tables.)