title: How to enable certain functions only for a specific period of time in apps?
body: <p>I am working on a Booking App ,where there are different time slots in a day(for example 11:30,12:30) in which users can book their ride.But I don't want the booking option to be open for the whole day,it should just be open from a certain time until the next day.I've heard this can be done by cloud functions,if so ,can anyone tell me how? </p>
  
  <p>This is my BookingActivity.java</p>
  
  <pre><code>public class BookingActivity extends AppCompatActivity {
  
  private DatabaseReference mUser;
  private DatabaseReference mTime1;
  private DatabaseReference mTime2;
  private DatabaseReference mCount1;
  private DatabaseReference mCount2;
  private FirebaseAuth mAuth;
  private static final String TAG = "BookingActivity";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_booking);
  
  mAuth = FirebaseAuth.getInstance();
  
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  FirebaseUser fu = mAuth.getCurrentUser();
  final User newUser = new User(fu);
  
  mUser = FirebaseDatabase.getInstance().getReference().child("Users");
  mTime1 = FirebaseDatabase.getInstance().getReference().child("3:30");
  mTime2 = FirebaseDatabase.getInstance().getReference().child("5:30");
  mCount1 = FirebaseDatabase.getInstance().getReference().child("Count@3:30");
  mCount2 = FirebaseDatabase.getInstance().getReference().child("Count@5:30");
  
  findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          Update(mTime1,mCount1,newUser);
  
      }
  });
  
  findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          Update(mTime2,mCount2,newUser);
      }
  });
  
  }
  
  
  public void Book(DatabaseReference mDatabase,User user) {
  
  Long tsLong = System.currentTimeMillis()/1000;
  String ts = tsLong.toString();
  
  HashMap&lt;String,String&gt;datamap = new HashMap&lt;&gt;();
  
  if(user!=null) {
      datamap.put("Name", user.getUserName());
      datamap.put("Email", user.getUserEmail());
      datamap.put("timestamp",ts);
      datamap.put("Limit", user.setRating("1"));
  }
  
   mDatabase.push().setValue(datamap);
  
  }
  
  public void Update(final DatabaseReference mDatabase, DatabaseReference mref,final User user) {
  
      mref.runTransaction(new Transaction.Handler() {
      @NonNull
      @Override
      public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
  
          Integer CurrentValue = mutableData.getValue(Integer.class);
          if(CurrentValue==null) {
              return Transaction.success(mutableData);
          }
          else if(CurrentValue&lt;5 &amp;&amp; user.getRating().equals("0")){
              mutableData.setValue(CurrentValue + 1);
              Book(mDatabase,user);
              runOnUiThread(new Runnable() {
                  public void run() {
                      final Toast toast = Toast.makeText(BookingActivity.this,"Booked Successfully",Toast.LENGTH_SHORT);
                      toast.show();
                  }
              });
           }
           else{
              runOnUiThread(new Runnable() {
                  public void run() {
                      final Toast toast = Toast.makeText(BookingActivity.this,"Maximum Limit Reached",Toast.LENGTH_SHORT);
                      toast.show();
                  }
              });
          }
          return Transaction.success(mutableData);
  
      }
  
      @Override
      public void onComplete(@Nullable DatabaseError databaseError, boolean b, @Nullable DataSnapshot dataSnapshot) {
  
          Log.d(TAG, "Updating likes count transaction is completed");
  
      }
  });
  }
  
  
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
  
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu, menu);
  
  return true;
  }
  
  public boolean onOptionsItemSelected(MenuItem item) {
  
  switch (item.getItemId()) {
      case R.id.menuLogout:
  
          FirebaseAuth.getInstance().signOut();
          finish();
          startActivity(new Intent(this, MainActivity.class));
  
          break;
  }
  
  return true;
  }
  </code></pre>
  
  <p>My database structure looks like this
  <a href="https://i.stack.imgur.com/wbVVD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wbVVD.png" alt="enter image description here"></a></p>