-1

In my app i want a feature where the user can update their status but i want them to only be able to update it once every 24 hours. Basically i want to take the updatedAt field from parse and check if the change was today in Cloud Code.

I am not very familiar with javascript but her's what i've tried: https://www.parse.com/questions/compare-date-and-createdat-to-figure-out-the-difference-in-days How to compare 2 Date fields in Parse Cloud?

I couldn't get to a solution that would basically tell me (beforeSave) if the date is today and allow the user to save/update the field if it isn't.

An example of what i want is WhatsApp that only allowed changing the last seen status on/off once every 24 hours. Also Viber has this feature.

Thanks.

Community
  • 1
  • 1
Sam Bing
  • 2,794
  • 1
  • 19
  • 29

1 Answers1

1

Parse.com supports moment.js

var updatedAt = ... ; // Get updatedAt value of your object
var now = moment();

if (now.diff(updatedAt, 'hours') >= 24) {
    // Last update was more than 24 hours ago
}
Shai
  • 25,159
  • 9
  • 44
  • 67
  • Can i do the same with NSDate? Pass NSDate to cloud code and compare it the same way? – Sam Bing Nov 29 '15 at 12:17
  • Yes you can, Parse will convert the date for you. – hhanesand Nov 30 '15 at 09:36
  • Thanks. I'll give it a shot. –  Nov 30 '15 at 09:40
  • I've used console log to check what the dates are and i am getting these : I2015-11-30T10:42:26.880Z]User Can't Post I2015-11-30T10:42:26.881Z]2015-12-01T11:12:28.804Z I2015-11-30T10:42:26.882Z]{"_d":"2015-11-30T10:42:26.877Z","_isUTC":false,"_a":null,"_lang":false} Even though the date is past 24 hours it still wont let the user post. Am i missing something? – Sam Bing Nov 30 '15 at 10:50