public void initCountDown() {

    LocalTime timeCurr = new LocalTime();

    LocalTime timeChosen;

    if (sharedPrefs.getString(TimeOption.TIME_STARTED, null) == null) {
      try {
        timeChosen = new LocalTime(sharedPrefs.getString(TimeOption.TIME_CHOSEN, "00:00:00"));
      } catch (Exception ex) {
        timeChosen = new LocalTime("00:00:00");
      }
    } else {

      int valueDiff =
          new LocalTime().getMillisOfDay()
              - new LocalTime(sharedPrefs.getString(TimeOption.TIME_STARTED, "00:00:00"))
                  .getMillisOfDay();

      int valueChosenInMilis =
          new LocalTime(sharedPrefs.getString(TimeOption.TIME_CHOSEN, "00:00:00")).getMillisOfDay();

      if (valueChosenInMilis > valueDiff) {
        valueDiff = valueChosenInMilis - valueDiff;
      } else {
        valueDiff = 0;
      }

      timeChosen = LocalTime.fromMillisOfDay(valueDiff);
    }

    int period = (timeCurr.getMillisOfDay() + timeChosen.getMillisOfDay());

    period -= timeCurr.getMillisOfDay();

    if (period > 0) {
      LocalTime time = new LocalTime().plusMillis(period);
      txtAlarmDone.setText(time.toString());
      txtAlarmPre.setText(time.minusMinutes(1).toString());
      /**
       * txtAlarmDone.setText("Alarm 1" +
       * DateTimeFormat.forPattern("HH:mm:ss").parseLocalTime(time.toString()).toString());
       * txtAlarmPre.setText("Alarm 2" +
       * DateTimeFormat.forPattern(time.minusMinutes(1).toString()).toString());
       */
    }

    startCountDown(period);
  }
 public void bind(DataBind b, LocalTime value) throws SQLException {
   if (value == null) {
     b.setNull(Types.TIME);
   } else {
     Time sqlTime = new Time(value.getMillisOfDay());
     b.setTime(sqlTime);
   }
 }
Пример #3
0
  @Test
  public void testTimeConverter() {
    String sql = "select current_time as col1 from (values(0))";

    Time sqlTime = sql2o.createQuery(sql).executeScalar(Time.class);
    assertThat(sqlTime, is(notNullValue()));
    assertTrue(sqlTime.getTime() > 0);

    Date date = sql2o.createQuery(sql).executeScalar(Date.class);
    assertThat(date, is(notNullValue()));

    LocalTime jodaTime = sql2o.createQuery(sql).executeScalar(LocalTime.class);
    assertTrue(jodaTime.getMillisOfDay() > 0);
    assertThat(jodaTime.getHourOfDay(), is(equalTo(new LocalTime().getHourOfDay())));
  }
Пример #4
0
 public void setTime(LocalTime time) {
   this.time = (time == null ? null : new java.sql.Time(time.getMillisOfDay()));
 }