Abstract
背景與問題: 於 Quizzman 陰陽曆運算與天文計算系統中,於地方午夜確定民用日界限(civil day boundary),乃裁定月初一日(定朔)與節氣交節之先決基礎。時區規約與時間尺度之微小偏差皆可能引發整日之曆日錯位。
方法: 本文件將依據特定地理子午線地方時判定民用日交接之數學基準方法形式化,嚴格遵循 ISO 8601 原則與 Meeus 天體力學時還原模型。
成果: 本演算法於基準資料集 CAL-BENCH-001(版本 1.2.0)之 139 項邊界測試用例中通過檢驗,達成與實測真值完全吻合。
結論: 本方法獲核准為 @quizzman/qm-calendar 函式庫及 Quizzman 生態系所有曆法運算服務之權威基準依據。
1 Scope
本規範訂定下列數學方法與規範性演算法法則:
- 確定地方時標下民用日之起止瞬時。
- 將 Unix 時間戳記(UTC 毫秒)連續轉換為離散整數民用日指數。
- 建立天文星曆計算層與民用曆法表達層間之標準界面。
本規範適用於 Quizzman 架構下所有計算引擎,特別是同步越南陰陽曆(法定基準時區 UTC+07:00)與國際曆法標準之各模組。
2 Normative references
下列引據文件為本方法施行所不可或缺之依據:
- 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
就本文件而言,適用下列術語與定義:
3.1 civil day
於地方民用時中持續精確 86,400 標準平太陽秒之時間區間(計入閏秒調整若有),始於午夜(00:00:00)並終止於當日之 24:00:00。
3.2 midnight transition
相鄰兩個民用日間之瞬時交接界限,對應於地方時 。
3.3 governing timezone offset
特定管轄區法定時間與協調世界時(UTC)間之標準時間位移(以分鐘或秒計)。
4 Symbols and abbreviated terms
- : 自 Unix 曆元(1970-01-01T00:00:00Z)起計之毫秒時間戳記。
- : 基準時區偏移量(以分鐘計,例如 UTC+07:00 為 )。
- : 疊加偏移量 後之地方毫秒時間戳記。
- : 連續整數民用日指數(儒略日數或自曆元起計日數)。
- : 地球力學時(TT)與世界時(UT1)之差值。
5 Conventions and assumptions
- 基準時間系統: Quizzman 分散式核心層所有輸入時間戳記 SHALL 統一以 UTC 格式存儲。
- 法定基準子午線: 傳統越南陰陽曆採用東經 子午線,對應法定時區偏移量 分鐘(參見 [5])。
- 捨入規約: 連續時間轉換為離散曆日,SHALL 於地方時間軸上強制採用向下取整函數(
floor)。
6 Background
東亞陰陽曆依託兩大核心天文現象:定朔以定月初一日,二分二至以定二十四節氣 [2]。因朔望合相於全地球為同一絕對物理瞬時,農曆初一日之判定完全取決於該合相瞬時落在地方午夜之前或之後。午夜交界處之微小瑕疵將導致整個農曆月份偏移整整一日。
7 Sources and materials
本基準方法承襲下列核心原則:
8 Methodology
計算方法由三個離散階段組成:
- 讀取原始時間戳記 及基準時區標識。
- 藉由時區偏移 之線性平移變換,將 投影至地方時間軸。
- 以 1970-01-01 午夜為坐標原點,將地方時間軸劃分為長度為 之互斥時間區間。
9 Formal model
設 為自 UTC 曆元起計之毫秒數。設 為以分鐘計之時區偏移量。
地方時間 定義為:
連續民用日指數 (自地方 1970-01-01 起之日數)依高斯向下取整函數計算:
標誌民用日起始之午夜對應滿足下列條件之 值:
10 Algorithm or rules
10.1 法則 R001:午夜交接吸收準則 (Civil Midnight Ingestion Rule)
- 法則編號:
CAL-R001 - 性質: 規範性(強制遵行)
- 前提條件:
- 為表達毫秒之有效整數。
- 為 範圍內之有效整數。
- 法則內容: Quizzman 曆法處理系統 SHALL 於瞬時 確立新民用日之起點。 若一天文事件(如定朔合相)發生於 ,該事件 SHALL 歸入 日。若事件發生於 ,該事件 SHALL 歸入 日。
- 禁止行為: 軟體實作 SHALL NOT 使用常規浮點四捨五入(
Math.round),以杜絕邊界處之一毫秒偏差。
11 Implementation
本標準於官方軟體包 @quizzman/qm-calendar [4] 之 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
方法有效性依據基準測試集 CAL-BENCH-001(版本 1.2.0)進行自動化審定,涵蓋:
- 1900 年至 2100 年間之 100 個隨機選定時間戳記。
- 39 個敏感邊界時間戳記:涵蓋閏月與閏年交接時之 、 與 瞬時。
13 Results
於針對 CAL-BENCH-001 之正式驗證中:
- 評估測試向量: 139 / 139 例。
- 完全吻合數: 139 / 139 例(達成率 100%)。
- 分歧差異數: 0 例。
- 平均執行耗時: 於 Node.js 20.x 環境下每次轉換耗時 0.0002 ms。
14 Discussion
實測結果證實了整數向下取整函數(floor)之算術穩定性。將法定時區偏移量 與 UTC 時間解耦,消除了夏令時(DST)所帶來之邊緣擾動,確保了分散式架構狀態同步所需之確定性。
15 Limitations
本方法受限於以下技術邊界:
- 數值表達範圍: 演算法依賴 JavaScript IEEE 754 64位元浮點安全整數(安全範圍自 至 ,涵蓋公元前 271,821 年至公元 275,760 年)。超越該區間可能產生數值誤差。
- 歷史時區演替: 方法假設偏移量 於查詢時為已知常數。針對 20 世紀前未具備國際標準時區之年代,須調用專門之歷史時區轉換表而非固定常數 。
- 驗證涵蓋度: 通過
CAL-BENCH-001之 139 個用例證實了基準領域內之一致性,但無法替代特定法規下異質行政區之特殊日光規定。
16 Conclusion
民用日界限判定基準方法 QP-EXAMPLE-001 展現了數學之嚴密性並與 ISO 8601 國際標準高度相容。本文件被核准為 Quizzman 生態系所有應用程式之 stable 級別官方基準規範。
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)
民用界限判定與時間索引配置之規範性實作:
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)
自 CAL-BENCH-001 抽取之測試向量樣本(完整集合見 artifacts/test-vectors.json):
| 測試序號 | UTC ISO 時間戳記 | 時區 () | 地方 ISO 時間戳記 | 預期民用日 | 測試判定 |
|---|---|---|---|---|---|
| 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 |
參考文獻(ISO 690 規範)
- [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] Meeus, Jean. Astronomical Algorithms. Edition 2. Willmann-Bell, Inc., 1998. (Foundational reference for solar and dynamical time reductions.)
- [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] Quizzman Research & Engineering. Quizzman Calendar Engine. 2026. [URL] (Reference TypeScript implementation for civil and lunisolar conversions.)
- [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.)
- [*] IANA Time Zone Database Contributor Group. Time Zone Database (tzdb). 2026. [URL] (Definitive historical and present time zone rules and leap second tables.)