Files
bookMgr-client/src/lib/formatters.ts
T
msksbr f28dc98f5e {"type":"assistant","message":{"id":"2099424a-0948-4423-a191-3c37d24e52ed","type":"message","role":"assistant","model":"deepseek-v4-flash","content":[{"type":"thinking","thinking":"The user wants me to generate a commit message based on the git diff provided. Let me analyze the changes:
1. **AdminLayout.tsx** - Major changes:
   - Added imports for `NavLink`, `useNavigate`, `BookOpenIcon`, `ListIcon`, `LogOutIcon`, `Button`, `useAuthStore`, `usePlatform`
   - Added navigation items array with book management and borrow management
   - Added admin layout with sidebar navigation, header with username, and logout functionality
   - Added responsive layout for desktop/mobile

2. **router/index.tsx** - Changes:
   - Removed placeholder components (`AdminBooksPage`, `AdminBorrowsPage`, `AdminIndexPage`)
   - Added imports from actual admin feature pages
   - Updated routes to use real admin layout and pages

This is clearly a **feat** (new feature) commit, adding admin layout with navigation and routing to real pages. The scope would be **admin** or **ui**.

The key changes are:
- Adding admin sidebar navigation with book/borrow management links
- Adding logout functionality with username display
- Replacing placeholder admin page components with real page implementations
- Integrating admin layout with the router

Let me write a concise commit message following the rules.","signature":"2099424a-0948-4423-a191-3c37d24e52ed"}],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":25016,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"service_tier":"standard"},"context_management":null},"parent_tool_use_id":null,"session_id":"bf312622-fae8-446d-8b67-c708b9d3a022","uuid":"50eb9e22-cc58-4b45-8f03-95386c522466"}{"type":"assistant","message":{"id":"2099424a-0948-4423-a191-3c37d24e52ed","type":"message","role":"assistant","model":"deepseek-v4-flash","content":[{"type":"text","text":"<commit>
feat(admin): add sidebar navigation and real page routes

Implement admin layout with sidebar navigation for book and borrow
management, including logout functionality and username display.
Replace placeholder admin page components with actual page routes."}],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":25016,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"service_tier":"standard"},"context_management":null},"parent_tool_use_id":null,"session_id":"bf312622-fae8-446d-8b67-c708b9d3a022","uuid":"1ca45e82-b885-4fa0-b886-fdfced0dc2e4"}<commit>
2026-05-24 20:28:28 +08:00

54 lines
1.6 KiB
TypeScript

export function formatDateTime(raw: unknown): string {
const d = toDate(raw)
if (!d) return "-"
const Y = d.getFullYear()
const M = String(d.getMonth() + 1).padStart(2, "0")
const D = String(d.getDate()).padStart(2, "0")
const h = String(d.getHours()).padStart(2, "0")
const m = String(d.getMinutes()).padStart(2, "0")
return `${Y}-${M}-${D} ${h}:${m}`
}
export function formatDate(raw: unknown): string {
const d = toDate(raw)
if (!d) return "-"
return d.toLocaleDateString()
}
function toDate(raw: unknown): Date | null {
if (raw == null) return null
if (raw instanceof Date) return isNaN(raw.getTime()) ? null : raw
if (typeof raw === "string") {
const d = new Date(raw)
return isNaN(d.getTime()) ? null : d
}
if (typeof raw === "number") {
const d = new Date(raw)
return isNaN(d.getTime()) ? null : d
}
// Java LocalDateTime array: [year, month, day, hour, minute, second, nanos]
if (Array.isArray(raw) && raw.length >= 3) {
const [y, mo, d, h = 0, mi = 0, s = 0] = raw
return new Date(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s))
}
if (typeof raw === "object") {
const obj = raw as Record<string, unknown>
const y = Number(obj.year ?? 0)
const mo = Number(obj.monthValue ?? obj.month ?? 1)
const d = Number(obj.dayOfMonth ?? obj.day ?? 1)
const h = Number(obj.hour ?? 0)
const mi = Number(obj.minute ?? 0)
const s = Number(obj.second ?? 0)
if (!isNaN(y) && !isNaN(mo) && !isNaN(d)) {
return new Date(y, mo - 1, d, h, mi, s)
}
}
return null
}