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