MCPcopy Index your code
hub / github.com/bombshell-dev/clack / detectLocaleFormat

Function detectLocaleFormat

packages/core/src/prompts/date.ts:28–45  ·  view source on GitHub ↗
(locale?: string)

Source from the content-addressed store, hash-verified

26}
27
28function detectLocaleFormat(locale?: string): { segments: SegmentConfig[]; separator: string } {
29 const fmt = new Intl.DateTimeFormat(locale, {
30 year: 'numeric',
31 month: '2-digit',
32 day: '2-digit',
33 });
34 const parts = fmt.formatToParts(new Date(2000, 0, 15));
35 const segments: SegmentConfig[] = [];
36 let separator = '/';
37 for (const p of parts) {
38 if (p.type === 'literal') {
39 separator = p.value.trim() || p.value;
40 } else if (p.type === 'year' || p.type === 'month' || p.type === 'day') {
41 segments.push({ type: p.type, len: p.type === 'year' ? 4 : 2 });
42 }
43 }
44 return { segments, separator };
45}
46
47/** Parse string segment values to numbers, treating blanks as 0 */
48function parseSegmentToNum(s: string): number {

Callers 1

constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected