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:org.openmrs.module.sync.scheduler.CleanupSyncTablesTask.java

/**
 * Do the actual deleting of tables.//from   w  w  w .  j  a  v  a  2 s. com
 */
public void execute() {
    Context.openSession();
    log.debug("Starting sync table cleanup ... ");
    try {
        if (Context.isAuthenticated() == false)
            authenticate();

        // get the possibly user-defined settings
        Map<String, String> props = null;
        if (taskDefinition != null)
            props = taskDefinition.getProperties();

        Integer daysBack = getIntegerProperty(PROPERTY_DAYS_BACK, props, DEFAULT_DAYS_BACK_TO_START_DELETE);

        Calendar today = Calendar.getInstance();
        today.add(Calendar.DATE, -1 * daysBack);
        Date deleteTo = today.getTime();

        SyncRecordState[] statesToDelete = getSyncRecordStateProperty(PROPERTY_STATES_TO_DELETE, props,
                DEFAULT_STATES_TO_DELETE);

        // do the actual deleting
        SyncService syncService = Context.getService(SyncService.class);
        Integer quantityDeleted = syncService.deleteSyncRecords(statesToDelete, deleteTo);

        log.info("There were " + quantityDeleted + " sync records cleaned out");
    } catch (Throwable t) {
        log.error("Error while doing sync table cleanup", t);
        throw new APIException(t);
    } finally {
        Context.closeSession();
    }
}

From source file:com.eventestimator.mvc.EventController.java

@RequestMapping(value = "/create", method = RequestMethod.GET)
protected String handleRequestInternal(Model model, HttpServletRequest request) throws Exception {

    String accessToken = request.getParameter("access_token");
    String userName = request.getParameter("userName");
    String eventUrl = WS_URL_PREFIX + userName + "/events?access_token=" + accessToken;
    Event event = new Event();
    event.setDescription("Example event");
    event.setName("Sri  " + new Date().toString());
    Calendar startDate = Calendar.getInstance();
    startDate.add(Calendar.DATE, 2);
    event.setStartDate(startDate.getTime());
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, 2);
    event.setEndDate(endDate.getTime());
    event.setEventType("EventType");
    Entry entry = new Entry();
    List<Event> events = new ArrayList<Event>(1);
    events.add(event);//  w w  w.ja  va  2  s  .c  o m
    entry.setContents(events);
    Entry eventResult = restTemplate.postForObject(eventUrl, entry, Entry.class);
    return "contact_list";
}

From source file:helper.util.DateHelper.java

/**
 * Take a local time calendar and represent it as a day
 * (truncate to day, retain yy/mm/dd from original date)
 **//*from   ww  w. j  a  va 2s .  c om*/
public static Calendar asDay(Calendar localTimeCalendar) {
    Calendar asDay = Calendar.getInstance(localTimeCalendar.getTimeZone());
    asDay.clear();
    asDay.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH),
            localTimeCalendar.get(Calendar.DATE), 0, 0, 0);
    asDay.set(Calendar.AM_PM, Calendar.AM);
    asDay.set(Calendar.MILLISECOND, 0);
    asDay.set(Calendar.HOUR, 0);
    return asDay;
}

From source file:com.ourlife.dev.common.utils.DateUtils.java

/**
 * ??//  w  w  w . j a  va  2s. com
 * 
 * @param date
 * @return
 */
public static String[] getDayBeginTimeAndEndTime(String date) {
    String[] dates = new String[2];
    Date beginDate = DateUtils.parseDate(date);
    dates[0] = DateUtils.formatDate(beginDate, "yyyy-MM-dd HH:mm:ss");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(beginDate);
    calendar.add(Calendar.DATE, 1);
    dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
    return dates;
}

From source file:eu.squadd.timesheets.eolas.TimeTemplate.java

public String prepareTimesheet(String[] args) {
    String response = null;/*from   ww  w .ja va 2 s.c  om*/
    try {
        String[] ym = args[0].split("/");
        month = Integer.parseInt(ym[0]);
        year = Integer.parseInt(ym[1]);

        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        monthName = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.ENGLISH);
        String periodName = monthName + "-" + year;
        cal.set(Calendar.DATE, 1);
        String dayOfWeek = new SimpleDateFormat("EE").format(cal.getTime());

        System.out.println("Month: " + periodName);
        System.out.println("Days in month: " + days);
        System.out.println("Month starts in: " + dayOfWeek);

        Map<String, String> bankHolidays = year == 2016 ? publicHolidays2016 : publicHolidays2017;
        Map<String, String> holidays = this.extractHolidays(args);

        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(template));
        HSSFSheet sheet = wb.getSheet("timesheet"); //getSheetAt(0);
        HSSFRow currentRow;
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        sheet.getRow(4).getCell(1).setCellValue(periodName);
        int row = 7;
        int startRow = 0;
        int i = 1;
        while (i <= days) {
            currentRow = sheet.getRow(row);
            if (currentRow.getRowNum() > 47)
                break;
            String day = currentRow.getCell(0).getStringCellValue();

            if (day.startsWith("Total")) {
                evaluator.evaluateFormulaCell(currentRow.getCell(2));
                evaluator.evaluateFormulaCell(currentRow.getCell(4));
                row++;
                continue;
            }

            if (startRow == 0) {
                if (dayOfWeek.equals(day.substring(0, 3))) {
                    startRow = currentRow.getRowNum();
                    System.out.println("Starting row found: " + startRow + 1);
                } else {
                    row++;
                    continue;
                }
            }
            cal.set(Calendar.DATE, i);
            String date = sdf.format(cal.getTime());
            if (!day.equals("Saturday") && !day.equals("Sunday") && bankHolidays.get(date) == null
                    && holidays.get(date) == null) {
                currentRow.getCell(1).setCellValue(date);
                currentRow.getCell(2).setCellValue(defaultHours); // regular hours
                //currentRow.getCell(3).setCellValue(defaultHours);   // overtime hours
                currentRow.getCell(4).setCellValue(defaultHours); // total hours                    
            }
            i++;
            row++;
        }
        currentRow = sheet.getRow(46);
        evaluator.evaluateFormulaCell(currentRow.getCell(2));
        evaluator.evaluateFormulaCell(currentRow.getCell(4));
        currentRow = sheet.getRow(47);
        evaluator.evaluateFormulaCell(currentRow.getCell(2));
        evaluator.evaluateFormulaCell(currentRow.getCell(4));
        response = outFilePath.replace("#MONTH#", periodName);
        wb.write(new FileOutputStream(response));

    } catch (IOException ex) {
        Logger.getLogger(Timesheets.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Timesheet created.");
    return response;
}

From source file:com.ubipass.middleware.web.action.LicenceMgtAction.java

/**
 * Action of display licence management page.
 * /*w  w w .  j  a  v  a 2 s.co  m*/
 * @param mapping
 *            ActionMapping
 * @param form
 *            ActionForm
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 * @return ActionForward forward to Struts page
 * @throws Exception
 * @see org.apache.struts.action.Action
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    request.getSession().setAttribute("page", "0,2");

    File file = new File(this.getServlet().getServletContext().getRealPath("/" + LICENCE_FILE));
    FileInputStream is;
    String userName = "";
    String licenceKey = "";
    String ExperDate = "0000-00-00";
    try {
        is = new FileInputStream(file);

        Properties properties = new Properties();
        properties.load(is);

        userName = properties.getProperty("userName");
        licenceKey = properties.getProperty("licenceKey");

        ExperDate = getDate(userName, licenceKey);
        Calendar cal = Calendar.getInstance();

        try {
            cal.setTimeInMillis(Long.parseLong(ExperDate));

            ExperDate = String.valueOf(cal.get(Calendar.YEAR)) + "-" + strReformat(cal.get(Calendar.MONTH) + 1)
                    + "-" + strReformat(cal.get(Calendar.DATE));

        } catch (Exception e) {
            ExperDate = "0000-00-00";
        }

        request.setAttribute("userName", userName);
        request.setAttribute("ExperDate", ExperDate);
        request.setAttribute("licenceKey", licenceKey);

        is.close();

        return mapping.findForward("Successful");
    } catch (Exception e) {
        request.setAttribute("error", "error");
        request.setAttribute("userName", userName);
        request.setAttribute("ExperDate", ExperDate);
        request.setAttribute("licenceKey", licenceKey);
        return mapping.findForward("Successful");
    }
}

From source file:com.mortgage.serial.LicenseService.java

private Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   w  w w.  j  av a 2  s .  c o m
    cal.add(Calendar.DATE, days); // minus number would decrement the days
    return cal.getTime();
}

From source file:org.openmrs.module.kenyaemr.reporting.builder.hiv.DecliningCd4ReportBuilderTest.java

@Test
public void testReport() throws Exception {
    Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV);

    // Enrol patient #7 in the HIV program
    TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram, new Date());

    // Give patient #7 a CD4 count 180 days ago
    Concept cd4 = Dictionary.getConcept(Dictionary.CD4_COUNT);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -180);
    TestUtils.saveObs(TestUtils.getPatient(7), cd4, 123d, calendar.getTime());

    // Give patient #7 a lower CD4 now
    TestUtils.saveObs(TestUtils.getPatient(7), cd4, 120d, new Date());

    Context.flushSession();//from ww  w. j  av a 2  s .c  om

    // Evaluate report
    ReportDefinition rd = reportBuilder.build(report);
    EvaluationContext ec = new EvaluationContext();

    ReportData data = Context.getService(ReportDefinitionService.class).evaluate(rd, ec);

    ReportingTestUtils.checkStandardCohortReport(Collections.singleton(7), data);
    //ReportingTestUtils.printReport(data);
}

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

@Test(enabled = true)
public void Test() {
    dateServ = ctx.getBean(ViewListingByDateOfBirthService.class);
    repoList = ctx.getBean(PublishedDeceasedListingRepository.class);
    subRepo = ctx.getBean(SubscriberRepository.class);
    userRepo = ctx.getBean(UserRoleRepository.class);

    //Initialise date
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2001);
    calendar.set(Calendar.MONTH, Calendar.MARCH);
    calendar.set(Calendar.DATE, 17);

    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("jGordan@gmail.com").setFirstName("james")
            .setSurname("gordan").setPwd("gotham").setUsername("commish").setSubscriptionDate(javaSqlDate)
            .setUserRoleID(userRole).build();
    subRepo.save(newSub);//from   w w  w.j av  a  2  s.  c  o m
    subID = newSub.getSubscriberID();

    PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Dean")
            .setSurname("Winchester")

            .setGender("Male").setDateOfBirth("27/07/1985").setDateOfDeath("14/10/2014")
            .setGraveInscription("will probably come back").setGraveNumber("2474")
            .setImageOfBurialSite("/images/004.jpg").setLastKnownContactName("sam")
            .setLastKnownContactNumber("07255718927")

            .setSubscriberSubmitID(subID).build();

    repoList.save(newListing);
    listingId = newListing.getPublishedListingID();

    List<PublishedDeceasedListing> pubListDob = dateServ.findListingByDOB("27/07/1985");
    Assert.assertFalse(pubListDob.isEmpty());
    repoList.delete(listingId);
    subRepo.delete(subID);

}

From source file:com.reizes.shiva.utils.CommonUtil.java

/**
 * ?    ?  ? ?. ? 00:00:00  /*from www .jav a  2  s  .co  m*/
 * adjustAmount ? -?  + ? ?, 0 ?  ?  
 */
public static Date getAdjustDayResetTime(Date date, int adjustAmount) {
    if (date == null) {
        return null;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.add(Calendar.DATE, adjustAmount);
    return cal.getTime();
}