From b3fc77a28eeceb8d28e09b7b4f76c33ed2dd563a Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 30 Mar 2026 05:38:08 +0200 Subject: [PATCH] Refactor terra date utilities split --- .../lib/date => util/dates}/CalendarDate.ts | 0 .../lib/date => util/dates}/DateFormatter.ts | 4 + .../dates}/calendars/BuddhistCalendar.ts | 0 .../dates}/calendars/EthiopicCalendar.ts | 2 +- .../dates}/calendars/GregorianCalendar.ts | 4 +- .../dates}/calendars/HebrewCalendar.ts | 4 +- .../dates}/calendars/IndianCalendar.ts | 0 .../dates}/calendars/IslamicCalendar.ts | 0 .../dates}/calendars/JapaneseCalendar.ts | 2 +- .../dates}/calendars/PersianCalendar.ts | 3 +- .../dates}/calendars/TaiwanCalendar.ts | 2 +- .../lib/date => util/dates}/conversion.ts | 0 .../lib/date => util/dates}/createCalendar.ts | 0 .../{glob/lib/date => util/dates}/defaults.ts | 10 +- .../{glob/lib/date => util/dates}/index.ts | 11 + .../lib/date => util/dates}/manipulation.ts | 0 .../util/dates}/placeholders.ts | 0 .../{glob/lib/date => util/dates}/queries.ts | 0 .../{glob/lib/date => util/dates}/string.ts | 0 .../{glob/lib/date => util/dates}/types.ts | 34 +- src/lib/util/dates/utils.ts | 11 + .../lib/date => util/dates}/weekStartData.ts | 0 src/lib/util/funcs/index.ts | 1 + .../terra/utils => lib/util/funcs}/noop.ts | 0 src/lib/util/objs/index.ts | 4 + .../date/utils.ts => util/objs/utilities.ts} | 5 +- src/lib/util/timers/debounce.ts | 2 + src/lib/util/timers/index.ts | 2 + src/routes/test/calendar/+page.svelte | 10 +- src/routes/test/date-picker/+page.svelte | 271 ++++++++++++- src/routes/test/date-range-field/+page.svelte | 16 +- .../test/date-range-picker/+page.svelte | 4 +- src/routes/test/range-calendar/+page.svelte | 10 +- src/routes/test/time-field/+page.svelte | 22 +- src/routes/test/time-range-field/+page.svelte | 21 +- src/uix/terra/base/config/index.ts | 2 +- src/uix/terra/base/config/prop-resolvers.ts | 12 +- src/uix/terra/base/config/types.ts | 10 +- src/uix/terra/base/mounted.svelte | 3 +- src/uix/terra/calendar/calendar.svelte.ts | 10 +- .../calendar/components/calendar-day.svelte | 1 + .../components/calendar-grid-body.svelte | 1 + .../components/calendar-grid-head.svelte | 1 + .../components/calendar-grid-row.svelte | 1 + .../calendar/components/calendar-grid.svelte | 1 + .../components/calendar-header.svelte | 1 + .../components/calendar-heading.svelte | 1 + .../components/calendar-month-select.svelte | 1 + .../components/calendar-next-button.svelte | 1 + .../components/calendar-prev-button.svelte | 1 + .../components/calendar-year-select.svelte | 1 + .../terra/calendar/components/calendar.svelte | 7 +- src/uix/terra/calendar/exports.ts | 1 + src/uix/terra/calendar/index.ts | 1 + src/uix/terra/calendar/types.ts | 7 +- .../components/date-field-hidden-input.svelte | 1 + .../components/date-field-input.svelte | 1 + .../components/date-field-segment.svelte | 1 + .../date-field/components/date-field.svelte | 7 +- src/uix/terra/date-field/date-field.svelte.ts | 21 +- src/uix/terra/date-field/exports.ts | 1 + src/uix/terra/date-field/index.ts | 1 + src/uix/terra/date-field/types.ts | 4 +- .../components/date-picker-calendar.svelte | 1 + .../components/date-picker-trigger.svelte | 3 +- .../date-picker/components/date-picker.svelte | 9 +- .../terra/date-picker/date-picker.svelte.ts | 9 +- src/uix/terra/date-picker/exports.ts | 1 + src/uix/terra/date-picker/index.ts | 1 + src/uix/terra/date-picker/types.ts | 5 +- .../components/date-range-field-input.svelte | 1 + .../components/date-range-field.svelte | 12 +- .../date-range-field.svelte.ts | 20 +- src/uix/terra/date-range-field/exports.ts | 1 + src/uix/terra/date-range-field/index.ts | 1 + src/uix/terra/date-range-field/types.ts | 6 +- .../date-range-picker-calendar.svelte | 1 + .../date-range-picker-trigger.svelte | 3 +- .../components/date-range-picker.svelte | 8 +- .../date-range-picker.svelte.ts | 9 +- src/uix/terra/date-range-picker/exports.ts | 1 + src/uix/terra/date-range-picker/index.ts | 5 +- src/uix/terra/date-range-picker/types.ts | 5 +- .../components/range-calendar-day.svelte | 1 + .../components/range-calendar.svelte | 7 +- src/uix/terra/range-calendar/exports.ts | 1 + src/uix/terra/range-calendar/index.ts | 5 +- .../range-calendar/range-calendar.svelte.ts | 8 +- src/uix/terra/range-calendar/types.ts | 7 +- .../components/time-field-hidden-input.svelte | 1 + .../components/time-field-input.svelte | 1 + .../components/time-field-segment.svelte | 1 + .../time-field/components/time-field.svelte | 7 +- src/uix/terra/time-field/exports.ts | 1 + src/uix/terra/time-field/index.ts | 1 + src/uix/terra/time-field/time-field.svelte.ts | 15 +- src/uix/terra/time-field/types.ts | 4 +- .../components/time-range-field-input.svelte | 1 + .../components/time-range-field.svelte | 7 +- src/uix/terra/time-range-field/exports.ts | 1 + src/uix/terra/time-range-field/index.ts | 1 + .../time-range-field.svelte.ts | 16 +- src/uix/terra/time-range-field/types.ts | 4 +- src/uix/terra/utils/arrays.ts | 268 ------------- src/uix/terra/utils/clamp.ts | 6 - .../utils/datetime/calendar-helpers.svelte.ts | 6 +- src/uix/terra/utils/datetime/field/types.ts | 35 -- src/uix/terra/utils/datetime/formatter.ts | 4 +- .../utils/datetime/{field => }/helpers.ts | 32 +- .../terra/utils/datetime/{field => }/index.ts | 1 + .../terra/utils/datetime/{field => }/parts.ts | 0 .../utils/datetime/{field => }/segments.ts | 4 +- .../datetime/{field => }/time-helpers.ts | 20 +- src/uix/terra/utils/datetime/types.ts | 6 +- src/uix/terra/utils/debounce.ts | 22 -- .../dom/tests/dom-context.test.svelte.ts | 371 ------------------ .../terra/utils/dom/tests/dom-context.test.ts | 359 ----------------- src/uix/terra/utils/dom/tests/dom.test.ts | 302 -------------- src/uix/terra/utils/math.ts | 18 - 119 files changed, 622 insertions(+), 1580 deletions(-) rename src/lib/{glob/lib/date => util/dates}/CalendarDate.ts (100%) rename src/lib/{glob/lib/date => util/dates}/DateFormatter.ts (99%) rename src/lib/{glob/lib/date => util/dates}/calendars/BuddhistCalendar.ts (100%) rename src/lib/{glob/lib/date => util/dates}/calendars/EthiopicCalendar.ts (99%) rename src/lib/{glob/lib/date => util/dates}/calendars/GregorianCalendar.ts (98%) rename src/lib/{glob/lib/date => util/dates}/calendars/HebrewCalendar.ts (98%) rename src/lib/{glob/lib/date => util/dates}/calendars/IndianCalendar.ts (100%) rename src/lib/{glob/lib/date => util/dates}/calendars/IslamicCalendar.ts (100%) rename src/lib/{glob/lib/date => util/dates}/calendars/JapaneseCalendar.ts (99%) rename src/lib/{glob/lib/date => util/dates}/calendars/PersianCalendar.ts (98%) rename src/lib/{glob/lib/date => util/dates}/calendars/TaiwanCalendar.ts (98%) rename src/lib/{glob/lib/date => util/dates}/conversion.ts (100%) rename src/lib/{glob/lib/date => util/dates}/createCalendar.ts (100%) rename src/lib/{glob/lib/date => util/dates}/defaults.ts (92%) rename src/lib/{glob/lib/date => util/dates}/index.ts (95%) rename src/lib/{glob/lib/date => util/dates}/manipulation.ts (100%) rename src/{uix/terra/utils/datetime => lib/util/dates}/placeholders.ts (100%) rename src/lib/{glob/lib/date => util/dates}/queries.ts (100%) rename src/lib/{glob/lib/date => util/dates}/string.ts (100%) rename src/lib/{glob/lib/date => util/dates}/types.ts (94%) create mode 100644 src/lib/util/dates/utils.ts rename src/lib/{glob/lib/date => util/dates}/weekStartData.ts (100%) create mode 100644 src/lib/util/funcs/index.ts rename src/{uix/terra/utils => lib/util/funcs}/noop.ts (100%) create mode 100644 src/lib/util/objs/index.ts rename src/lib/{glob/lib/date/utils.ts => util/objs/utilities.ts} (84%) create mode 100644 src/lib/util/timers/debounce.ts create mode 100644 src/lib/util/timers/index.ts delete mode 100644 src/uix/terra/utils/arrays.ts delete mode 100644 src/uix/terra/utils/clamp.ts delete mode 100644 src/uix/terra/utils/datetime/field/types.ts rename src/uix/terra/utils/datetime/{field => }/helpers.ts (94%) rename src/uix/terra/utils/datetime/{field => }/index.ts (78%) rename src/uix/terra/utils/datetime/{field => }/parts.ts (100%) rename src/uix/terra/utils/datetime/{field => }/segments.ts (98%) rename src/uix/terra/utils/datetime/{field => }/time-helpers.ts (95%) delete mode 100644 src/uix/terra/utils/debounce.ts delete mode 100644 src/uix/terra/utils/dom/tests/dom-context.test.svelte.ts delete mode 100644 src/uix/terra/utils/dom/tests/dom-context.test.ts delete mode 100644 src/uix/terra/utils/dom/tests/dom.test.ts delete mode 100644 src/uix/terra/utils/math.ts diff --git a/src/lib/glob/lib/date/CalendarDate.ts b/src/lib/util/dates/CalendarDate.ts similarity index 100% rename from src/lib/glob/lib/date/CalendarDate.ts rename to src/lib/util/dates/CalendarDate.ts diff --git a/src/lib/glob/lib/date/DateFormatter.ts b/src/lib/util/dates/DateFormatter.ts similarity index 99% rename from src/lib/glob/lib/date/DateFormatter.ts rename to src/lib/util/dates/DateFormatter.ts index 5a27171c3..79d6aef4f 100644 --- a/src/lib/glob/lib/date/DateFormatter.ts +++ b/src/lib/util/dates/DateFormatter.ts @@ -10,6 +10,8 @@ * governing permissions and limitations under the License. */ +import type { HourCycle } from '$lib/util/dates/types'; + let formatterCache = new Map(); interface DateRangeFormatPart extends Intl.DateTimeFormatPart { @@ -196,3 +198,5 @@ function getResolvedHourCycle(locale: string, options: Intl.DateTimeFormatOption throw new Error('Unexpected hour cycle result'); } + + diff --git a/src/lib/glob/lib/date/calendars/BuddhistCalendar.ts b/src/lib/util/dates/calendars/BuddhistCalendar.ts similarity index 100% rename from src/lib/glob/lib/date/calendars/BuddhistCalendar.ts rename to src/lib/util/dates/calendars/BuddhistCalendar.ts diff --git a/src/lib/glob/lib/date/calendars/EthiopicCalendar.ts b/src/lib/util/dates/calendars/EthiopicCalendar.ts similarity index 99% rename from src/lib/glob/lib/date/calendars/EthiopicCalendar.ts rename to src/lib/util/dates/calendars/EthiopicCalendar.ts index f5bea84c6..d8eb8d6cf 100644 --- a/src/lib/glob/lib/date/calendars/EthiopicCalendar.ts +++ b/src/lib/util/dates/calendars/EthiopicCalendar.ts @@ -15,7 +15,7 @@ import type {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; -import type {Mutable} from '../utils'; +import type {Mutable} from '$lib/util/objs'; const ETHIOPIC_EPOCH = 1723856; const COPTIC_EPOCH = 1824665; diff --git a/src/lib/glob/lib/date/calendars/GregorianCalendar.ts b/src/lib/util/dates/calendars/GregorianCalendar.ts similarity index 98% rename from src/lib/glob/lib/date/calendars/GregorianCalendar.ts rename to src/lib/util/dates/calendars/GregorianCalendar.ts index 46c422eb3..78b0bf9cc 100644 --- a/src/lib/glob/lib/date/calendars/GregorianCalendar.ts +++ b/src/lib/util/dates/calendars/GregorianCalendar.ts @@ -15,8 +15,8 @@ import type {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; -import {mod} from '../utils'; -import type {Mutable} from '../utils'; +import {mod} from '$lib/util/numbers'; +import type {Mutable} from '$lib/util/objs'; const EPOCH = 1721426; // 001/01/03 Julian C.E. export function gregorianToJulianDay(era: string, year: number, month: number, day: number): number { diff --git a/src/lib/glob/lib/date/calendars/HebrewCalendar.ts b/src/lib/util/dates/calendars/HebrewCalendar.ts similarity index 98% rename from src/lib/glob/lib/date/calendars/HebrewCalendar.ts rename to src/lib/util/dates/calendars/HebrewCalendar.ts index 366200c6e..1467e82c6 100644 --- a/src/lib/glob/lib/date/calendars/HebrewCalendar.ts +++ b/src/lib/util/dates/calendars/HebrewCalendar.ts @@ -15,8 +15,8 @@ import type {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; -import {mod} from '../utils'; -import type {Mutable} from '../utils'; +import {mod} from '$lib/util/numbers'; +import type {Mutable} from '$lib/util/objs'; const HEBREW_EPOCH = 347997; diff --git a/src/lib/glob/lib/date/calendars/IndianCalendar.ts b/src/lib/util/dates/calendars/IndianCalendar.ts similarity index 100% rename from src/lib/glob/lib/date/calendars/IndianCalendar.ts rename to src/lib/util/dates/calendars/IndianCalendar.ts diff --git a/src/lib/glob/lib/date/calendars/IslamicCalendar.ts b/src/lib/util/dates/calendars/IslamicCalendar.ts similarity index 100% rename from src/lib/glob/lib/date/calendars/IslamicCalendar.ts rename to src/lib/util/dates/calendars/IslamicCalendar.ts diff --git a/src/lib/glob/lib/date/calendars/JapaneseCalendar.ts b/src/lib/util/dates/calendars/JapaneseCalendar.ts similarity index 99% rename from src/lib/glob/lib/date/calendars/JapaneseCalendar.ts rename to src/lib/util/dates/calendars/JapaneseCalendar.ts index b27333110..1d248d329 100644 --- a/src/lib/glob/lib/date/calendars/JapaneseCalendar.ts +++ b/src/lib/util/dates/calendars/JapaneseCalendar.ts @@ -16,7 +16,7 @@ import type {AnyCalendarDate, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; import {GregorianCalendar} from './GregorianCalendar'; -import type {Mutable} from '../utils'; +import type {Mutable} from '$lib/util/objs'; const ERA_START_DATES = [[1868, 9, 8], [1912, 7, 30], [1926, 12, 25], [1989, 1, 8], [2019, 5, 1]]; const ERA_END_DATES = [[1912, 7, 29], [1926, 12, 24], [1989, 1, 7], [2019, 4, 30]]; diff --git a/src/lib/glob/lib/date/calendars/PersianCalendar.ts b/src/lib/util/dates/calendars/PersianCalendar.ts similarity index 98% rename from src/lib/glob/lib/date/calendars/PersianCalendar.ts rename to src/lib/util/dates/calendars/PersianCalendar.ts index cb6e22add..2aab2dfdf 100644 --- a/src/lib/glob/lib/date/calendars/PersianCalendar.ts +++ b/src/lib/util/dates/calendars/PersianCalendar.ts @@ -15,7 +15,8 @@ import type {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; -import {mod} from '../utils'; +import {mod} from '$lib/util/numbers'; + const PERSIAN_EPOCH = 1948320; diff --git a/src/lib/glob/lib/date/calendars/TaiwanCalendar.ts b/src/lib/util/dates/calendars/TaiwanCalendar.ts similarity index 98% rename from src/lib/glob/lib/date/calendars/TaiwanCalendar.ts rename to src/lib/util/dates/calendars/TaiwanCalendar.ts index e0eaaab22..da0497903 100644 --- a/src/lib/glob/lib/date/calendars/TaiwanCalendar.ts +++ b/src/lib/util/dates/calendars/TaiwanCalendar.ts @@ -16,7 +16,7 @@ import type {AnyCalendarDate, CalendarIdentifier} from '../types'; import {CalendarDate} from '../CalendarDate'; import {fromExtendedYear, getExtendedYear, GregorianCalendar} from './GregorianCalendar'; -import type {Mutable} from '../utils'; +import type {Mutable} from '$lib/util/objs'; const TAIWAN_ERA_START = 1911; diff --git a/src/lib/glob/lib/date/conversion.ts b/src/lib/util/dates/conversion.ts similarity index 100% rename from src/lib/glob/lib/date/conversion.ts rename to src/lib/util/dates/conversion.ts diff --git a/src/lib/glob/lib/date/createCalendar.ts b/src/lib/util/dates/createCalendar.ts similarity index 100% rename from src/lib/glob/lib/date/createCalendar.ts rename to src/lib/util/dates/createCalendar.ts diff --git a/src/lib/glob/lib/date/defaults.ts b/src/lib/util/dates/defaults.ts similarity index 92% rename from src/lib/glob/lib/date/defaults.ts rename to src/lib/util/dates/defaults.ts index 9d6facca5..d5dd9871f 100644 --- a/src/lib/glob/lib/date/defaults.ts +++ b/src/lib/util/dates/defaults.ts @@ -1,7 +1,15 @@ import {CalendarDate, CalendarDateTime, Time} from './CalendarDate'; import type {DateValue, TimeValue} from './queries'; import {getLocalTimeZone} from './queries'; -import type {Granularity, TimeGranularity, HourCycle} from './types'; +import type {Granularity, TimeGranularity, HourCycle, DateOrder } from './types'; + + + +/** Valores por defecto compartidos para componentes desacoplados de contexto. */ +export const DEFAULT_TIME_FORMAT: HourCycle = 24; +export const DEFAULT_DATE_ORDER: DateOrder = 'DMY'; + + // ─── Date defaults ──────────────────────────────────────────────────────────── diff --git a/src/lib/glob/lib/date/index.ts b/src/lib/util/dates/index.ts similarity index 95% rename from src/lib/glob/lib/date/index.ts rename to src/lib/util/dates/index.ts index 9c22ad6d0..a42e7e94f 100644 --- a/src/lib/glob/lib/date/index.ts +++ b/src/lib/util/dates/index.ts @@ -30,8 +30,10 @@ export type { TimeGranularity, HourCycle, WeekStartsOn, + DateOrder, } from './types'; + export type { DateValue, TimeValue, @@ -125,6 +127,7 @@ export { parseAbsoluteToLocal, parseZonedDateTime, parseDuration + } from './string'; export {DateFormatter} from './DateFormatter'; export { @@ -138,4 +141,12 @@ export { inferGranularity, inferTimeGranularity, getDefaultHourCycle, + + DEFAULT_TIME_FORMAT, + DEFAULT_DATE_ORDER, } from './defaults'; + + +export { timeFormatToHourCycle } from './utils'; + +export * from './placeholders.ts'; \ No newline at end of file diff --git a/src/lib/glob/lib/date/manipulation.ts b/src/lib/util/dates/manipulation.ts similarity index 100% rename from src/lib/glob/lib/date/manipulation.ts rename to src/lib/util/dates/manipulation.ts diff --git a/src/uix/terra/utils/datetime/placeholders.ts b/src/lib/util/dates/placeholders.ts similarity index 100% rename from src/uix/terra/utils/datetime/placeholders.ts rename to src/lib/util/dates/placeholders.ts diff --git a/src/lib/glob/lib/date/queries.ts b/src/lib/util/dates/queries.ts similarity index 100% rename from src/lib/glob/lib/date/queries.ts rename to src/lib/util/dates/queries.ts diff --git a/src/lib/glob/lib/date/string.ts b/src/lib/util/dates/string.ts similarity index 100% rename from src/lib/glob/lib/date/string.ts rename to src/lib/util/dates/string.ts diff --git a/src/lib/glob/lib/date/types.ts b/src/lib/util/dates/types.ts similarity index 94% rename from src/lib/glob/lib/date/types.ts rename to src/lib/util/dates/types.ts index f31b716d0..0613b3a7c 100644 --- a/src/lib/glob/lib/date/types.ts +++ b/src/lib/util/dates/types.ts @@ -150,6 +150,14 @@ export interface CycleOptions { round?: boolean } + +/** + * Hour cycle for time display. + * - `12` — 12-hour clock (AM/PM) + * - `24` — 24-hour clock + */ +export type HourCycle = 12 | 24; + export interface CycleTimeOptions extends CycleOptions { /** * Whether to use 12 or 24 hour time. If 12 hour time is chosen, the resulting value @@ -157,9 +165,26 @@ export interface CycleTimeOptions extends CycleOptions { * the resulting value also be AM). * @default 24 */ - hourCycle?: 12 | 24 + hourCycle?: HourCycle } + + +/** + * Nivel de detalle en el formateo de fecha u hora. + * Mapea directamente a los valores que acepta `Intl.DateTimeFormat`. + */ +export type DateStyleType = 'short' | 'medium' | 'long' | 'full'; + + +/** Orden preferido de los componentes de fecha (informativo para la UI). */ +export type DateOrder = 'DMY' | 'MDY' | 'YMD'; + + + + + + // ─── Domain types ───────────────────────────────────────────────────────────── /** @@ -171,12 +196,7 @@ export type Granularity = 'day' | 'hour' | 'minute' | 'second'; /** Time-only granularity (subset of Granularity). */ export type TimeGranularity = 'hour' | 'minute' | 'second'; -/** - * Hour cycle for time display. - * - `12` — 12-hour clock (AM/PM) - * - `24` — 24-hour clock - */ -export type HourCycle = 12 | 24; + /** * Day of the week that the calendar week starts on. diff --git a/src/lib/util/dates/utils.ts b/src/lib/util/dates/utils.ts new file mode 100644 index 000000000..477515ac5 --- /dev/null +++ b/src/lib/util/dates/utils.ts @@ -0,0 +1,11 @@ + +import type { HourCycle } from '$lib/util/dates/types'; + + + + + +/** Convierte la preferencia de usuario `DatiTimeFormat` al `HourCycle` numérico de `Intl`. */ +export function timeFormatToHourCycle(fmt: HourCycle): HourCycle { + return fmt === 12 ? 12 : 24; +} diff --git a/src/lib/glob/lib/date/weekStartData.ts b/src/lib/util/dates/weekStartData.ts similarity index 100% rename from src/lib/glob/lib/date/weekStartData.ts rename to src/lib/util/dates/weekStartData.ts diff --git a/src/lib/util/funcs/index.ts b/src/lib/util/funcs/index.ts new file mode 100644 index 000000000..ad0878695 --- /dev/null +++ b/src/lib/util/funcs/index.ts @@ -0,0 +1 @@ +export * from './noop.ts'; \ No newline at end of file diff --git a/src/uix/terra/utils/noop.ts b/src/lib/util/funcs/noop.ts similarity index 100% rename from src/uix/terra/utils/noop.ts rename to src/lib/util/funcs/noop.ts diff --git a/src/lib/util/objs/index.ts b/src/lib/util/objs/index.ts new file mode 100644 index 000000000..eabb21217 --- /dev/null +++ b/src/lib/util/objs/index.ts @@ -0,0 +1,4 @@ + + +export * from './utilities'; + diff --git a/src/lib/glob/lib/date/utils.ts b/src/lib/util/objs/utilities.ts similarity index 84% rename from src/lib/glob/lib/date/utils.ts rename to src/lib/util/objs/utilities.ts index 94f74cbb4..69bb37388 100644 --- a/src/lib/glob/lib/date/utils.ts +++ b/src/lib/util/objs/utilities.ts @@ -10,10 +10,9 @@ * governing permissions and limitations under the License. */ +import type { HourCycle } from '$lib/util/dates/types'; + export type Mutable = { -readonly[P in keyof T]: T[P] }; -export function mod(amount: number, numerator: number): number { - return amount - numerator * Math.floor(amount / numerator); -} diff --git a/src/lib/util/timers/debounce.ts b/src/lib/util/timers/debounce.ts new file mode 100644 index 000000000..c63aaf409 --- /dev/null +++ b/src/lib/util/timers/debounce.ts @@ -0,0 +1,2 @@ +// debounce.ts + diff --git a/src/lib/util/timers/index.ts b/src/lib/util/timers/index.ts new file mode 100644 index 000000000..c591497b7 --- /dev/null +++ b/src/lib/util/timers/index.ts @@ -0,0 +1,2 @@ +// index.ts + diff --git a/src/routes/test/calendar/+page.svelte b/src/routes/test/calendar/+page.svelte index e266a23d4..8d2817c70 100644 --- a/src/routes/test/calendar/+page.svelte +++ b/src/routes/test/calendar/+page.svelte @@ -1,8 +1,8 @@ + +
+
+

acel · date-picker

+

DatePicker

-

Demo para probar picker simple con `locale`, `dateOrder` y herencia vía `AcelConfig`.

+ +

Demo para probar picker simple con `locale`, `dateOrder` y herencia vía `TerraConfig`.

+
+ +
+
+ Locale + {#each LOCALES as option} + + {/each} +
+
+ Date order + {#each ORDERS as order} + + {/each} +
+
+ +
+
+

Básico

+ + Fecha +
+ + {#snippet children({ segments })} + {#each segments as { part, value }} + {value} + {/each} + {/snippet} + + 📅 +
+ + + {#snippet children({ months, weekdays })} + + ‹ + + › + + {#each months as month} + + + + {#each weekdays as day} + {day} + {/each} + + + + {#each month.weeks as week} + + {#each week as date} + + + + {/each} + + {/each} + + + {/each} + {/snippet} + + +
+
{fmt(value1)}
+
+ +
+

Dos meses

+ + Fecha extendida +
+ + {#snippet children({ segments })} + {#each segments as { part, value }} + {value} + {/each} + {/snippet} + + 📅 +
+ + + {#snippet children({ months, weekdays })} +
+ {#each months as month, i} +
+
+ {#if i === 0} + � + {:else} + + {/if} + + {#if i === months.length - 1} + � + {:else} + + {/if} +
+ + + + {#each weekdays as day} + {day} + {/each} + + + + {#each month.weeks as week} + + {#each week as date} + + + + {/each} + + {/each} + + +
+ {/each} +
+ {/snippet} +
+
+
+
{fmt(value2)}
+
+ +
-

Vía AcelConfig

- + +

Vía TerraConfig

+ + + + Fecha heredada +
+ + {#snippet children({ segments })} + {#each segments as { part, value }} + {value} + {/each} + {/snippet} + + 📅 +
+ + + {#snippet children({ months, weekdays })} + + � + + � + + {#each months as month} + + + + {#each weekdays as day} + {day} + {/each} + + + + {#each month.weeks as week} + + {#each week as date} + + + + {/each} + + {/each} + + + {/each} + {/snippet} + + +
-
+ + +
{fmt(value3)}
+
+
+
+ + + + diff --git a/src/routes/test/date-range-field/+page.svelte b/src/routes/test/date-range-field/+page.svelte index dd15764ff..8f230bda6 100644 --- a/src/routes/test/date-range-field/+page.svelte +++ b/src/routes/test/date-range-field/+page.svelte @@ -2,11 +2,11 @@ import { TerraConfig, DateRangeField } from '$uix/terra'; - import type { DatiDateOrder, DatiTimeFormat } from '$lib/glob/lib'; + import type { DateOrder, HourCycle } from '$lib/util/dates'; - import type { DateValue } from '$lib/glob/lib/date'; + import type { DateValue } from '$lib/util/dates'; - import { today, getLocalTimeZone, CalendarDate } from '$lib/glob/lib/date'; + import { today, getLocalTimeZone, CalendarDate } from '$lib/util/dates'; @@ -38,13 +38,13 @@ let locale = $state('es-ES'); - const DATE_ORDERS: DatiDateOrder[] = ['DMY', 'MDY', 'YMD']; + const DATE_ORDERS: DateOrder[] = ['DMY', 'MDY', 'YMD']; - const TIME_FORMATS: DatiTimeFormat[] = ['24h', '12h']; + const TIME_FORMATS: HourCycle[] = [24, 12]; - let dateOrder = $state('DMY'); + let dateOrder = $state('DMY'); - let timeFormat = $state('24h'); + let timeFormat = $state(24); @@ -208,7 +208,7 @@ onclick={() => (timeFormat = format)} - >{format} + >{format === 24 ? '24h' : '12h'} {/each} diff --git a/src/routes/test/date-range-picker/+page.svelte b/src/routes/test/date-range-picker/+page.svelte index 3f03d87a9..5219898e2 100644 --- a/src/routes/test/date-range-picker/+page.svelte +++ b/src/routes/test/date-range-picker/+page.svelte @@ -1,7 +1,7 @@