Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

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

Usage

From source file:it.marcoberri.mbmeteo.action.chart.Base.java

/**
 *
 * @param from/*from   w  w w .  j av  a2  s  .co  m*/
 * @param to
 * @return
 */
protected List<Date> getRangeDate(Date from, Date to) {
    final List<Date> dates = new ArrayList<Date>();
    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(from);

    while (calendar.getTime().before(to)) {
        Date resultado = calendar.getTime();
        dates.add(resultado);
        calendar.add(Calendar.DATE, 1);
    }
    return dates;
}

From source file:com.aimdek.ccm.dao.impl.test.StatementDaoImplTest.java

/**
 * Initialize.//from  w  ww  .  ja v a 2 s.c  o  m
 */
@Before
public void initialize() {

    List<Statement> statementList = new ArrayList<Statement>();

    Statement statement = new Statement();
    statement.setAmountDue(500);
    statement.setCardNumber("1234-1234-1234-0008");
    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTime(new Date());
    calendar1.add(Calendar.DATE, 15);
    calendar1.set(Calendar.HOUR_OF_DAY, 23);
    calendar1.set(Calendar.MINUTE, 59);
    calendar1.set(Calendar.MINUTE, 59);
    statement.setDueDate(calendar1.getTime());
    statement.setStatementDate(new Date());
    Calendar calendar = Calendar.getInstance();
    calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    statement.setToDate(calendar.getTime());
    statement.setCreditCardId(1);
    statementList.add(statement);

    Statement statement1 = new Statement();
    statement1.setAmountDue(500);
    statement1.setCardNumber("1234-1234-1234-0008");
    statement1.setDueDate(calendar1.getTime());
    statement1.setStatementDate(new Date());
    statement1.setToDate(calendar.getTime());
    statement1.setCreditCardId(2);
    statement1.setStatementDate(new Date());
    statementList.add(statement1);

    Statement statement2 = new Statement();
    statement2.setAmountDue(500);
    statement2.setCardNumber("1234-1234-1234-0008");
    statement2.setDueDate(calendar1.getTime());
    statement2.setStatementDate(new Date());
    statement2.setToDate(calendar.getTime());
    statement2.setCreditCardId(3);
    statement2.setStatementDate(new Date());
    statementList.add(statement2);

    Statement statement3 = new Statement();
    statement3.setAmountDue(500);
    statement3.setCardNumber("1234-1234-1234-0008");
    statement3.setDueDate(calendar1.getTime());
    statement3.setStatementDate(new Date());
    statement3.setToDate(calendar.getTime());
    statement3.setCreditCardId(3);
    statement3.setStatementDate(new Date());
    statementList.add(statement3);

    statementRepository.save(statementList);
}

From source file:com.clustercontrol.maintenance.factory.MaintenanceObject.java

/**
 * ?(dataRetentionPeriod)????00:00:00?epoch()??
 * @param dataRetentionPeriod/* www.  jav a2 s.c  o m*/
 * @return
 */
private Long getDataRetentionBoundary(int dataRetentionPeriod) {
    m_log.debug("getDataRetentionBoundary() dataRetentionPeriod : " + dataRetentionPeriod);

    // ???
    Calendar calendar = HinemosTime.getCalendarInstance();

    // 0?dataRetentionPeriod????
    if (dataRetentionPeriod > 0) {
        calendar.add(Calendar.DATE, -dataRetentionPeriod);
    }
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Long boundary = calendar.getTimeInMillis();

    m_log.debug("getDataRetentionBoundary() : boundary is " + boundary + " ("
            + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(boundary) + ")");

    return boundary;
}

From source file:gov.utah.dts.det.ccl.model.FacilityTest.java

@Test
public void testGetActiveLicenses() {
    Date now = DateUtils.truncate(new Date(), Calendar.DATE);
    Facility f1 = new Facility();

    //an empty list should be returned when there are no licenses
    assertTrue(f1.getActiveLicenses().isEmpty());

    License l1 = new License();
    l1.setStartDate(DateUtils.addDays(now, -60));
    l1.setExpirationDate(DateUtils.addDays(now, -30));
    f1.addLicense(l1);/*  w  w w.j a  v a 2s  .  com*/
    assertTrue(f1.getActiveLicenses().isEmpty());

    License l2 = new License();
    l2.setStartDate(DateUtils.addDays(now, -30));
    l2.setExpirationDate(DateUtils.addDays(now, 30));
    f1.addLicense(l2);
    //List<License> test = f1.getActiveLicenses();
    assertTrue(f1.getActiveLicenses().size() == 0);
    //assertEquals(f1.getActiveLicenses().get(0), l2);
}

From source file:org.openmrs.module.kenyaemr.calculation.library.MissedLastAppointmentCalculationTest.java

/**
 * @see MissedLastAppointmentCalculation#evaluate(java.util.Collection, java.util.Map, org.openmrs.calculation.patient.PatientCalculationContext)
 *//*from  ww w  .j a  v  a  2s.c  om*/
@Test
public void evaluate_shouldDetermineWhetherPatientsWhoMissedAppointmentsOrDefaulted() throws Exception {
    // Give patient #7 a return visit obs of 10 days ago
    Concept returnVisit = Context.getConceptService().getConcept(5096);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -10);
    TestUtils.saveObs(TestUtils.getPatient(7), returnVisit, calendar.getTime(), calendar.getTime());

    // Give patient #8 a return visit obs of 10 days in the future
    calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 10);
    TestUtils.saveObs(TestUtils.getPatient(8), returnVisit, calendar.getTime(), calendar.getTime());

    List<Integer> cohort = Arrays.asList(6, 7, 8, 9);

    CalculationResultMap resultMap = new MissedLastAppointmentCalculation().evaluate(cohort, null,
            Context.getService(PatientCalculationService.class).createCalculationContext());
    Assert.assertFalse((Boolean) resultMap.get(6).getValue()); // patient has no return visit obs
    Assert.assertTrue((Boolean) resultMap.get(7).getValue()); // patient has missed visit
    Assert.assertFalse((Boolean) resultMap.get(8).getValue()); // patient has future return visit date
}

From source file:gov.nih.nci.cabig.caaers.domain.factory.ReportFactoryIntegrationTest.java

public void testAddScheduledNotifications() {
    reportDefinition.setTimeScaleUnitType(TimeScaleUnit.DAY);

    PlannedNotification pn1 = Fixtures.createPlannedEmailNotification();
    pn1.setIndexOnTimeScale(2);//from   ww w .  ja va  2s  .co m
    reportDefinition.addPlannedNotification(pn1);

    PlannedNotification pn2 = Fixtures.createPlannedEmailNotification();
    pn2.setIndexOnTimeScale(3);
    reportDefinition.addPlannedNotification(pn2);

    assertEquals(2, reportDefinition.getPlannedNotifications().size());
    reportFactory.addScheduledNotifications(reportDefinition, report);
    assertEquals(2, report.getScheduledNotifications().size());

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 2);
    Date dayAfterTomorrow = cal.getTime();
    cal.add(Calendar.DATE, 1);
    Date dayAfterDayAfterTomorrow = cal.getTime();

    assertEquals(DeliveryStatus.CREATED, report.getScheduledNotifications().get(0).getDeliveryStatus());
    assertEquals(0,
            DateUtils.compareDate(new Date(), report.getScheduledNotifications().get(0).getCreatedOn()));

    assertEquals(0, DateUtils.compareDate(dayAfterTomorrow,
            report.getScheduledNotifications().get(0).getScheduledOn()));
    assertEquals(0, DateUtils.compareDate(dayAfterDayAfterTomorrow,
            report.getScheduledNotifications().get(1).getScheduledOn()));
    assertTrue(report.hasScheduledNotifications());

}

From source file:DateUtils.java

public static final String dateToString(Date dt, String tzString, String dateformat) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(dt);/*from ww w.j av  a  2  s  .  c om*/
    cal.setTimeZone(TimeZone.getTimeZone(tzString));

    StringBuffer ret = new StringBuffer();
    String separator = new String();
    if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) {
        separator = "-";
    }
    if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) {
        separator = "/";
    }
    ret.append(cal.get(Calendar.YEAR));
    ret.append(separator);
    ret.append(cal.get(Calendar.MONTH) + 1);
    ret.append(separator);
    ret.append(cal.get(Calendar.DATE));

    return ret.toString();
}

From source file:com.cemeterylistingswebtest.test.services.PublishListingServiceTest.java

@Test()
public void publishTest() {
    pubServ = ctx.getBean(PublishListingService.class);
    repo = ctx.getBean(SubscriberRepository.class);
    repoList = ctx.getBean(RequiresApprovalDeceasedListingRepository.class);
    userRepo = ctx.getBean(UserRoleRepository.class);
    pubRepo = ctx.getBean(PublishedDeceasedListingRepository.class);

    //Initialise date
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2010);
    calendar.set(Calendar.MONTH, Calendar.JUNE);
    calendar.set(Calendar.DATE, 14);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    //Initialise user role                
    UserRole userRole = new UserRole.Builder().setLevel(2).build();
    //userRepo.save(userRole);
    //userRoleID = userRole.getUserRoleID();

    //Initialise subscriber
    Subscriber newSub = new Subscriber.Builder().setEmail("bwillis@gmail.com").setFirstName("bruce")
            .setSurname("willis").setPwd("diehard").setUsername("bwillis").setSubscriptionDate(javaSqlDate)
            .setUserRoleID(userRole).build();
    repo.save(newSub);//from w ww. j  a va  2 s.c o m
    subID = newSub.getSubscriberID();

    //Finally Initialise RequiresApprovalDeceasedListing
    RequiresApprovalDeceasedListing newListing = new RequiresApprovalDeceasedListing.Builder()
            .setFirstName("maggie").setSurname("mcClain").setMaidenName("Gerber").setGender("Female")
            .setDateOfBirth("10/06/1967").setDateOfDeath("14/03/2006").setGraveInscription("was a mother")
            .setGraveNumber("2521").setImageOfBurialSite("/images/003.jpg").setLastKnownContactName("john")
            .setLastKnownContactNumber("07273218482").setSubscriberSubmitID(subID)
            //cemetery id

            //names

            .build();

    repoList.save(newListing);
    id = newListing.getRequiresApprovalDeceasedListingID();

    id2 = pubServ.publishListingsReturn(newListing);
    boolean empty = pubRepo.findAll().isEmpty();
    //Assert.assertEquals(repoList.findAll().size(), 1);
    Assert.assertFalse(empty);
    Assert.assertNotNull(pubRepo.findOne(id2).getPublishedListingID());
    repoList.delete(id);
    pubRepo.delete(id2);
    repo.delete(subID);

}

From source file:com.lordmat.githubstream.data.GitHubCallerTest.java

@Test
public void testGetCommits() {
    System.out.println("testGetCommits");
    GitHubCaller instance = createInstance();

    Calendar calender = Calendar.getInstance();
    calender.set(Calendar.DATE, calender.getActualMinimum(Calendar.DATE));

    String since = DateTimeFormat.format(calender.getTime());
    String until = null;//from w ww . j a v a 2  s .  c  om

    Map<Date, GitHubCommit> result = instance.getCommits(since, until);

    assertTrue(result.size() > 0);

    assertNotNull(result.values().iterator().next().getDate());
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static String getNextWorkingDay(String currDate, int[] NWD, String[] CH) {
    Calendar c1 = Calendar.getInstance();
    Date stdate = c1.getTime();//from w w  w .  java  2s .c  o m
    java.text.SimpleDateFormat sdfLong = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
    int n = 1;
    try {
        c1.setTime(sdfLong.parse(currDate));
        while (n > 0) {
            c1.add(Calendar.DATE, 1);
            if (Arrays.binarySearch(NWD, (c1.get(Calendar.DAY_OF_WEEK) - 1)) > -1
                    || Arrays.binarySearch(CH, sdf.format(c1.getTime())) > -1) {
                n++;
            } else {
                n = 0;
            }
            stdate = c1.getTime();
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("Exception while calculating next working day : " + e.getMessage(), e);
    } finally {
        return sdfLong.format(stdate);
    }
}