Example usage for java.util Calendar MILLISECOND

List of usage examples for java.util Calendar MILLISECOND

Introduction

In this page you can find the example usage for java.util Calendar MILLISECOND.

Prototype

int MILLISECOND

To view the source code for java.util Calendar MILLISECOND.

Click Source Link

Document

Field number for get and set indicating the millisecond within the second.

Usage

From source file:com.autentia.tnt.bean.activity.GlobalHoursReportBean.java

public List<GlobalHourReport> getAll() {

    // Retrieve activities for every User during that period of time            
    ActivitySearch search = new ActivitySearch();

    Calendar init = Calendar.getInstance();
    init.setTime(startDate);/* ww  w  .  j a v a2  s .  c  o m*/
    Calendar last = Calendar.getInstance();
    last.setTime(endDate);

    init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
    init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
    init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
    init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));

    last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
    last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
    last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
    last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));

    search.setStartStartDate(init.getTime());
    search.setEndStartDate(last.getTime());

    List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>();

    if (billable)
        search.setBillable(true);

    // Search activities during indicated dates
    List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));

    // Search for projects in activities and create the global list.      

    for (Activity act : activities) {
        Project proj = act.getRole().getProject();
        GlobalHourReport unit = new GlobalHourReport();
        unit.setProject(proj);

        // an entry in the list represents a project
        if (!listGlobal.contains(unit))
            listGlobal.add(unit);

        // Retrieve the stored unit and save hours
        GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit));
        float horas = act.getDuration() / 60.0f;

        storedUnit.setUserHours(act.getUser(), horas);
        storedUnit.setIterator(usuarios.iterator());

    }

    return listGlobal;

}

From source file:com.tesora.dve.common.TestDataGenerator.java

protected Object getColumnValue(ColumnMetadata cm) {
    Object cv = null;/*www .  j av a 2  s  .c o m*/
    Calendar cal = Calendar.getInstance();

    switch (cm.getDataType()) {
    case Types.BIT:
    case Types.BOOLEAN:
        cv = Boolean.TRUE;
        break;
    case Types.BIGINT:
        cv = Long.MAX_VALUE;
        break;
    case Types.CHAR:
    case Types.VARCHAR:
        cv = StringUtils.left(baseString, cm.getSize());
        break;
    case Types.SMALLINT:
        cv = Short.MAX_VALUE;
        break;
    case Types.TINYINT:
        cv = Byte.MAX_VALUE;
        break;
    case Types.INTEGER:
        cv = Integer.MAX_VALUE;
        break;
    case Types.DOUBLE:
        cv = new Double(1234.5678); // TODO need to handle s,p
        break;
    case Types.FLOAT:
        cv = new Float(123.56); // TODO need to handle s,p
        break;
    case Types.DECIMAL:
        cv = new BigDecimal("12345.6789"); // TODO need to handle s,p
        break;
    case Types.DATE:
        cal.setTimeInMillis(123456789);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cv = cal.getTime();
        break;
    case Types.TIMESTAMP:
        cal.setTimeInMillis(123456789);
        cv = cal.getTime();
        break;
    case Types.TIME:
        cv = new Time(123456789);
        break;
    default:
        break;
    }

    return cv;
}

From source file:py.una.pol.karaku.test.test.dao.interceptors.TimeInterceptorTest.java

/**
 * Test time./*www  .j a va 2  s .c  om*/
 */
@Test
public void testTime() {

    Date d = new Date();
    Date d2 = new Date(d.getTime());

    TimeTest tt = new TimeTest(d, d, d);

    this.interceptorHandler.intercept(Operation.CREATE, tt);

    Calendar c = Calendar.getInstance();
    c.setTime(tt.getTime());

    Calendar c2 = Calendar.getInstance();
    c2.setTime(d2);

    assertThat(c.get(Calendar.YEAR), is(1970));
    assertThat(c.get(Calendar.MONTH), is(0));
    assertThat(c.get(Calendar.DAY_OF_MONTH), is(1));

    assertThat(c.get(Calendar.HOUR_OF_DAY), is(c2.get(Calendar.HOUR_OF_DAY)));
    assertThat(c.get(Calendar.MINUTE), is(c2.get(Calendar.MINUTE)));

    assertThat(c.get(Calendar.SECOND), is(0));
    assertThat(c.get(Calendar.MILLISECOND), is(0));

}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java

/**
 * Return <code>true</code> if the date represented by the passed parameters is strictly before the given upper limit,
 * <code>false</code> otherwise.
 *
 * Note: All parameters are 1-based meaning 1 for Jan, 2 for Feb etc unlike Java Calendar API.
 *
 * @param day date value for the date/*from  ww  w  .  j a va2s. c  om*/
 * @param month month value for the date
 * @param year year value for the date
 * @param strictUpperLimit the strict upper limit for the given date
 * @return <code>true</code> if the date represented by the passed parameters is strictly before the given upper limit,
 * <code>false</code> otherwise
 */
public static boolean isDateStrictlyBeforeGivenTime(final String day, final String month, final String year,
        final Calendar strictUpperLimit) {

    boolean result = true;

    final Calendar calendarFromDate = Calendar.getInstance();
    calendarFromDate.setLenient(false);
    calendarFromDate.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day), 0, 0, 0);
    calendarFromDate.set(Calendar.MILLISECOND, 0);

    if (!calendarFromDate.before(strictUpperLimit)) {
        result = false;
    }

    return result;
}

From source file:com.xumpy.timesheets.services.implementations.TickedJobsSrvImpl.java

@Override
@Transactional/*w  w w .j  av  a 2 s. com*/
public TickedJobsLstCtrlPojo allNotProcessedTickedJobs() {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    TickedJobsLstCtrlPojo tickedJobsFiltered = new TickedJobsLstCtrlPojo();
    List<? extends TickedJobs> tickedJobsAll = tickedJobsDao.selectAllTickedJobs();
    try {
        List<TimeRecording> timeRecordings = sessionTimesheet.getTimesheetTable();

        for (TimeRecording timeRecording : timeRecordings) {
            boolean found = false;
            for (TickedJobs tickedJob : tickedJobsAll) {
                if (timeRecording.getTicked().equals(format.format(tickedJob.getTicked()))) {
                    found = true;
                }
            }

            if (!found) {
                TickedJobsCtrlPojo tickedJobsCtrlPojo = new TickedJobsCtrlPojo();

                tickedJobsCtrlPojo.setSqlite_id(timeRecording.getSqlite_id());

                if (timeRecording.getStarted().equals(10)) {
                    tickedJobsCtrlPojo.setStarted(true);
                } else {
                    tickedJobsCtrlPojo.setStarted(false);
                }

                tickedJobsCtrlPojo.setTicked(format.parse(timeRecording.getTicked()));

                Calendar cal = Calendar.getInstance(); // locale-specific
                cal.setTime(tickedJobsCtrlPojo.getTicked());
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                cal.set(Calendar.MILLISECOND, 0);

                List<JobsCtrlPojo> allJobs = new ArrayList<JobsCtrlPojo>();
                List<? extends Jobs> selectedJobs = jobsDao.selectDate(cal.getTime());

                for (Jobs job : selectedJobs) {
                    allJobs.add(new JobsCtrlPojo(job));
                }

                if (selectedJobs.size() == 1) {
                    tickedJobsCtrlPojo.setSelectedJobId(selectedJobs.get(0).getPk_id());
                }

                tickedJobsCtrlPojo.setJobs(allJobs);

                tickedJobsFiltered.add(tickedJobsCtrlPojo);
            }
        }

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    return tickedJobsFiltered;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.CancelacionDaoHibernate.java

@Override
@Transactional(readOnly = true)//from  www  .  java2  s .  co m
public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de cancelaciones con params {}", params);
    if (params == null) {
        params = new HashMap<>();
    }

    if (!params.containsKey("max")) {
        params.put("max", 10);
    } else {
        params.put("max", Math.min((Integer) params.get("max"), 100));
    }

    if (params.containsKey("pagina")) {
        Long pagina = (Long) params.get("pagina");
        Long offset = (pagina - 1) * (Integer) params.get("max");
        params.put("offset", offset.intValue());
    }

    if (!params.containsKey("offset")) {
        params.put("offset", 0);
    }
    Criteria criteria = currentSession().createCriteria(Cancelacion.class);
    Criteria countCriteria = currentSession().createCriteria(Cancelacion.class);

    if (params.containsKey("almacen")) {
        criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
        countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
    }

    if (params.containsKey("fechaIniciado")) {
        log.debug("Buscando desde {}", params.get("fechaIniciado"));
        criteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado")));
        countCriteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado")));
    } else {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 1);
        log.debug("Asignando busqueda desde {}", calendar.getTime());
        criteria.add(Restrictions.ge("fechaCreacion", calendar.getTime()));
        countCriteria.add(Restrictions.ge("fechaCreacion", calendar.getTime()));
    }

    if (params.containsKey("fechaTerminado")) {
        log.debug("Buscando hasta {}", params.get("fechaTerminado"));
        criteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado")));
        countCriteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado")));
    }

    if (params.containsKey("filtro")) {
        String filtro = (String) params.get("filtro");
        Disjunction propiedades = Restrictions.disjunction();
        propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("comentarios", filtro, MatchMode.ANYWHERE));
        criteria.add(propiedades);
        countCriteria.add(propiedades);
    }

    if (params.containsKey("order")) {
        String campo = (String) params.get("order");
        if (params.get("sort").equals("desc")) {
            criteria.addOrder(Order.desc(campo));
        } else {
            criteria.addOrder(Order.asc(campo));
        }
    } else {
        criteria.addOrder(Order.desc("fechaCreacion"));
    }

    if (!params.containsKey("reporte")) {
        criteria.setFirstResult((Integer) params.get("offset"));
        criteria.setMaxResults((Integer) params.get("max"));
    }
    params.put("cancelaciones", criteria.list());

    countCriteria.setProjection(Projections.rowCount());
    params.put("cantidad", (Long) countCriteria.list().get(0));

    return params;
}

From source file:com.acmeair.loader.FlightLoader.java

public void loadFlights() throws Exception {
    InputStream csvInputStream = FlightLoader.class.getResourceAsStream("/mileage.csv");

    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(csvInputStream));
    String line1 = lnr.readLine();
    StringTokenizer st = new StringTokenizer(line1, ",");
    ArrayList<AirportCodeMapping> airports = new ArrayList<AirportCodeMapping>();

    // read the first line which are airport names
    while (st.hasMoreTokens()) {
        AirportCodeMapping acm = new AirportCodeMapping();
        acm.setAirportName(st.nextToken());
        airports.add(acm);// w w  w. j  a va  2  s  .  c o m
    }
    // read the second line which contains matching airport codes for the first line
    String line2 = lnr.readLine();
    st = new StringTokenizer(line2, ",");
    int ii = 0;
    while (st.hasMoreTokens()) {
        String airportCode = st.nextToken();
        airports.get(ii).setAirportCode(airportCode);
        ii++;
    }
    // read the other lines which are of format:
    // airport name, aiport code, distance from this airport to whatever airport is in the column from lines one and two
    String line;
    int flightNumber = 0;
    while (true) {
        line = lnr.readLine();
        if (line == null || line.trim().equals("")) {
            break;
        }
        st = new StringTokenizer(line, ",");
        String airportName = st.nextToken();
        String airportCode = st.nextToken();
        if (!alreadyInCollection(airportCode, airports)) {
            AirportCodeMapping acm = new AirportCodeMapping();
            acm.setAirportName(airportName);
            acm.setAirportCode(airportCode);
            airports.add(acm);
        }
        int indexIntoTopLine = 0;
        while (st.hasMoreTokens()) {
            String milesString = st.nextToken();
            if (milesString.equals("NA")) {
                indexIntoTopLine++;
                continue;
            }
            int miles = Integer.parseInt(milesString);
            String toAirport = airports.get(indexIntoTopLine).getAirportCode();
            String flightId = "AA" + flightNumber;
            FlightSegment flightSeg = new FlightSegment(flightId, airportCode, toAirport, miles);
            flightService.storeFlightSegment(flightSeg);
            Date now = new Date();
            for (int daysFromNow = 0; daysFromNow < MAX_FLIGHTS_PER_SEGMENT; daysFromNow++) {
                Calendar c = Calendar.getInstance();
                c.setTime(now);
                c.set(Calendar.HOUR_OF_DAY, 0);
                c.set(Calendar.MINUTE, 0);
                c.set(Calendar.SECOND, 0);
                c.set(Calendar.MILLISECOND, 0);
                c.add(Calendar.DATE, daysFromNow);
                Date departureTime = c.getTime();
                Date arrivalTime = getArrivalTime(departureTime, miles);
                flightService.createNewFlight(flightId, departureTime, arrivalTime, new BigDecimal(500),
                        new BigDecimal(200), 10, 200, "B747");

            }
            flightNumber++;
            indexIntoTopLine++;
        }
    }

    for (int jj = 0; jj < airports.size(); jj++) {
        flightService.storeAirportMapping(airports.get(jj));
    }
    lnr.close();
}

From source file:com.amediamanager.util.S3FormSigner.java

/**
 * The UploadPolicy method creates the S3 upload policy for the aMediaManager application.
 * Much of this is hard coded and would have to change with any changes to the fields in the S3
 * upload form./*www  .  j  av  a  2  s .  c  om*/
 *
 * @param key            this is not currently used.
 * @param redirectUrl    this is the URL to which S3 will redirect the browser on successful upload.
 * @return                the upload policy string is returned.
 */
String generateUploadPolicy(String s3BucketName, String keyPrefix, AWSCredentialsProvider credsProvider,
        String redirectUrl) {

    Calendar dateTime = Calendar.getInstance();
    // add the offset from UTC
    dateTime.add(Calendar.MILLISECOND, -dateTime.getTimeZone().getOffset(dateTime.getTimeInMillis()));
    // add 15 minutes more for skew
    dateTime.add(Calendar.MINUTE, 15);
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    String expirationDate = dateFormatter.format(dateTime.getTime());

    StringBuilder sb = new StringBuilder();
    sb.append("{ \"expiration\": \"" + expirationDate + "\",");
    sb.append("\"conditions\": [ { \"bucket\": \"" + s3BucketName + "\" }, ");
    sb.append("[\"starts-with\", \"$key\", \"" + keyPrefix + "/\"], ");
    sb.append("{ \"success_action_redirect\": \"" + redirectUrl + "\" },");
    sb.append("[\"eq\", \"$x-amz-meta-bucket\", \"" + s3BucketName + "\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-owner\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-uuid\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-title\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-tags\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-createdDate\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-description\", \"\"], ");
    sb.append("[\"starts-with\", \"$x-amz-meta-privacy\", \"\"], ");
    sb.append("[\"starts-with\", \"$Content-Type\", \"video/\"], ");

    if (credsProvider.getCredentials() instanceof BasicSessionCredentials) {
        sb.append("[\"starts-with\", \"$x-amz-security-token\", \"\"], ");
    }

    sb.append("[\"content-length-range\", 0, 1073741824] ] }");
    return sb.toString();
}

From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java

/**
 * Make sure we can delete jobs that were created before a given date.
 *//*www.  j  a  v  a 2  s  . co  m*/
@Test
public void canDeleteJobsCreatedBeforeDateWithPageLargerThanMax() {

    // Try to delete a all jobs from before Jan 1, 2016
    final Calendar cal = Calendar.getInstance(JobConstants.UTC);
    cal.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);

    final long deleted = this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(cal.getTime(), 1, 10);

    Assert.assertThat(deleted, Matchers.is(2L));
    Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(1L));
    Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(1L));
    Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(1L));
    Assert.assertThat(this.jobRepository.count(), Matchers.is(1L));
    Assert.assertNotNull(this.jobExecutionRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRequestRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRequestMetadataRepository.getOne(JOB_3_ID));
    Assert.assertNotNull(this.jobRepository.getOne(JOB_3_ID));
}

From source file:be.fedict.eid.pkira.blm.model.reporting.ReportEntryListQuery.java

private void setQueryParameters(Query query) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(reportDate);//from   w w  w. j a  va 2 s.c  o  m
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date start = calendar.getTime();

    calendar.add(Calendar.DATE, 1);
    Date end = calendar.getTime();

    query.setParameter("start", start, TemporalType.TIMESTAMP);
    query.setParameter("end", end, TemporalType.TIMESTAMP);

    if (contractTypeFilter != null)
        query.setParameter("contractType", contractTypeFilter);
    if (StringUtils.isNotBlank(certificateDomainNameFilter))
        query.setParameter("certificateDomainName", "%" + certificateDomainNameFilter.toLowerCase() + "%");
    if (StringUtils.isNotBlank(subjectFilter))
        query.setParameter("subject", "%" + subjectFilter.toLowerCase() + "%");
    if (successFilter != null)
        query.setParameter("success", successFilter);
}