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.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java

/**
 * Make sure we can delete jobs that were created before a given date.
 *//*from  ww  w. ja  v  a  2s  .c o  m*/
@Test
public void canDeleteJobsCreatedBeforeDateWithMaxLargerThanPage() {

    // 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(), 10, 1);

    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:net.sourceforge.eclipsetrader.ats.internal.components.LiveMarketManager.java

void updateBarData(Security security) {
    Quote quote = security.getQuote();//  w ww  .j  av  a 2 s.co m
    if (quote == null || quote.getDate() == null)
        return;

    barTime.setTime(quote.getDate());
    barTime.set(Calendar.SECOND, 0);
    barTime.set(Calendar.MILLISECOND, 0);

    int quoteTime = barTime.get(Calendar.HOUR_OF_DAY) * 60 + barTime.get(Calendar.MINUTE);
    if (quoteTime < security.getBeginTime() || quoteTime > security.getEndTime())
        return;

    MapData data = (MapData) map.get(security);
    if (data.bar != null && data.bar.getDate() != null) {
        if (barTime.after(data.nextBarTime) || barTime.equals(data.nextBarTime)) {
            BarEvent e = new BarEvent(data.bar.getDate(), security, data.bar, data.bar.getClose());
            fireBarCloseEvent(e);

            data.bar = null;
        }
    } else if (data.bar == null) {
        data.bar = new Bar();
        data.bar.setOpen(quote.getLast());
        data.bar.setHigh(quote.getLast());
        data.bar.setLow(quote.getLast());
        data.bar.setClose(quote.getLast());
        data.volume = quote.getVolume();
        barTime.add(Calendar.MINUTE, -(barTime.get(Calendar.MINUTE) % minutes));
        data.bar.setDate(barTime.getTime());
        data.nextBarTime.setTime(data.bar.getDate());
        data.nextBarTime.add(Calendar.MINUTE, minutes);

        BarEvent e = new BarEvent(data.bar.getDate(), security, data.bar.getOpen());
        fireBarOpenEvent(e);
    }

    if (data.bar != null) {
        if (quote.getLast() > data.bar.getHigh())
            data.bar.setHigh(quote.getLast());
        if (quote.getLast() < data.bar.getLow())
            data.bar.setLow(quote.getLast());
        data.bar.setClose(quote.getLast());
        data.bar.setVolume(quote.getVolume() - data.volume);
    }
}

From source file:com.zergiu.tvman.jobs.TestTVRageShowLoader.java

@Test
public void testExecuteFringe() throws JobExecutionException {
    context.checking(new Expectations() {
        {// w ww .j av  a 2  s. c  om
            oneOf(jobContext).getJobDetail();
            will(returnValue(jobDetail));
        }
    });

    context.checking(new Expectations() {
        {
            oneOf(jobDetail).getJobBuilder();
            will(returnValue(JobBuilder.newJob()));
        }
    });

    show.setProviderSeriesId("18388");
    showLoader = createShowLoader("resources/tvrage/fringe_full_show_info.xml");

    showLoader.execute(jobContext);
    context.assertIsSatisfied();
    assertNotNull(show.getSeasons());
    assertEquals(4, show.getSeasons().size());
    assertEquals(80, getEpisodeCount());
    assertEquals(TVShowStatus.Continuing, show.getStatus());
    Calendar firstAirDate = Calendar.getInstance();
    firstAirDate.set(Calendar.YEAR, 2008);
    firstAirDate.set(Calendar.MONTH, Calendar.SEPTEMBER);
    firstAirDate.set(Calendar.DAY_OF_MONTH, 9);
    firstAirDate.set(Calendar.HOUR_OF_DAY, 0);
    firstAirDate.set(Calendar.MINUTE, 0);
    firstAirDate.set(Calendar.SECOND, 0);
    firstAirDate.set(Calendar.MILLISECOND, 0);
    assertEquals(firstAirDate.getTime(), show.getFirstAirDate());
    assertEquals("FOX", show.getNetwork());
    for (TVShowSeason season : show.getSeasons()) {
        for (TVShowEpisode ep : season.getEpisodes()) {
            assertNotNull(ep.getAirDate());
        }
    }
}

From source file:DateUtility.java

/**
 * We convert the date of the W3CDTF form into java.util.Date type.
 * //w w w .  ja va  2s. c  o  m
 * @param W3CDTFDate
 * @return
 */
public static Date getDateFromW3CDTF(String w3cDTFDate) {
    if (w3cDTFDate == null || w3cDTFDate.length() == 0)
        return null;

    try {
        int year = Integer.parseInt(w3cDTFDate.substring(0, 4));
        int month = Integer.parseInt(w3cDTFDate.substring(5, 7));
        int day = Integer.parseInt(w3cDTFDate.substring(8, 10));
        int hour = Integer.parseInt(w3cDTFDate.substring(11, 13));
        int minute = Integer.parseInt(w3cDTFDate.substring(14, 16));
        int second = Integer.parseInt(w3cDTFDate.substring(17, 19));
        String zone = "GMT" + w3cDTFDate.substring(19);
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day, hour, minute, second);
        cal.set(Calendar.MILLISECOND, 0);
        cal.setTimeZone(TimeZone.getTimeZone(zone));
        return cal.getTime();
    } catch (Exception e) {
        System.out.println(w3cDTFDate + " is invalid date string.");
    }

    return null;
}

From source file:org.openmrs.module.pharmacyapi.api.prescription.util.AbstractPrescriptionItemGenerator.java

public boolean isOrderExpired(final PrescriptionItem item, final Date creationDate) {

    final Double drugToPickUp = item.getDrugToPickUp();

    final Date nextPickUpDate = this.getNextPickUpDate(item.getDrugOrder());

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(nextPickUpDate);/*from   w  w w.j a  va 2  s  .  co m*/
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(Calendar.DAY_OF_MONTH, drugToPickUp.intValue());

    while ((calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            || (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {
        calendar.add(Calendar.DAY_OF_MONTH, -1);
    }

    return creationDate.after(calendar.getTime());
}

From source file:edu.jhuapl.openessence.web.util.Filters.java

public List<Filter> getFilters(final Map<String, String[]> parameterValues, final OeDataSource ds,
        final String prePullArg, final int prePullInc, final String resolution, int calWeekStartDay,
        final boolean adjustDate) throws ErrorMessageException {

    final List<Filter> filters = new ArrayList<Filter>();
    for (final FilterDimension fd : ds.getFilterDimensions()) {
        final FieldType type = fd.getSqlType();

        for (final String sfx : parmSfx.keySet()) {
            final String key = fd.getId() + sfx;

            if (!reservedParameters.contains(key)) {
                final String[] values = parameterValues.get(key);

                // No values for a filter dimension is ok
                if (!ArrayUtils.isEmpty(values)) {
                    if (values.length == 1) {
                        Object argument = ControllerUtils.formatData(key, values[0], type, false).get(key);

                        final Relation rel = type == FieldType.TEXT ? Relation.LIKE : parmSfx.get(sfx);

                        try {
                            if (fd.getId().equals(prePullArg) && (rel == Relation.GTEQ)) {
                                argument = muckDate((Date) argument, prePullInc, resolution, calWeekStartDay);
                            }//from   ww w  . ja va2  s  .c  om
                            // if end date, account for hours 00:00:00 to 23:59:59
                            if ((type == FieldType.DATE_TIME || type == FieldType.DATE)
                                    && (rel == Relation.LTEQ)) {
                                GregorianCalendar x = new GregorianCalendar();
                                x.setTime((Date) argument);

                                // Only perform this operation if it hasn't already been handled in a previous call.
                                // When generating a Chart, it will go to the end of the day and adjust the filter
                                // to be 23:59:59.999 (5/1/13 becomes 5/1/13-23:59:59.999).  But, when the user
                                // would click-through on a bar/slice, it would accidently perform this action again.
                                // This resulted in adding another day to the query; now becoming 5/2/13 23:59:59.998.
                                if (adjustDate) {
                                    x.add(Calendar.DATE, 1);
                                    x.add(Calendar.MILLISECOND, -1);
                                    argument = x.getTime();
                                }
                            }
                            filters.add(fd.makeFilter(rel, argument));
                        } catch (OeDataSourceException e) {
                            throw new ErrorMessageException("Could not create filter", e);
                        }
                    } else {
                        final Object[] arguments = new Object[values.length];
                        for (int i = 0; i < values.length; i++) {
                            arguments[i] = ControllerUtils.formatData(key, values[i], type, false).get(key);
                        }

                        try {
                            filters.add(fd.makeFilter(Relation.IN, arguments));
                        } catch (OeDataSourceException e) {
                            throw new ErrorMessageException("Could not create filter", e);
                        }
                    }
                }
            }
        }
    }

    return filters;
}

From source file:TimeLib.java

/**
 * Get the timestamp for the given year, month, and, day.
 * @param c a Calendar to use to help compute the result. The state of the
 * Calendar will be overwritten./*  w w  w  . jav a  2 s.c om*/
 * @param year the year to look up
 * @param month the month to look up (months start at 0==January)
 * @param day the day to look up
 * @return the timestamp for the given date
 */
public static long getDate(Calendar c, int year, int month, int day) {
    c.clear(Calendar.MILLISECOND);
    c.set(year, month, day, 0, 0, 0);
    return c.getTimeInMillis();
}

From source file:net.firejack.platform.core.utils.DateUtils.java

/**
 * Increments the date to round it on week level
 * @param date - date to be incremented// w ww.  j  a  va 2s.  co  m
 * @return incremented date
 */
public static Date ceilDateToWeek(Date date) {
    date = addWeeks(date, 1);
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return addMinutes(cal.getTime(), -1);
}

From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresLastDayPast() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.add(Calendar.MONTH, -1);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    actual.set(Calendar.DAY_OF_MONTH, actual.getActualMaximum(Calendar.DAY_OF_MONTH));

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());/*from  www .j a  v  a  2s . c om*/
    expected.add(Calendar.MONTH, 1);

    final int month = expected.get(Calendar.MONTH);
    properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, "LAST");

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(month, actual.get(Calendar.MONTH));
}

From source file:com.appeligo.epg.demo.DemoEPGService.java

public ScheduledProgram getScheduledProgram(String lineupId, String channelNumber, Date time) {

    StationChannel stationChannel = null;
    if (channelNumber.equals("41")) {
        stationChannel = createStationChannel("41", "Versus", "VS", "Versus");
    } else {//from w  w  w.j a  va2s  . c  o m
        stationChannel = createStationChannel(channelNumber, channelNumber, channelNumber, channelNumber);
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(time);
    int minute = cal.get(Calendar.MINUTE);
    if (minute < 30) {
        cal.set(Calendar.MINUTE, 0);
    } else {
        cal.set(Calendar.MINUTE, 30);
    }
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    time = cal.getTime();
    ScheduledProgram program = createScheduledProgram(time, null, stationChannel);
    return program;
}