Example #1
0
 @Test
 public void testCalendar2Timestamp() {
   Calendar calendar = Calendar.getInstance();
   calendar.setTimeInMillis(time);
   Time sqltime = sqlTimeConverter.convert(calendar);
   assertEquals(time, sqltime.getTime());
 }
Example #2
0
  @Test
  public void timestamp() throws SQLException {
    connectWithJulianDayModeActivated();
    long now = System.currentTimeMillis();
    Timestamp d1 = new Timestamp(now);
    Date d2 = new Date(now);
    Time d3 = new Time(now);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTimestamp(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1, rs.getTimestamp(1));

    rs = stat.executeQuery("select date(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d2.toString(), rs.getString(1));

    rs = stat.executeQuery("select time(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d3.toString(), rs.getString(1));

    rs = stat.executeQuery("select strftime('%Y-%m-%d %H:%M:%f', c1, 'localtime') from t;");
    assertTrue(rs.next());
    // assertEquals(d1.toString(), rs.getString(1)); // ms are not occurate...
  }
Example #3
0
  private static Time getTime(SQLDialect dialect, ResultSet rs, int index) throws SQLException {

    // SQLite's type affinity needs special care...
    if (dialect == SQLDialect.SQLITE) {
      String time = rs.getString(index);

      if (time != null) {
        return new Time(parse("HH:mm:ss", time));
      }

      return null;
    }

    // Cubrid SQL dates are incorrectly fetched. Reset milliseconds...
    // See http://jira.cubrid.org/browse/APIS-159
    // See https://sourceforge.net/apps/trac/cubridinterface/ticket/140
    else if (dialect == CUBRID) {
      Time time = rs.getTime(index);

      if (time != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(time.getTime());
        cal.set(Calendar.MILLISECOND, 0);
        time = new Time(cal.getTimeInMillis());
      }

      return time;
    } else {
      return rs.getTime(index);
    }
  }
Example #4
0
 @Transient
 private void generateKode() {
   Time time = DateUtil.getTime();
   String kode =
       String.format("%s-%s-%s", operator.hashCode(), tanggalBuat.hashCode(), time.hashCode());
   setKode(kode);
 }
  private List<WebSocketChannelDTO> buildChannelDTOs(ResultSet rs) throws SQLException {
    ArrayList<WebSocketChannelDTO> channels = new ArrayList<>();
    try {
      while (rs.next()) {
        WebSocketChannelDTO channel = new WebSocketChannelDTO();
        channel.id = rs.getInt("channel_id");
        channel.host = rs.getString("host");
        channel.port = rs.getInt("port");
        channel.url = rs.getString("url");
        channel.startTimestamp = rs.getTimestamp("start_timestamp").getTime();

        Time endTs = rs.getTime("end_timestamp");
        channel.endTimestamp = (endTs != null) ? endTs.getTime() : null;

        channel.historyId = rs.getInt("history_id");

        channels.add(channel);
      }
    } finally {
      rs.close();
    }

    channels.trimToSize();

    return channels;
  }
Example #6
0
  public static int calculate(Time awal, Time akhir) {
    Long millis3 = (akhir.getTime() - awal.getTime());
    Long hasil = millis3 / HOUR_IN_MILIS;

    if (millis3 % HOUR_IN_MILIS > 0) hasil++;

    return hasil.intValue();
  }
 @Nullable
 @Override
 public OffsetTime getValue(ResultSet rs, int startIndex) throws SQLException {
   Time time = rs.getTime(startIndex, utc());
   return time != null
       ? OffsetTime.ofInstant(Instant.ofEpochMilli(time.getTime()), ZoneOffset.UTC)
       : null;
 }
 private static Time toTime(Object obj) throws HproseException {
   if (obj instanceof DateTime) {
     return ((DateTime) obj).toTime();
   }
   if (obj instanceof char[]) {
     return Time.valueOf(new String((char[]) obj));
   }
   return Time.valueOf(obj.toString());
 }
Example #9
0
  public static Long toEpochFormat(String mdate, int hour, int minute) throws ParseException {
    Date date = new Date(mdate);
    Time time = new Time(hour + 7, minute, 0);

    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);
    calendar.add(Calendar.MILLISECOND, (int) time.getTime());
    return calendar.getTime().getTime();
  }
 public Time getTimeModificado(Time time, int min) {
   Calendar calendar = Calendar.getInstance();
   int year = calendar.get(Calendar.YEAR);
   int month = calendar.get(Calendar.MONTH);
   int day = calendar.get(Calendar.DAY_OF_MONTH);
   calendar.set(year, month, day, time.getHours(), time.getMinutes(), time.getSeconds());
   calendar.add(Calendar.MINUTE, min);
   Time time_modificado = new Time(calendar.getTimeInMillis());
   return time_modificado;
 }
Example #11
0
  public void test(TestHarness harness) {
    Time t = new Time(0);

    try {
      t.getDate();
      harness.check(false, "getDate");
    } catch (IllegalArgumentException e) {
      harness.check(true, "getDate");
    }

    try {
      t.getDay();
      harness.check(false, "getDay");
    } catch (IllegalArgumentException e) {
      harness.check(true, "getDay");
    }

    try {
      t.getMonth();
      harness.check(false, "getMonth");
    } catch (IllegalArgumentException e) {
      harness.check(true, "getMonth");
    }

    try {
      t.getYear();
      harness.check(false, "getYear");
    } catch (IllegalArgumentException e) {
      harness.check(true, "getYear");
    }

    try {
      t.setDate(0);
      harness.check(false, "setDate");
    } catch (IllegalArgumentException e) {
      harness.check(true, "setDate");
    }

    try {
      t.setMonth(0);
      harness.check(false, "setMonth");
    } catch (IllegalArgumentException e) {
      harness.check(true, "setMonth");
    }

    try {
      t.setYear(0);
      harness.check(false, "setYear");
    } catch (IllegalArgumentException e) {
      harness.check(true, "setYear");
    }

    try {
      Time.valueOf("NoSuchTime");
      harness.check(false, "valueOf");
    } catch (IllegalArgumentException e) {
      harness.check(true, "valueOf");
    }
  }
 @Override
 public WorkTime getNewTransientObject(int i) {
   WorkTime workTime = new WorkTime();
   workTime.setEmployee(employeeDataOnDemand.getRandomObject());
   workTime.setProject(projectDataOnDemand.getRandomObject());
   workTime.setDate(new Date());
   workTime.setStartTime(Time.valueOf("09:00:00"));
   workTime.setEndTime(Time.valueOf("17:00:00"));
   workTime.setComment("comment_" + i);
   return workTime;
 }
Example #13
0
    public static IRubyObject prepareRubyTimeFromSqlTime(Ruby runtime, Time time) {

        if (time.getTime() + 3600000 == 0) {
            return runtime.getNil();
        }

        RubyTime rbTime = RubyTime.newTime(runtime, time.getTime());
        rbTime.extend(new IRubyObject[]{runtime.getModule("TimeFormatter")});
        return rbTime;
        // SimpleDateFormat sdf = new SimpleDateFormat("HH-mm-ss"); // TODO proper format?
        // return runtime.newString(sdf.format(rbTime.getJavaDate()));
    }
Example #14
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())));
  }
    /** {@inheritDoc} */
    @SuppressWarnings("EqualsHashCodeCalledOnUrl")
    @Override
    public int hashCode() {
      int res = id;

      res = 31 * res + (boolVal != null ? boolVal.hashCode() : 0);
      res = 31 * res + (byteVal != null ? byteVal.hashCode() : 0);
      res = 31 * res + (shortVal != null ? shortVal.hashCode() : 0);
      res = 31 * res + (intVal != null ? intVal.hashCode() : 0);
      res = 31 * res + (longVal != null ? longVal.hashCode() : 0);
      res = 31 * res + (floatVal != null ? floatVal.hashCode() : 0);
      res = 31 * res + (doubleVal != null ? doubleVal.hashCode() : 0);
      res = 31 * res + (bigVal != null ? bigVal.hashCode() : 0);
      res = 31 * res + (strVal != null ? strVal.hashCode() : 0);
      res = 31 * res + (arrVal != null ? Arrays.hashCode(arrVal) : 0);
      res = 31 * res + (dateVal != null ? dateVal.hashCode() : 0);
      res = 31 * res + (timeVal != null ? timeVal.hashCode() : 0);
      res = 31 * res + (tsVal != null ? tsVal.hashCode() : 0);
      res = 31 * res + (urlVal != null ? urlVal.hashCode() : 0);
      res = 31 * res + (f1 != null ? f1.hashCode() : 0);
      res = 31 * res + (f2 != null ? f2.hashCode() : 0);
      res = 31 * res + (f3 != null ? f3.hashCode() : 0);

      return res;
    }
Example #16
0
    @Test
    public void testInlinedBindValuesForDatetime() throws Exception {
        jOOQAbstractTest.reset = false;

        Date d1 = Date.valueOf("1981-07-10");
        Time t1 = Time.valueOf("12:01:15");
        Timestamp ts1 = Timestamp.valueOf("1981-07-10 12:01:15");

        Factory create = create(new Settings()
            .withStatementType(StatementType.STATIC_STATEMENT));

        DATE date = create.newRecord(TDates());
        date.setValue(TDates_ID(), 1);
        assertEquals(1, date.store());

        date.setValue(TDates_ID(), 2);
        date.setValue(TDates_D(), d1);
        date.setValue(TDates_T(), t1);
        date.setValue(TDates_TS(), ts1);
        assertEquals(1, date.store());

        Result<Record> dates =
        create.select(TDates_ID(), TDates_D(), TDates_T(), TDates_TS())
              .from(TDates())
              .orderBy(TDates_ID())
              .fetch();

        assertEquals(2, dates.size());
        assertEquals(asList(1, 2), dates.getValues(TDates_ID()));
        assertEquals(asList(1, null, null, null), asList(dates.get(0).intoArray()));
        assertEquals(asList((Object) 2, d1, t1, ts1), asList(dates.get(1).intoArray()));
    }
Example #17
0
 @Override
 public String translateLiteralTime(Time timeValue) {
   if (!hasTimeType()) {
     return translateLiteralTimestamp(new Timestamp(timeValue.getTime()));
   }
   return '\'' + formatDateValue(timeValue) + '\'';
 }
Example #18
0
 private String getTimeSQL(Time time) {
   String s = "'" + time.toString() + "'";
   if (config.getMode() != TestSynth.HSQLDB) {
     s = "TIME " + s;
   }
   return s;
 }
Example #19
0
  private void readNotification(JSONObject root) {
    JSONObject data = (JSONObject) root.get("data");

    Notificacion n = new Notificacion();
    n.setDate(Date.valueOf((String) root.get("date")));
    n.setTime(Time.valueOf((String) root.get("time")));
    n.setIdDevice((String) root.get("idDevice"));
    n.setIdPaciente((Long) data.get("idPaciente"));
    n.setIdContenido((Long) data.get("idPictograma"));
    n.setIdContexto((Long) data.get("idContexto"));

    // TODO si no existe el alumno con id/idDevice de la notificación, guardarlo
    Paciente paciente = new PacienteDAO().getById(n.getIdPaciente(), n.getIdDevice());
    if (paciente == null) {
      paciente =
          new Paciente(
              n.getIdPaciente().intValue(),
              n.getIdDevice(),
              (String) data.get("nombre"),
              (String) data.get("apellido"),
              ((String) data.get("sexo")).charAt(0));
      new PacienteDAO().guardar(paciente);
    }

    ViewManager.getInstance().showNotification(n);
  }
Example #20
0
  public ArrayList<PartidoOctavos> getAdaptadorPartidosOctavos() {
    PartidoOctavos partidoO;
    ArrayList<PartidoOctavos> listaPartidosOctavos = new ArrayList<PartidoOctavos>();
    String sql2 = "SELECT COUNT(idpartidooctavos) FROM partidooctavos";
    String sql =
        "SELECT idpartidooctavos,idoctavos1,pais1,gol1,gol2,pais2,idoctavos2,fecha,hora,estado FROM partidooctavos";

    Cursor c = miDB.rawQuery(sql, null);
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
      partidoO =
          new PartidoOctavos(
              c.getString(0),
              c.getString(1),
              c.getString(2),
              c.getInt(3),
              c.getInt(4),
              c.getString(5),
              c.getString(6),
              Date.valueOf(c.getString(7)),
              Time.valueOf(c.getString(8)),
              c.getInt(9));
      listaPartidosOctavos.add(partidoO);
    }
    return listaPartidosOctavos;
  }
    /** {@inheritDoc} */
    @SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      TestObject that = (TestObject) o;

      if (id != that.id) return false;
      if (!Arrays.equals(arrVal, that.arrVal)) return false;
      if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
      if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
      if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
      if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
      if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null)
        return false;
      if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
      if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
      if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
      if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
      if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
      if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
      if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
      if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
      if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
      if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
      if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;

      return true;
    }
 static final Time read(HproseReader reader, InputStream stream) throws IOException {
   int tag = stream.read();
   switch (tag) {
     case TagDate:
       return DefaultUnserializer.readDateTime(reader, stream).toTime();
     case TagTime:
       return DefaultUnserializer.readTime(reader, stream).toTime();
     case TagNull:
     case TagEmpty:
       return null;
     case TagString:
       return Time.valueOf(StringUnserializer.readString(reader, stream));
     case TagRef:
       return toTime(reader.readRef(stream));
   }
   if (tag >= '0' && tag <= '9') return new Time(tag - '0');
   switch (tag) {
     case TagInteger:
     case TagLong:
       return new Time(ValueReader.readLong(stream));
     case TagDouble:
       return new Time(Double.valueOf(ValueReader.readDouble(stream)).longValue());
     default:
       throw ValueReader.castError(reader.tagToString(tag), Time.class);
   }
 }
 public Object deserialize(String data) {
   try {
     return java.sql.Time.valueOf(data);
   } catch (IllegalArgumentException e) {
     throw new JRRuntimeException("Error parsing Time data \"" + data + "\"", e);
   }
 }
 public void setTime(int parameterIndex, java.sql.Time x) throws SQLException {
   if (parameterIndex < 1 || parameterIndex > args.length) {
     throw new SQLException("bad parameter index");
   }
   if (x == null) {
     args[parameterIndex - 1] = nullrepl ? "" : null;
   } else {
     if (conn.useJulian) {
       args[parameterIndex - 1] =
           java.lang.Double.toString(SQLite.Database.julian_from_long(x.getTime()));
     } else {
       args[parameterIndex - 1] = x.toString();
     }
   }
   blobs[parameterIndex - 1] = false;
 }
Example #25
0
 public ArrayList<Partido> getAdapterPatidosGrupo(String g) {
   ActualizarPosiciones(g);
   Partido partido;
   ArrayList<Partido> lista = new ArrayList<Partido>();
   Toast toast = Toast.makeText(miContexto, "Grupo: " + g, Toast.LENGTH_SHORT);
   toast.show();
   String SQL =
       "SELECT idpartido,pais1,pais2,goles1,goles2,hora,fecha,grupo,estado,recordar FROM partido WHERE grupo='"
           + g
           + "'";
   Cursor c = miDB.rawQuery(SQL, null);
   for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
     partido =
         new Partido(
             c.getInt(0),
             c.getString(1),
             c.getString(2),
             c.getInt(3),
             c.getInt(4),
             Time.valueOf(c.getString(5)),
             Date.valueOf(c.getString(6)),
             c.getString(7),
             c.getInt(8),
             c.getInt(9));
     lista.add(partido);
   }
   return lista;
 }
Example #26
0
  public ArrayList<PartidoCuartos> getAdaptadorPartidosCuartos() {
    PartidoCuartos partidoC;
    ArrayList<PartidoCuartos> lista = new ArrayList<PartidoCuartos>();
    String sql =
        "SELECT idpartidocuartos,idganador1,bandera1,paisganador1,gol1,gol2,bandera2,paisganador2,idganador2,fecha,hora,estado FROM partidocuartos";

    Cursor c = miDB.rawQuery(sql, null);
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
      partidoC =
          new PartidoCuartos(
              c.getString(0),
              c.getString(1),
              c.getInt(2),
              c.getString(3),
              c.getInt(4),
              c.getInt(5),
              c.getInt(6),
              c.getString(7),
              c.getString(8),
              Date.valueOf(c.getString(9)),
              Time.valueOf(c.getString(10)),
              c.getInt(11));
      lista.add(partidoC);
    }
    return lista;
  }
  /** Test of setObject method, of inteface java.sql.CallableStatement. */
  public void testSetObject_TIME() throws Exception {
    println("setObject - TIME");

    setUpDualTable();

    setObjectTest("time", Time.valueOf("1:23:47"), Types.TIME);
  }
Example #28
0
 public ArrayList<Partido> getAdapterPatidosFecha(Date f) {
   Partido partido;
   ArrayList<Partido> lista = new ArrayList<Partido>();
   String SQL =
       "SELECT idpartido,pais1,pais2,goles1,goles2,hora,fecha,grupo,estado,recordar FROM partido WHERE fecha='"
           + f
           + "' AND estado=0";
   Cursor c = miDB.rawQuery(SQL, null);
   for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
     partido =
         new Partido(
             c.getInt(0),
             c.getString(1),
             c.getString(2),
             c.getInt(3),
             c.getInt(4),
             Time.valueOf(c.getString(5)),
             Date.valueOf(c.getString(6)),
             c.getString(7),
             c.getInt(8),
             c.getInt(9));
     lista.add(partido);
   }
   return lista;
 }
Example #29
0
  /**
   * Implement the interface for validating and converting to internal object. Null is a valid
   * successful return, so errors are indicated only by existance or not of a message in the
   * messageBuffer.
   */
  public Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer) {
    // handle null, which is shown as the special string "<null>"
    if (value.equals("<null>") || value.equals("")) return null;

    // Do the conversion into the object in a safe manner
    try {
      if (useJavaDefaultFormat) {
        // allow the user to enter just the hour or just hour and minute
        // and assume the un-entered values are 0
        int firstColon = value.indexOf(":");
        if (firstColon == -1) {
          // user just entered the hour, so append min & sec
          value = value + ":0:0";
        } else {
          // user entered hour an min. See if they also entered secs
          if (value.indexOf(":", firstColon + 1) == -1) {
            // user did not enter seconds
            value = value + ":0";
          }
        }
        Object obj = Time.valueOf(value);
        return obj;
      } else {
        // use the DateFormat to parse
        java.util.Date javaDate = dateFormat.parse(value);
        return new Time(javaDate.getTime());
      }
    } catch (Exception e) {
      messageBuffer.append(e.toString() + "\n");
      // ?? do we need the message also, or is it automatically part of the toString()?
      // messageBuffer.append(e.getMessage());
      return null;
    }
  }
  private void jButton4ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:

    System.out.println(dateNow.toLocalDate());
    System.out.println(timeNow.toLocalTime());
  } // GEN-LAST:event_jButton4ActionPerformed