-3

right now i created a project and one of the features is daily-check in. with this I got into some difficulties. The case is - i want the user to do daily check in.That means, after a check in, The user must wait until tomorrow to do the daily check-in again. how should i implements this and how should the validation work?

I already found the solution in google but couldn't get it to work.

I also already tested using a scheduler. It works but i think this is not the best practice i can get here, so if someone has a solution, I'd love to hear.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

2 Answers2

0

Not really sure if this is the best solution, but here is how I would solve this.

Under your Users/user-id, add a field called 'lastCheckinTime'.

When the user is checking in, first call the lastCheckinTime and see if it <24hrs, if not only then let the user checkin.

Then on writing the new check-in operation, update the lastCheckinTime with the latest timestamp. Hope it answers your question.

0

I would just keep an instance of the last day the user checked in regardless the time it happened..

And so you could just check if at a particular date a check in has occurred or not.

Use -

String currentDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());

to get the current date parameter and then do the check as followed -

if(currentDate.after(lastCheckInDate)){
            //your check in method here
        }
Itay Feldman
  • 846
  • 10
  • 23