Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

In this page you can find the example usage for java.sql Time Time.

Prototype

public Time(long time) 

Source Link

Document

Constructs a Time object using a milliseconds time value.

Usage

From source file:TestCalificarEstablecimiento.java

@Test
@Transactional/*from   w  ww  .  jav a  2s  .c o  m*/
@Rollback(true)
public void testCalificarEstablecimientoPrimero() throws OperationFailedException {

    Cliente c1 = new Cliente(456, "Zlatan Ibrahimovic");
    logica.registrarCliente(c1);
    Ensayo es1 = new Ensayo(666, c1, "Ensayo en la sala studio");
    //es1.setCalificacions(new HashSet<Calificacion>());
    logica.registrarEnsayo(es1);
    DetalleInstrumento det = new DetalleInstrumento(1, "Guitarra");
    logica.registrarDetalleInstrumento(det);
    Establecimiento est = new Establecimiento(888, "Abril Records", "123.456.333-1", "calle falsa bla bla",
            new Time(800), new Time(1800), 5.5, "Suba", "44440000", "34556478987987078329");
    logica.registrarEstablecimiento(est);
    Instrumento ins = new Instrumento(111, det, es1, est, "1000");
    logica.registrarInstrumento(ins);

    Calificacion califiN = new Calificacion(es1.getIdEnsayo(), es1, 5, 0,
            "Ensayaron bien y los equipos no sufrieron daos");
    logica.registrarCalificacion(califiN);

    logica.calificarEstablecimiento(c1.getIdCliente(), es1.getIdEnsayo(), 4,
            "Fue muy bueno por que regalaron te, lo recomiendo");
    Ensayo ens = logica.consultarEnsayo(666);

    Calificacion cals = logica.consultarCalificacionDeEnsayo(ens.getIdEnsayo());

    assertEquals(cals.getCalificacionEstablecimiento(), 4);
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Time getTime(java.util.Date date) {
    if (date == null) {
        return currentTime();
    }/*from w w w  .j a v a 2 s  .  co m*/
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    c.set(Calendar.YEAR, 1970);
    c.set(Calendar.MONTH, Calendar.JANUARY);
    c.set(Calendar.DAY_OF_MONTH, 1);
    return new Time(c.getTimeInMillis());
}

From source file:org.eclipse.dirigible.runtime.scripting.utils.DbUtils.java

public Time createTime(long value) {
    return new Time(value);
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

@Override
public Time fromString(Class targetClass, String s) {
    if (s == null) {
        return null;
    }//from   w ww  .  ja v a 2s  .  co  m

    if (StringUtils.isNumeric(s)) {
        return new Time(Long.parseLong(s));
    }
    Time t = Time.valueOf(s);
    return t;
}

From source file:cz.muni.fi.anatomytutor.backend.service.PracticeServiceImpl.java

@Override
public void saveAnswer(AuthUserDto user, QuestionDto answer) {
    Answer answerEntity = new Answer();
    answerEntity.setAuthor(AuthUserConvert.fromDtoToEntity(user));
    Picture picture = new Picture();
    picture.setId(answer.getPictureId());
    picture.setName(answer.getPictureName());
    picture.setSvg(answer.getPictureSvg());
    answerEntity.setQuestionTerm(OptionConvert.fromDtoToEntity(answer.getQuestion(), picture));
    answerEntity.setAnswerTerm(OptionConvert.fromDtoToEntity(answer.getAnswer(), picture));
    Long now = System.currentTimeMillis();
    answerEntity.setAnswerTime(new Time(now));
    answerEntity.setAnswerDate(new Date(now));
    answerDao.create(answerEntity);//from www  .j a  va2s. co  m
}

From source file:com.haulmont.cuba.web.gui.components.WebTimeField.java

public WebTimeField() {
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);

    timeFormat = Datatypes.getFormatStringsNN(uss.getLocale()).getTimeFormat();
    resolution = DateField.Resolution.MIN;

    component = new CubaMaskedTextField();
    component.setMaskedMode(true);/*from   ww w.j  a  v  a2  s .  com*/
    component.setImmediate(true);
    component.setTimeMask(true);
    setShowSeconds(timeFormat.contains("ss"));

    component.setInvalidAllowed(false);
    component.setInvalidCommitted(true);
    component.addValidator(value -> {
        if (!(!(value instanceof String) || checkStringValue((String) value))) {
            component.markAsDirty();
            throw new com.vaadin.data.Validator.InvalidValueException("Unable to parse value: " + value);
        }
    });
    attachListener(component);

    component.setConverter(new Converter<String, Date>() {
        @Override
        public Date convertToModel(String formattedValue, Class<? extends Date> targetType, Locale locale)
                throws ConversionException {
            if (StringUtils.isNotEmpty(formattedValue) && !formattedValue.equals(placeholder)) {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
                    sdf.setLenient(false);

                    Date date = sdf.parse(formattedValue);
                    if (component.getComponentError() != null)
                        component.setComponentError(null);
                    if (targetType == java.sql.Time.class) {
                        return new Time(date.getTime());
                    }
                    if (targetType == java.sql.Date.class) {
                        LoggerFactory.getLogger(WebTimeField.class)
                                .warn("Do not use java.sql.Date with time field");
                        return new java.sql.Date(date.getTime());
                    }
                    return date;
                } catch (Exception e) {
                    LoggerFactory.getLogger(WebTimeField.class)
                            .debug("Unable to parse value of component {}:\n{}", getId(), e.getMessage());
                    throw new ConversionException("Invalid value");
                }
            } else
                return null;
        }

        @Override
        public String convertToPresentation(Date value, Class<? extends String> targetType, Locale locale)
                throws ConversionException {
            if (value != null) {
                SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
                return sdf.format(value);
            } else
                return null;
        }

        @Override
        public Class<Date> getModelType() {
            return Date.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });
}

From source file:org.kuali.kpme.core.calendar.dao.CalendarDaoOjbImpl.java

@Override
public List<CalendarBo> getCalendars(String calendarName, String calendarTypes, String flsaBeginDay,
        String flsaBeginTime) {//from   www.  ja  v  a  2 s  .  c  o  m
    Criteria crit = new Criteria();

    List<CalendarBo> results = new ArrayList<CalendarBo>();

    if (StringUtils.isNotBlank(calendarName) && StringUtils.isNotEmpty(calendarName)) {
        crit.addLike("UPPER(calendarName)", calendarName.toUpperCase()); // KPME-2695
    }
    if (StringUtils.isNotBlank(calendarTypes) && StringUtils.isNotEmpty(calendarTypes)) {
        crit.addLike("calendarTypes", calendarTypes);
    }
    if (StringUtils.isNotBlank(flsaBeginDay) && StringUtils.isNotEmpty(flsaBeginDay)) {
        crit.addLike("flsaBeginDay", flsaBeginDay);
    }
    if (flsaBeginTime != null) {
        SimpleDateFormat sdFormat = new SimpleDateFormat("hh:mm aa");
        try {
            Time flsaTime = new Time(sdFormat.parse(flsaBeginTime).getTime());
            crit.addLike("flsaBeginTime", flsaTime);
        } catch (ParseException e) {

        }
    }
    Query query = QueryFactory.newQuery(CalendarBo.class, crit);
    Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
    results.addAll(c);

    return results;
}

From source file:Main.java

public static Time[] getTimesFromScheduleHour(char[] hoursArray) {

    Calendar begin = Calendar.getInstance();
    Calendar end = Calendar.getInstance();

    begin.set(Calendar.SECOND, 0);
    begin.set(Calendar.MILLISECOND, 0);
    end.set(Calendar.SECOND, 0);/*from   w  w  w  . ja v a2  s .  com*/
    end.set(Calendar.MILLISECOND, 0);

    char beginChar = hoursArray[0];
    char endChar = hoursArray[hoursArray.length - 1];

    switch (beginChar) {
    case 'A':
        begin.set(Calendar.HOUR_OF_DAY, 7);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'B':
        begin.set(Calendar.HOUR_OF_DAY, 8);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'C':
        begin.set(Calendar.HOUR_OF_DAY, 9);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'D':
        begin.set(Calendar.HOUR_OF_DAY, 10);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'E':
        begin.set(Calendar.HOUR_OF_DAY, 11);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'F':
        begin.set(Calendar.HOUR_OF_DAY, 12);
        begin.set(Calendar.MINUTE, 0);
        break;
    case 'G':
        begin.set(Calendar.HOUR_OF_DAY, 13);
        begin.set(Calendar.MINUTE, 0);
        break;
    case 'H':
        begin.set(Calendar.HOUR_OF_DAY, 13);
        begin.set(Calendar.MINUTE, 50);
        break;
    case 'I':
        begin.set(Calendar.HOUR_OF_DAY, 14);
        begin.set(Calendar.MINUTE, 50);
        break;
    case 'J':
        begin.set(Calendar.HOUR_OF_DAY, 15);
        begin.set(Calendar.MINUTE, 40);
        break;
    case 'L':
        begin.set(Calendar.HOUR_OF_DAY, 16);
        begin.set(Calendar.MINUTE, 40);
        break;
    case 'M':
        begin.set(Calendar.HOUR_OF_DAY, 17);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'N':
        begin.set(Calendar.HOUR_OF_DAY, 18);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'O':
        begin.set(Calendar.HOUR_OF_DAY, 19);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'P':
        begin.set(Calendar.HOUR_OF_DAY, 20);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'Q':
        begin.set(Calendar.HOUR_OF_DAY, 21);
        begin.set(Calendar.MINUTE, 10);
        break;
    default:
        return null;
    }

    switch (endChar) {
    case 'A':
        end.set(Calendar.HOUR_OF_DAY, 8);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'B':
        end.set(Calendar.HOUR_OF_DAY, 9);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'C':
        end.set(Calendar.HOUR_OF_DAY, 10);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'D':
        end.set(Calendar.HOUR_OF_DAY, 11);
        end.set(Calendar.MINUTE, 0);
        break;
    case 'E':
        end.set(Calendar.HOUR_OF_DAY, 12);
        end.set(Calendar.MINUTE, 0);
        break;
    case 'F':
        end.set(Calendar.HOUR_OF_DAY, 12);
        end.set(Calendar.MINUTE, 50);
        break;
    case 'G':
        end.set(Calendar.HOUR_OF_DAY, 13);
        end.set(Calendar.MINUTE, 50);
        break;
    case 'H':
        end.set(Calendar.HOUR_OF_DAY, 14);
        end.set(Calendar.MINUTE, 40);
        break;
    case 'I':
        end.set(Calendar.HOUR_OF_DAY, 15);
        end.set(Calendar.MINUTE, 40);
        break;
    case 'J':
        end.set(Calendar.HOUR_OF_DAY, 16);
        end.set(Calendar.MINUTE, 30);
        break;
    case 'L':
        end.set(Calendar.HOUR_OF_DAY, 17);
        end.set(Calendar.MINUTE, 30);
        break;
    case 'M':
        end.set(Calendar.HOUR_OF_DAY, 18);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'N':
        end.set(Calendar.HOUR_OF_DAY, 19);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'O':
        end.set(Calendar.HOUR_OF_DAY, 20);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'P':
        end.set(Calendar.HOUR_OF_DAY, 21);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'Q':
        end.set(Calendar.HOUR_OF_DAY, 22);
        end.set(Calendar.MINUTE, 0);
        break;
    default:
        return null;
    }

    return new Time[] { new Time(begin.getTimeInMillis()), new Time(end.getTimeInMillis()) };
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

@Override
public Time getCopy(Object object) {
    Time t = (Time) object;
    return t != null ? new Time(t.getTime()) : null;
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

public Time getInstance(Class<?> clazz) {
    return new Time(Integer.MAX_VALUE);
}