To run the app, simply run npm i && npm run dev
then navigate to http://localhost:5173/refund.
I've left some comments in the code where I've made some assumptions or where I've kept the logic simple for the purpose of this test. Here's a list of the same thoughts:
-
Date helper library: There were many options to choose from here, such as moment, luxon, dayjs, date-fns, etc. I've used moment in the past, then luxon when it seemed the better choice. I've picked date-fns for this test because it seemed to offer better TypeScript support, but if I had more time, I'd probably give the other libraries a shot too.
-
Displaying dates: In the front end, dates are displayed in UTC and passed through a simple function that humanises the timestamp. This is a simple approach that allowed me to make sense of all the different time-zoned dates. Obviously, in a real-life scenario, the behavior might differ, and they would perhaps be displayed in the end user's time zone. Furthermore, in the original data, some of the dates included a related column with the time (hours). I've merged these into a single column for simplicity.
-
Determining whether a particular day is a business day or not: For simplicity, I'm considering any day that is not a Saturday or a Sunday a business day. I am not taking into account any holidays. The logic could be improved here but felt outside the scope of this test.
-
Determining whether a particular time is within business hours or not: For simplicity, I'm checking that a particular time is after 9 AM and before 5 PM UK time. Theoretically, a request made at precisely 9 AM and 0 milliseconds would not be considered after 9 AM.
-
Determining the precise moment the new TOS came into effect: The test indicated that users who had signed up after 2/1/2020 (EU format) would get the new TOS. By "after", I'm assuming they came into effect at midnight on 3/1. I'm also making the assumption that rather than being midnight in the UK, it would be midnight in the user's timezone. This is just an assumption that I've made and can be easily changed if needs be.
-
The region/timezone data column: I did not want to tamper with the original data, so for the purpose of this test, all I did was convert the markdown table into a JSON equivalent, leaving the data untouched. It made sense to internally split the region/timezone column into two separate values. I doubt that data would be returned in this fashion in a real scenario, but for the purpose of this test, I wrote a simple regex to match the two values.
-
Error handling: Errors could be handled more gracefully in a couple of places, but in a real scenario, I would probably take care of this with a stricter validation layer at the API level.