Example usage for java.util Calendar DAY_OF_MONTH

List of usage examples for java.util Calendar DAY_OF_MONTH

Introduction

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

Prototype

int DAY_OF_MONTH

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:models.MilestoneTest.java

@Test
public void findById() throws Exception {
    // Given//from ww w.  j a v  a2s  . c o m
    // When
    Milestone firstMilestone = Milestone.findById(1l);
    // Then
    assertThat(firstMilestone.title).isEqualTo("v.0.1");
    assertThat(firstMilestone.getContents()).isEqualTo("nFORGE  .");

    Calendar expactDueDate = new GregorianCalendar();
    expactDueDate.set(2012, Calendar.JULY, 12, 23, 59, 59); // 2012-07-12

    Calendar dueDate = new GregorianCalendar();
    dueDate.setTime(firstMilestone.dueDate);

    assertThat(expactDueDate.get(Calendar.YEAR)).isEqualTo(dueDate.get(Calendar.YEAR));
    assertThat(expactDueDate.get(Calendar.MONTH)).isEqualTo(dueDate.get(Calendar.MONTH));
    assertThat(expactDueDate.get(Calendar.DAY_OF_MONTH)).isEqualTo(dueDate.get(Calendar.DAY_OF_MONTH));

    assertThat(firstMilestone.getNumClosedIssues()).isEqualTo(2);
    assertThat(firstMilestone.getNumOpenIssues()).isEqualTo(2);
    assertThat(firstMilestone.getNumTotalIssues()).isEqualTo(4);
    assertThat(firstMilestone.project).isEqualTo(Project.find.byId(1l));
    assertThat(firstMilestone.getCompletionRate()).isEqualTo(50);
}

From source file:emily.util.YTUtil.java

/**
 * Time until the next google api reset happens (Midnight PT), or 9am GMT
 *
 * @return formatted string, eg. "10 minutes form now"
 *///from  w w w.  j  a v a 2 s.c  o  m
public static String nextApiResetTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, 0);
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return TimeUtil.getRelativeTime(
            (System.currentTimeMillis()
                    + (c.getTimeInMillis() - System.currentTimeMillis()) % TimeUnit.DAYS.toMillis(1)) / 1000L,
            false);
}

From source file:com.clican.pluto.dataprocess.engine.processes.TimerProcessor.java

public void process(final ProcessorContext context) throws DataProcessException {
    String id = UUID.randomUUID().toString();
    Date start = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Date end = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
    final SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
    final List<Throwable> exceptionList = new ArrayList<Throwable>();
    final Thread currentThread = Thread.currentThread();
    try {//www. ja  v  a 2 s. c om
        start = sdf2.parse(sdf1.format(start) + " " + startTime.trim());
        end = sdf2.parse(sdf1.format(end) + " " + endTime.trim());
        ScheduledTask task = new ScheduledTask(new Runnable() {

            public void run() {
                log.debug("timerProcessor?,?" + sdf2.format(new Date()));
                try {
                    for (DataProcessor timerProcessor : timerProcessors) {
                        if (stepCommit) {
                            dataProcessTransaction.doInCommit(timerProcessor, context);
                        } else {
                            timerProcessor.beforeProcess(context);
                            timerProcessor.process(context);
                            timerProcessor.afterProcess(context);
                        }
                    }
                } catch (InterruptedException e) {
                    log.error("Timer", e);
                    exceptionList.add(e);
                    synchronized (currentThread) {
                        currentThread.notify();
                    }
                } catch (Throwable e) {
                    log.error("Timer", e);
                    exceptionList.add(e);
                }
                log.debug("timerProcessor?,?" + sdf2.format(new Date()));
            }
        }, id, cronExpression, start, end, concurrent);
        long timeout = end.getTime() - new Date().getTime();
        if (log.isDebugEnabled()) {
            log.debug("timeout=" + timeout);
        }
        long beforetime = start.getTime() - new Date().getTime();
        if (beforetime > 5000) {
            throw new InterruptedException("???task,beforetime=[" + beforetime + "]");
        }
        if (timeout < 0) {
            throw new InterruptedException("????task,timeout=[" + timeout + "]");
        } else {
            taskScheduler.schedule(id, task);
            synchronized (currentThread) {
                currentThread.wait(timeout);
            }
        }
    } catch (Exception e) {
        throw new DataProcessException("Timer[" + this.getId() + "]", e);
    }
    try {
        if (exceptionList.size() != 0) {
            throw new DataProcessException(exceptionList.get(0));
        }
    } catch (Exception e) {
        throw new DataProcessException("TimerProcessor[" + this.getId() + "]", e);
    } finally {
        taskScheduler.cancel(id);
    }
}

From source file:de.arago.rike.task.action.StartTask.java

@Override
public void execute(IDataWrapper data) throws Exception {
    if (data.getRequestAttribute("id") != null) {
        String user = SecurityHelper.getUserEmail(data.getUser());

        if (TaskHelper.getTasksInProgressForUser(user).size() < Integer
                .parseInt(GlobalConfig.get(WORKFLOW_WIP_LIMIT))) {
            Task task = TaskHelper.getTask(data.getRequestAttribute("id"));

            if (!TaskHelper.canDoTask(user, task) || task.getStatusEnum() != Task.Status.OPEN) {
                return;
            }/*ww  w. j a  v a2s . c om*/

            task.setOwner(user);
            task.setStart(new Date());
            task.setStatus(Task.Status.IN_PROGRESS);
            if (GlobalConfig.get(WORKFLOW_TYPE).equalsIgnoreCase("arago Technologies")) {
                GregorianCalendar c = new GregorianCalendar();
                c.setTime(task.getStart());
                c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(GlobalConfig.get(WORKFLOW_DAYS_TO_FINISH_TASK)));
                task.setDueDate(c.getTime());
            }

            TaskHelper.save(task);
            StatisticHelper.update();

            data.setSessionAttribute("task", task);

            HashMap<String, Object> notificationParam = new HashMap<String, Object>();

            notificationParam.put("id", task.getId().toString());
            data.setEvent("TaskUpdateNotification", notificationParam);

            ActivityLogHelper.log(
                    " started Task #" + task.getId() + " <a href=\"/web/guest/rike/-/show/task/" + task.getId()
                            + "\">" + StringEscapeUtils.escapeHtml(task.getTitle()) + "</a> ",
                    task.getStatus(), user, data, task.toMap());
        }
    }
}

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 w w .  j  a  v a  2 s.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:net.ceos.project.poi.annotated.bean.PropagationHorizontalObjectBuilder.java

/**
 * Validate the PropagationHorizontalObject based on the object build with the method
 * 'buildPropagationHorizontalObject'/* www  .  j av a 2 s . co  m*/
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validatePropagationHorizontalObject(PropagationHorizontalObject toValidate) {
    PropagationHorizontalObject base = buildPropagationHorizontalObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));
    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute());
    assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute());
    assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute());
    assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute());
    assertEquals(base.getUnitFamily(), toValidate.getUnitFamily());
    assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute());
    // TODO add new validation below
}

From source file:nz.net.orcon.kanban.tools.DateInterpreterTest.java

@Test
public void testConversion_futureDate() throws Exception {
    final Calendar calFutureDate = Calendar.getInstance();
    calFutureDate.add(Calendar.DAY_OF_YEAR, 4);

    int dayOfMonth = calFutureDate.get(Calendar.DAY_OF_MONTH);
    int month = calFutureDate.get(Calendar.MONTH);
    int year = calFutureDate.get(Calendar.YEAR);

    final Date interpretDate = dateInterpreter.interpretDateFormula("today+4days");

    Calendar calInterpreted = Calendar.getInstance();
    calInterpreted.setTime(interpretDate);

    Assert.assertEquals(dayOfMonth, calInterpreted.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(month, calInterpreted.get(Calendar.MONTH));
    Assert.assertEquals(year, calInterpreted.get(Calendar.YEAR));
}

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

@Override
protected void adjustExpires(Calendar next) {

    if (StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) {
        next.set(Calendar.DAY_OF_MONTH, next.getActualMaximum(Calendar.DAY_OF_MONTH));
    } else {/*  w w  w.jav  a2 s .c om*/
        next.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayOfMonth));
    }
    if (next.before(Calendar.getInstance())) {
        next.add(Calendar.MONTH, 1);
    }
}

From source file:org.hephaestus.fixedformat.impl.TestRecordFactoryBase.java

public void testDetail1Scan() {
    Object vo = recordFactory.createRecord(DETAIL_RECORD_1);
    assertNotNull(vo);//from w w  w . j av  a 2  s.  co  m
    assertTrue(vo instanceof TstDetailRecord);

    TstDetailRecord tdr = (TstDetailRecord) vo;
    assertEquals(2L, tdr.getRecordType());
    assertEquals("Item 1", tdr.getDescription());
    assertEquals(303L, tdr.getAmount().longValue());

    Date dt = tdr.getDate();
    Calendar cal = Calendar.getInstance();
    cal.setTime(dt);
    assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
    assertEquals(31, cal.get(Calendar.DAY_OF_MONTH));

    dt = tdr.getTime();
    cal = Calendar.getInstance();
    cal.setTime(dt);
    assertEquals(23, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(33, cal.get(Calendar.MINUTE));
}