mercredi 24 juillet 2019

Storing Date Components Instead of a Date

My app lets people log the movies they see (for example). Each logged movie usually (but not always) has a date and sometimes has a time. It's not unusual to have one but not the other. Occasionally the dates are only a year ("I watched a Dumbo sometime in 1984"), but could realistically be any combination of day/month/year/time.

I am used to modeling dates as date objects in my app and my backend. But is it a viable approach to store each component separately? When I need to reference an actual date from the components (e.g. for sorting the log) this will be built client-side, or perhaps be stored as a derived property sortDate and updated whenever any of the components change.

What are the limitations and/or pitfalls of this approach? Does anyone have experience modeling their dates this way?

If it's of any consequence, my app is for iOS written in Swift and uses a Parse Server backend.

Aucun commentaire:

Enregistrer un commentaire