write function that takes timestamp, parses it and returns date as a string in…
- User
write function that takes timestamp, parses it and returns date as a string in YYYY-MM-DD format in JS with TS types
Assistant
Here is a function that parses a timestamp and returns a date string in YYYY-MM-DD format with TypeScript types:
interface DateObject { year: number; month: number; day: number; } function parseTimestamp(timestamp: number): string { const date = new Date(timestamp); const dateObject: DateObject = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() }; return `${dateObject.year}-${padTo2Digits(dateObject.month)}-${padTo2Digits(dateObject.day)}`; } function padTo2Digits(num: number): string { return num.toString().padStart(2, '0'); }Explanation:
- Accept a timestamp (number) as input
- Create a Date object from the timestamp
- Extract year, month and day into a DateObject interface
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.