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:at.florian_lentsch.expirysync.NotifyChecker.java

private static long getFirstStartMillis(Context appContext) {
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);
    long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1);
    if (firstStartMillis == -1) {
        return -1;
    }/*from  w ww  .  j a va 2s .co m*/

    Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    midnight.set(Calendar.HOUR_OF_DAY, 0);
    midnight.set(Calendar.MINUTE, 0);
    midnight.set(Calendar.SECOND, 0);
    midnight.set(Calendar.MILLISECOND, 0);

    // add "today at 0:00" to the ms value for the alarm (else the alarm
    // would be scheduled for 1970-01-01):
    firstStartMillis += midnight.getTimeInMillis();

    // if we're already past the alarm time today, we need to add another
    // day:
    if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) {
        firstStartMillis += AlarmManager.INTERVAL_DAY;
    }

    return firstStartMillis;
}

From source file:py.una.pol.karaku.dao.entity.interceptors.TimeInterceptor.java

@Override
public void intercept(Operation op, Field f, Object bean) {

    Object o = ReflectionUtils.getField(f, bean);

    if (o == null) {
        return;//from  w  ww .  ja va  2  s . c  o  m
    }

    Time t = f.getAnnotation(Time.class);
    Date date = (Date) o;
    Calendar c = Calendar.getInstance();
    c.setTime(date);

    if ((t == null) || t.type().equals(Time.Type.DATE)) {
        this.handleDate(c);
    } else if (t.type().equals(Time.Type.TIME)) {
        this.handleTime(c);
    }
    // DATETIME no es manejado por que no requeire ningun
    // trato especial

    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    ReflectionUtils.setField(f, bean, c.getTime());
}

From source file:com.lohika.alp.reporter.fe.dao.TestMethodDAOImpl.java

private DetachedCriteria getFilteredCriteria(TestMethodFilter filter) {
    DetachedCriteria criteria = DetachedCriteria.forClass(TestMethod.class);

    criteria.createAlias("testInstance", "testInstance").createAlias("testInstance.testClass", "testClass")
            .createAlias("testInstance.test", "test");

    if (filter.getFrom() != null && filter.getTill() != null) {
        Calendar c = Calendar.getInstance();

        c.setTime(filter.getFrom());// ww w. j  av a 2s .c o m
        c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND));
        Date from = c.getTime();

        c.setTime(filter.getTill());
        c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND));
        Date till = c.getTime();

        criteria.add(Restrictions.between("startDate", from.getTime(), till.getTime()));
    }

    if (filter.getCl() != "" && filter.getCl() != null) {
        try {
            criteria.add(querytr.translate("testClass.name", filter.getCl()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    if (filter.getGr() != "" && filter.getGr() != null) {
        criteria.createAlias("groups", "groups");

        try {
            criteria.add(querytr.translate("groups.name", filter.getGr()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    return criteria;
}

From source file:org.tsm.concharto.audit.IntegrationTestAuditEntry.java

@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3);
    cal.set(Calendar.MILLISECOND, 750);
    begin = cal.getTime();/* w ww  . j  av a2s.c o m*/
    cal.set(Calendar.SECOND, 35);
    end = cal.getTime();

}

From source file:AIR.Common.Sql.UnitTestDateUtilDll.java

private synchronized Date getDateStatic() {
    Date current = _baseLineDate.getTime();
    // increment the time by a couple of seconds to simulate subsequent calls
    // with increasing time.
    _baseLineDate.add(Calendar.MILLISECOND, 5);
    return current;
}

From source file:org.activiti.rest.service.api.runtime.TaskEventResourceTest.java

/**
 * Test getting a single event for a task. GET runtime/tasks/{taskId}/events/{eventId}
 *//*from w  w  w .  j  ava2 s  . co  m*/
public void testGetEvent() throws Exception {
    try {
        Calendar now = Calendar.getInstance();
        now.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(now.getTime());

        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.addUserIdentityLink(task.getId(), "gonzo", "someType");

        Event event = taskService.getTaskEvents(task.getId()).get(0);

        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX
                + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_EVENT, task.getId(), event.getId()));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals(event.getId(), responseNode.get("id").textValue());
        assertEquals(event.getAction(), responseNode.get("action").textValue());
        assertEquals(event.getUserId(), responseNode.get("userId").textValue());
        assertTrue(responseNode.get("url").asText().endsWith(
                RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_EVENT, task.getId(), event.getId())));
        assertTrue(responseNode.get("taskUrl").asText()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertEquals(now.getTime(), getDateFromISOString(responseNode.get("time").textValue()));

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}

From source file:com.ancientprogramming.fixedformat4j.format.impl.TestNullableFixedFormatManagerImpl.java

private MyNullableRecord createMyNullableRecord() {
    Calendar someDay = Calendar.getInstance();
    someDay.set(2008, 4, 14, 0, 0, 0);//  w  ww  .j  a v  a2 s .c o m
    someDay.set(Calendar.MILLISECOND, 0);

    MyNullableRecord myRecord = new MyNullableRecord();
    myRecord.setBooleanData(true);
    myRecord.setCharData('C');
    myRecord.setDateData(someDay.getTime());
    myRecord.setDoubleData(10.35);
    myRecord.setFloatData(20.56F);
    myRecord.setLongData(11L);
    myRecord.setIntegerData(null);
    myRecord.setStringData(null);
    myRecord.setBigDecimalData(new BigDecimal(-12.012));
    myRecord.setSimpleFloatData(20.56F);
    return myRecord;
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

public static Date convertToGMTAbsoluteDate(Date dateValue, String sourceSystemTimezone) {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(sourceSystemTimezone));
    cal.setLenient(false);/*from w ww .  j  a  va  2s  . c o m*/
    cal.setTime(dateValue);
    Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone(GMT_TIME_ZONE_STRING));
    newCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    newCal.set(Calendar.MILLISECOND, 0);
    Date returnDate = newCal.getTime();
    return returnDate;
}

From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java

@Override
public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {

    if (data == null) {
        // TODO replace value
        return null;
    }/*from  w w  w .  j a  va  2  s.  com*/

    IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
    IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD);
    IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);

    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    BigDecimal day = null;
    BigDecimal month = null;
    BigDecimal year = null;

    if (data.length != getTypeLength()) {
        throw new EBusTypeException(
                String.format("Input byte array must have a length of %d bytes!", getTypeLength()));
    }

    if (StringUtils.equals(variant, SHORT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, DEFAULT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, HEX_SHORT)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, DAYS)) {
        BigDecimal daysSince1900 = wordType.decode(data);
        calendar.set(1900, 0, 1, 0, 0);
        calendar.add(Calendar.DAY_OF_YEAR, daysSince1900.intValue());
    }

    if (day != null && month != null && year != null) {
        if (day.intValue() < 1 || day.intValue() > 31) {
            throw new EBusTypeException("A valid day must be in a range between 1-31 !");
        }
        if (month.intValue() < 1 || month.intValue() > 12) {
            throw new EBusTypeException("A valid day must be in a range between 1-12 !");
        }
    }

    if (year != null) {
        if (year.intValue() < 70) {
            year = year.add(new BigDecimal(2000));
        } else {
            year = year.add(new BigDecimal(1900));
        }
        calendar.set(Calendar.YEAR, year.intValue());
    }

    if (month != null) {
        calendar.set(Calendar.MONTH, month.intValue() - 1);
    }

    if (day != null && day.intValue() > 0 && day.intValue() < 32) {
        calendar.set(Calendar.DAY_OF_MONTH, day.intValue());
    }

    return new EBusDateTime(calendar, false, true);
}