From 6e68650d095e2cc4aa766e39160892a83be8babe Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 3 Oct 2026 18:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E8=A7=88=E5=8C=97=E4=BA=AC=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=97=81=E5=A2=9E=E5=8A=A0=E5=91=A8=E5=87=A0=E4=B8=8E?= =?UTF-8?q?=E5=86=9C=E5=8E=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- static/hub.css | 24 +++++ static/hub.js | 187 ++++++++++++++++++++++++++++++++------- templates/base.html | 2 +- templates/dashboard.html | 3 +- 4 files changed, 182 insertions(+), 34 deletions(-) diff --git a/static/hub.css b/static/hub.css index c112391..13c78e8 100644 --- a/static/hub.css +++ b/static/hub.css @@ -102,6 +102,7 @@ body.page-login .main { margin-left: auto; display: inline-flex; align-items: center; + flex-wrap: wrap; gap: 10px; padding: 0; border: 0; @@ -134,6 +135,29 @@ body.page-login .main { font-variant-numeric: tabular-nums; white-space: nowrap; } +.overview-bj-meta { + display: inline-flex; + align-items: center; + gap: 8px; + font-size: 0.88rem; + font-weight: 550; + letter-spacing: 0.02em; + color: var(--text); + white-space: nowrap; +} +.overview-bj-meta::before { + content: ""; + display: inline-block; + width: 1px; + height: 12px; + background: rgba(56, 189, 248, 0.35); +} +.overview-bj-weekday { + color: var(--text); +} +.overview-bj-lunar { + color: var(--muted); +} @media (max-width: 720px) { .page-head { flex-wrap: wrap; } .overview-bj-clock { diff --git a/static/hub.js b/static/hub.js index 690a736..a0372bd 100644 --- a/static/hub.js +++ b/static/hub.js @@ -505,7 +505,109 @@ } } - function formatBeijingNow() { + const WEEKDAYS = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; + const LUNAR_MONTHS = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊"]; + const LUNAR_INFO = [ + 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, + 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, + 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, + 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, + 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, + 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, + 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, + 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, + 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, + 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, + 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, + 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, + 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, + 0x05aa0, 0x076a3, 0x096d0, 0x04afb, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, + 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, + 0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, + 0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, + 0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, + 0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, + 0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, + 0x0d520, + ]; + + function lunarLeapMonth(year) { + return LUNAR_INFO[year - 1900] & 0xf; + } + + function lunarLeapDays(year) { + if (!lunarLeapMonth(year)) return 0; + return LUNAR_INFO[year - 1900] & 0x10000 ? 30 : 29; + } + + function lunarMonthDays(year, month) { + return LUNAR_INFO[year - 1900] & (0x10000 >> month) ? 30 : 29; + } + + function lunarYearDays(year) { + let sum = 348; + for (let i = 0x8000; i > 0x8; i >>= 1) { + sum += LUNAR_INFO[year - 1900] & i ? 1 : 0; + } + return sum + lunarLeapDays(year); + } + + function lunarDayName(day) { + const n = ["日", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]; + if (day === 10) return "初十"; + if (day === 20) return "二十"; + if (day === 30) return "三十"; + if (day < 11) return "初" + n[day]; + if (day < 20) return "十" + n[day - 10]; + return "廿" + n[day - 20]; + } + + function solarToLunarText(year, month, day) { + if (year < 1900 || year > 2100) return ""; + let offset = Math.round( + (Date.UTC(year, month - 1, day) - Date.UTC(1900, 0, 31)) / 86400000 + ); + let i; + let temp = 0; + for (i = 1900; i < 2101 && offset > 0; i++) { + temp = lunarYearDays(i); + offset -= temp; + } + if (offset < 0) { + offset += temp; + i--; + } + const lunarYear = i; + const leap = lunarLeapMonth(lunarYear); + let isLeap = false; + for (i = 1; i < 13 && offset > 0; i++) { + if (leap > 0 && i === leap + 1 && !isLeap) { + i--; + isLeap = true; + temp = lunarLeapDays(lunarYear); + } else { + temp = lunarMonthDays(lunarYear, i); + } + if (isLeap && i === leap + 1) isLeap = false; + offset -= temp; + } + if (offset === 0 && leap > 0 && i === leap + 1) { + if (isLeap) { + isLeap = false; + } else { + isLeap = true; + i--; + } + } + if (offset < 0) { + offset += temp; + i--; + } + const monthName = (isLeap ? "闰" : "") + LUNAR_MONTHS[i - 1] + "月"; + return "农历" + monthName + lunarDayName(offset + 1); + } + + function beijingParts() { try { const parts = new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Shanghai", @@ -523,48 +625,69 @@ }); return hit ? hit.value : ""; }; - return ( - get("year") + - "-" + - get("month") + - "-" + - get("day") + - " " + - get("hour") + - ":" + - get("minute") + - ":" + - get("second") - ); + const y = Number(get("year")); + const m = Number(get("month")); + const d = Number(get("day")); + return { + time: + get("year") + + "-" + + get("month") + + "-" + + get("day") + + " " + + get("hour") + + ":" + + get("minute") + + ":" + + get("second"), + weekday: WEEKDAYS[new Date(Date.UTC(y, m - 1, d)).getUTCDay()] || "", + lunar: solarToLunarText(y, m, d), + }; } catch (e) { - const d = new Date(); - const utc = d.getTime() + d.getTimezoneOffset() * 60000; + const now = new Date(); + const utc = now.getTime() + now.getTimezoneOffset() * 60000; const bj = new Date(utc + 8 * 3600000); const p = function (n) { return String(n).padStart(2, "0"); }; - return ( - bj.getFullYear() + - "-" + - p(bj.getMonth() + 1) + - "-" + - p(bj.getDate()) + - " " + - p(bj.getHours()) + - ":" + - p(bj.getMinutes()) + - ":" + - p(bj.getSeconds()) - ); + const y = bj.getFullYear(); + const m = bj.getMonth() + 1; + const d = bj.getDate(); + return { + time: + y + + "-" + + p(m) + + "-" + + p(d) + + " " + + p(bj.getHours()) + + ":" + + p(bj.getMinutes()) + + ":" + + p(bj.getSeconds()), + weekday: WEEKDAYS[bj.getDay()] || "", + lunar: solarToLunarText(y, m, d), + }; } } function tickBeijingClock() { const el = document.getElementById("overview-bj-time"); if (!el) return; - const text = formatBeijingNow(); - el.textContent = text; - el.setAttribute("datetime", text.replace(" ", "T") + "+08:00"); + const parts = beijingParts(); + el.textContent = parts.time; + el.setAttribute("datetime", parts.time.replace(" ", "T") + "+08:00"); + const meta = document.getElementById("overview-bj-meta"); + if (meta) { + const bits = [parts.weekday, parts.lunar].filter(Boolean); + meta.innerHTML = + '' + + bits[0] + + "" + + (bits[1] ? '' + bits[1] + "" : ""); + } } function boot() { diff --git a/templates/base.html b/templates/base.html index 8674b31..7a3ca24 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,7 +4,7 @@ {% block title %}期权中控{% endblock %} - + {% if session.get('logged_in') %} diff --git a/templates/dashboard.html b/templates/dashboard.html index 9150f54..7c37855 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -6,6 +6,7 @@
北京时间 +
@@ -14,6 +15,6 @@
{% endblock %} {% block scripts %} - + {% endblock %}