bulletproof-react icon indicating copy to clipboard operation
bulletproof-react copied to clipboard

Why we need to use number for createdAt in BaseEntity class

Open galih56 opened this issue 10 months ago • 3 comments

Why we use number instead of Date Object or Datetime string? Any explaination on this?

Thank you

galih56 avatar Apr 09 '24 08:04 galih56

hey @galih56

This was because the dates are stored as timestamps, which are numbers instead of dates. Both options are valid, it would be up to the API implementation how to implement it.

alan2207 avatar Apr 09 '24 19:04 alan2207

If I want to use a Datetime string to serve dates from an endpoint, do I have to convert the dates into Date Objects for every fetch? For now, I have to make a converter that I use in the axios interceptor to convert the dates for every HTTP request, whether it's a POST, GET, PUT, or DELETE request. But I'm still curious to ask this question.

galih56 avatar Apr 15 '24 01:04 galih56

If you really want dates as date objects, consider treating them that way at the API level, so you don't do any conversion on the FE.

But if you don't control the API data and really want it, then transforming the response makes sense. In that case, you can also consider using zod for transforming and validating your responses.

alan2207 avatar Apr 16 '24 06:04 alan2207