So I want to specify a time after which a post gets deleted. The time is 3 months, in my code I would define this as
const THREE_MONTHS_IN_MS = 7889400000
export const TIME_AFTER_WHICH_USER_IS_DELETED = THREE_MONTHS_IN_MS
How can I define this in my database without resorting to the use of a magic number? Basically it looks like this right now:
timeAfterWhichUserIsDeleted: 7889400000
Or as a direct screenshot of the database: https://gyazo.com/67abfdc329e1e36aae4e66b0da4b4f75
I would like to avoid this value in the database and instead have it be more readable.
Any tips or suggestions?
The
7889400000is a UNIX timestamp, indicating a number of milliseconds since the epic. While you can store a value indicating the same moment in a different format, you'll want to make sure that the format you use still allows you to query the value.A common format that is both readable and queryable it ISO-8859-1, and my current time in that format would be
2022-03-22 06:50:48.I noticed after re-reading your question that your
timeAfterWhichUserIsDeletedis actually an interval and not a moment. If the interval is always going to be in months, you could storecountOfMonthsAfterWhichUserIsDeleted: 3as a more readable form of the same intent. Just note that3is equally magic as7889400000and the main difference is that I've named the field more meaningfully.