battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programming a forum for elite programmers with extreme will power to sharpen their skills
HomeGallerySearchRegisterLog in

 [java] time gate

Go down 

Posts : 293
Join date : 2012-04-17

[java] time gate Empty
PostSubject: [java] time gate   [java] time gate EmptyThu Mar 19, 2020 5:51 am

a Boolean gate that only opens x minutes after being closed What a Face

import java.util.Calendar;
import java.util.Date;

public class TimeGate {
   // a gate that only opens x minutes after it has been set
   private int pause = 1;
   private Date openedGate = addMinutesToJavaUtilDate(new Date(), pause);

   public TimeGate(int minutes) {
      this.pause = minutes;
   public TimeGate() {
   public Boolean isClosed() {
      return !openedGate.before(new Date());
   public void close() {
      this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
   public void close(int minutes) {
      Date now = new Date();
      openedGate = addMinutesToJavaUtilDate(now, minutes);
   private Date addMinutesToJavaUtilDate(Date date, int minutes) {
       Calendar calendar = Calendar.getInstance();
       calendar.add(Calendar.MINUTE, minutes);
       return calendar.getTime();
   public void setPause(int pause) {
      if(pause <60 && pause >0) {
      this.pause = pause;}

cool pepe
Back to top Go down
[java] time gate
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: