Saturday, 15 March 2014

javascript - What is the proper way to store an expiration date/timestamp? -



javascript - What is the proper way to store an expiration date/timestamp? -

i'm setting scheme needs have posts expire, , need compare 2 determine if it's expired. i'm using meteor can on clientside or serverside (i'm assuming latter preferred).

looking mdn, i'm not quite sure how store timestamps , format use. seems naive way utilize date.now() current time , add together 30 days in ms expired timestamp. there improve way this?

postmodel = { id: string createdon: date.now() expireson: date.now() + 2592000000 // 30days } post = getpost() if (post.expires after now) { // throw expired error }

you should store expiration time span and not actual date in configurable manner. can configuration file or database or other persistence mechanism. business entity need store creation time only. way expiration can calculated on either client or server side. hard coding values expiration not idea.

also, should utilize utc instead of local time. plan success!

javascript datetime

No comments:

Post a Comment