Simplify day segment hour formatting

master
dev 5 months ago
parent 101ba02e3d
commit 77a7cc86a5

@ -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.

@ -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 }> {

Loading…
Cancel
Save

Powered by TurnKey Linux.