From 77a7cc86a55a66ae87919572c35569d8941fbe4b Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 29 Apr 2026 21:52:11 +0200 Subject: [PATCH] Simplify day segment hour formatting --- NEXT_STEPS.md | 1 + src/libs/days/segments.ts | 36 ++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/NEXT_STEPS.md b/NEXT_STEPS.md index 250f81d..9d314de 100644 --- a/NEXT_STEPS.md +++ b/NEXT_STEPS.md @@ -52,6 +52,7 @@ Estado al cierre: - `arts/timr/engine-timers.ts` delega cancelacion y seleccion por scope en `timer-cancel.ts`. - `arts/timr/engine-timers.ts` delega entrada viva, contexto de task y max-runs en `timer-entry.ts`. - `libs/color/segments.ts` reutiliza helpers locales para canales requeridos y parsing por rango RGB/HSL. + - `libs/days/segments.ts` centraliza el formateo de hora 12h y mantiene imports agrupados. - Integracion total ampliada: `Auth.signOut()` valida anonimizacion, invalidacion de `Permissions` y evento `Cache.invalidate`. - Tanda focalizada verde: `npx vitest run src/arts/conn src/libs/cach src/arts/cach src/svrs/cach src/arts/auth src/svrs/auth src/libs/auth src/arts/aapp/test/ecosystem.integration.test.ts` -> 19 archivos, 82 tests. - `/test/ecosystem` revisado en navegador: carga sin errores de consola, `ar` cambia a `rtl`, Formats se actualiza por locale, Perm cambia con rol `viewer`, Cach re-scopea por locale y Conn loopback publica/recibe. diff --git a/src/libs/days/segments.ts b/src/libs/days/segments.ts index 6806a05..98468c9 100644 --- a/src/libs/days/segments.ts +++ b/src/libs/days/segments.ts @@ -26,6 +26,8 @@ import type { TimeValue } from './types'; import { getCachedDateFormat, getDefaultHourCycle, getPlaceholder } from './format'; +import { hasTime, isZonedDateTime } from './queries'; +import { convertTimeValueToDateValue, dateValueToDate } from './operations'; /** * Segment placeholder text shown when a segment is empty. Delegates to dias' @@ -42,8 +44,6 @@ function getSegmentPlaceholder( if (part === 'second') return 'ss'; return getPlaceholder(part, '', locale); } -import { hasTime, isZonedDateTime } from './queries'; -import { convertTimeValueToDateValue, dateValueToDate } from './operations'; // ── Constants ─────────────────────────────────────────────────────────────── @@ -400,15 +400,7 @@ function buildSegmentContentObj(input: CreateSegmentContentInput): SegmentConten }); if (part === 'hour' && has12HourClock) { - if (intValue > 12) { - const hour = intValue - 12; - if (hour === 0) return '12'; - if (hour < 10) return `0${hour}`; - return `${hour}`; - } - if (intValue === 0) return '12'; - if (intValue < 10) return `0${intValue}`; - return `${intValue}`; + return format12HourSegment(intValue); } if (part === 'year') return `${value}`; @@ -564,15 +556,7 @@ function buildTimeContentObj(input: CreateTimeSegmentContentInput): TimeSegmentC }); if (part === 'hour' && has12HourClock) { - if (intValue > 12) { - const hour = intValue - 12; - if (hour === 0) return '12'; - if (hour < 10) return `0${hour}`; - return `${hour}`; - } - if (intValue === 0) return '12'; - if (intValue < 10) return `0${intValue}`; - return `${intValue}`; + return format12HourSegment(intValue); } if (leadingZero && formatted.length === 1) return `0${formatted}`; @@ -584,6 +568,18 @@ function buildTimeContentObj(input: CreateTimeSegmentContentInput): TimeSegmentC return content; } +function format12HourSegment(hour24: number): string { + if (hour24 > 12) { + const hour = hour24 - 12; + if (hour === 0) return '12'; + if (hour < 10) return `0${hour}`; + return `${hour}`; + } + if (hour24 === 0) return '12'; + if (hour24 < 10) return `0${hour24}`; + return `${hour24}`; +} + function buildTimeContentArr( input: CreateTimeSegmentContentInput & { contentObj: TimeSegmentContentObj } ): Array<{ part: TimeSegmentPart; value: string }> {