// Adjust time to on hour or half hour
 public LocalTime adjustTime(LocalTime time) {
   if (!(time.getMinute() == 0 || time.getMinute() == 30)) {
     if (time.getMinute() > 30) {
       time = time.plusHours(1);
       time = time.withMinute(0);
     } else if (time.getMinute() < 30) {
       time = time.withMinute(30);
     } else {
     }
   }
   return time;
 }
Exemplo n.º 2
0
  static void f2() {
    LocalTime time = LocalTime.of(20, 30);
    int hour = time.getHour(); // 20
    int minute = time.getMinute(); // 30
    time = time.withSecond(6); // 20:30:06
    time = time.plusMinutes(3); // 20:33:06

    System.out.println(hour);
    System.out.println(minute);
    System.out.println(time);
  }
Exemplo n.º 3
0
  @Test
  public void updateTask() throws Exception {
    // update existing task
    Task t = new Task();
    Long id = PermanentUserData.tasks.get(0).getId();
    t.setName("updated");
    t.setRole(new Role(PermanentUserData.tasks.get(0).getRole().getId()));
    given()
        .contentType("application/json")
        .filter(sessionFilter)
        .body(om.writeValueAsString(t))
        .put("/web/" + id.toString())
        .then()
        .statusCode(204);

    // delete it
    given()
        .header(PermanentUserData.tokenHeader)
        .delete("/m/" + PermanentUserData.tasks.get(0).getId())
        .then()
        .statusCode(204);

    // test if is recreated with correct values
    t.setNote("note");
    LocalTime moment = LocalTime.now();
    int minutes = moment.getMinute();
    int hours = moment.getHour();
    t.setTime(moment);
    given()
        .contentType("application/json")
        .header(PermanentUserData.tokenHeader)
        .body(om.writeValueAsString(t))
        .put("/m/" + id.toString())
        .then()
        .statusCode(204);
    try (Connection conn = ds.getConnection();
        PreparedStatement ps = conn.prepareStatement("select * from task where name = ?"); ) {
      ps.setString(1, "updated");
      try (ResultSet rs = ps.executeQuery(); ) {
        rs.next();
        assertThat(rs.getString("name"), equalTo("updated"));
        assertThat(rs.getString("note"), equalTo("note"));
        assertThat(rs.getTime("time").getMinutes(), equalTo(minutes));
        assertThat(rs.getTime("time").getHours(), equalTo(hours));
        // rest was set to default
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getBoolean("important"), equalTo(false));
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getDate("date"), equalTo(null));
        assertThat(rs.getDate("firstDate"), equalTo(null));
      }
    }
  }
  @FXML
  private void saveNewMatch() throws RemoteException {

    if (validateInput()) {

      MatchDTO newMatch = new MatchDTOImpl();
      newMatch.setDuration(_duration);
      Calendar cal = new GregorianCalendar();
      cal.set(
          _localDate.getYear(),
          _localDate.getMonthValue(),
          _localDate.getDayOfMonth(),
          _localTime.getHour(),
          _localTime.getMinute(),
          _localTime.getSecond());
      newMatch.setStart(cal.getTime());

      MatchDTOImpl.SimpleMatchTeamDTO team1 =
          new MatchDTOImpl.SimpleMatchTeamDTO(
              _allTeamsTableView.getSelectionModel().getSelectedItem().getId());
      team1.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team1.setName(_allTeamsTableView.getSelectionModel().getSelectedItem().getName());
      team1.setVersion(_allTeamsTableView.getSelectionModel().getSelectedItem().getVersion());

      MatchDTOImpl.SimpleMatchTeamDTO team2 =
          new MatchDTOImpl.SimpleMatchTeamDTO(
              _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team2.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId());
      team2.setName(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getName());
      team2.setVersion(
          _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getVersion());

      newMatch.setTeam1(team1);
      newMatch.setTeam2(team2);
      newMatch.setTournamentId(_tournament.getId());
      newMatch.setMatchStatus("Planned");

      _tournament.addMatch(newMatch);

      initSuccessAlert();
      // todo fix correct weiterleitung
      if (_newTournament) {
        SportifyGUI.getSharedMainApp().loadNewTournamentView(_tournament, _externalDisplayTeamDTOs);
      } else {
        SportifyGUI.getSharedMainApp().loadEditTournamentForm(_tournament);
      }
    }
  }
Exemplo n.º 5
0
  private static String addOneHourTo(String startTimeString) {
    String endTimeString;
    LocalTime startTime = TimeParser.parse(startTimeString);
    startTime = startTime.plusHours(1);

    String hour = Integer.toString(startTime.getHour());
    Integer minute = startTime.getMinute();

    if (minute < 10) {
      endTimeString = new String(hour + "0" + minute);
    } else {
      endTimeString = new String(hour + minute);
    }

    return endTimeString;
  }
Exemplo n.º 6
0
  private static void useLocalDate() {
    LocalDate date = LocalDate.of(2014, 3, 18);
    int year = date.getYear(); // 2014
    Month month = date.getMonth(); // MARCH
    int day = date.getDayOfMonth(); // 18
    DayOfWeek dow = date.getDayOfWeek(); // TUESDAY
    int len = date.lengthOfMonth(); // 31 (days in March)
    boolean leap = date.isLeapYear(); // false (not a leap year)
    System.out.println(date);

    int y = date.get(ChronoField.YEAR);
    int m = date.get(ChronoField.MONTH_OF_YEAR);
    int d = date.get(ChronoField.DAY_OF_MONTH);

    LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20
    int hour = time.getHour(); // 13
    int minute = time.getMinute(); // 45
    int second = time.getSecond(); // 20
    System.out.println(time);

    LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45
    LocalDateTime dt2 = LocalDateTime.of(date, time);
    LocalDateTime dt3 = date.atTime(13, 45, 20);
    LocalDateTime dt4 = date.atTime(time);
    LocalDateTime dt5 = time.atDate(date);
    System.out.println(dt1);

    LocalDate date1 = dt1.toLocalDate();
    System.out.println(date1);
    LocalTime time1 = dt1.toLocalTime();
    System.out.println(time1);

    Instant instant = Instant.ofEpochSecond(44 * 365 * 86400);
    Instant now = Instant.now();

    Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time);
    Duration d2 = Duration.between(instant, now);
    System.out.println(d1.getSeconds());
    System.out.println(d2.getSeconds());

    Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES);
    System.out.println(threeMinutes);

    JapaneseDate japaneseDate = JapaneseDate.from(date);
    System.out.println(japaneseDate);
  }
Exemplo n.º 7
0
  @Test
  public void testTimerWidgetTriggered() throws Exception {
    Executors.newScheduledThreadPool(1)
        .scheduleAtFixedRate(
            new TimerWorker(holder.userDao, holder.sessionDao), 0, 1000, TimeUnit.MILLISECONDS);

    clientPair.appClient.send("deactivate 1");
    verify(clientPair.appClient.responseMock, timeout(500))
        .channelRead(any(), eq(new ResponseMessage(1, OK)));

    Timer timer = new Timer();
    timer.id = 1;
    timer.x = 1;
    timer.y = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.startValue = "dw 5 1";
    timer.stopValue = "dw 5 0";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    long curTime =
        localDateTime.getSecond() + localDateTime.getMinute() * 60 + localDateTime.getHour() * 3600;
    timer.startTime = curTime + 1;
    timer.stopTime = curTime + 2;

    DashBoard dashBoard = new DashBoard();
    dashBoard.id = 1;
    dashBoard.name = "Test";
    dashBoard.widgets = new Widget[] {timer};

    clientPair.appClient.send("saveDash " + dashBoard.toString());
    verify(clientPair.appClient.responseMock, timeout(500))
        .channelRead(any(), eq(new ResponseMessage(2, OK)));

    clientPair.appClient.send("activate 1");
    verify(clientPair.appClient.responseMock, timeout(500))
        .channelRead(any(), eq(new ResponseMessage(3, OK)));

    verify(clientPair.hardwareClient.responseMock, timeout(2000))
        .channelRead(any(), eq(produce(7777, HARDWARE, "dw 5 1")));
    clientPair.hardwareClient.reset();
    verify(clientPair.hardwareClient.responseMock, timeout(2000))
        .channelRead(any(), eq(produce(7777, HARDWARE, "dw 5 0")));
  }
 public void setObject(ExecutionContext ec, PreparedStatement ps, int[] exprIndex, Object value) {
   if (value == null) {
     getDatastoreMapping(0).setObject(ps, exprIndex[0], null);
   } else if (datastoreMappings != null
       && datastoreMappings.length > 0
       && datastoreMappings[0].isStringBased()) {
     TypeConverter conv =
         ec.getNucleusContext()
             .getTypeManager()
             .getTypeConverterForType(LocalTime.class, String.class);
     if (conv != null) {
       Object obj = conv.toDatastoreType(value);
       getDatastoreMapping(0).setObject(ps, exprIndex[0], obj);
     } else {
       throw new NucleusUserException("This type doesn't support persistence as a String");
     }
   } else {
     LocalTime val = (LocalTime) value;
     Calendar cal = Calendar.getInstance();
     cal.set(0, 0, 0, val.getHour(), val.getMinute(), val.getSecond());
     getDatastoreMapping(0).setObject(ps, exprIndex[0], cal);
   }
 }
Exemplo n.º 9
0
 // -----------------------------------------------------------------------
 private void check(LocalTime time, int h, int m, int s, int n) {
   assertEquals(time.getHour(), h);
   assertEquals(time.getMinute(), m);
   assertEquals(time.getSecond(), s);
   assertEquals(time.getNano(), n);
 }
Exemplo n.º 10
0
 /** @param time Zeit */
 public void setValue(final LocalTime time) {
   hoursTextField.setText(getTwoDigitValue(time.getHour()));
   minutesTextField.setText(getTwoDigitValue(time.getMinute()));
   secondsTextField.setText(getTwoDigitValue(time.getSecond()));
 }
Exemplo n.º 11
0
  public static int getMinute(Time time) {
    LocalTime localTime = time.toLocalTime();

    return localTime.getMinute();
  }