Add trains endpoint handler
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
This commit is contained in:
20
src/lib/helpers.ts
Normal file
20
src/lib/helpers.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Normalises input to YYYY-MM-DD string
|
||||
* - Strings are passed through as is
|
||||
* - Date objects are converted to UK time
|
||||
*/
|
||||
export const ensureDateString = (input: Date | string): string => {
|
||||
if (typeof input === 'string') return input.trim();
|
||||
|
||||
const d = new Intl.DateTimeFormat('en-GB', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
timeZone: 'Europe/London'
|
||||
}).formatToParts(input);
|
||||
|
||||
const part = (type: string) => d.find(p => p.type === type)?.value;
|
||||
|
||||
return `${part('year')}-${part('month')}-${part('day')}`
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user