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.clinicalsummary.web.controller.service.LocationCohortController.java

@RequestMapping(method = RequestMethod.GET)
public void searchCohort(@RequestParam(required = false, value = "username") String username,
        @RequestParam(required = false, value = "password") String password,
        @RequestParam(required = true, value = "locationId") Integer locationId,
        @RequestParam(required = true, value = "summaryId") Integer summaryId, HttpServletResponse response)
        throws IOException {

    try {/*w  ww .  j av  a  2  s .c om*/
        if (!Context.isAuthenticated())
            Context.authenticate(username, password);

        String cohortTimeFrame = Context.getAdministrationService()
                .getGlobalProperty(CLINICALSUMMARY_SERVICE_TIMEFRAME);
        Integer timeFrame = NumberUtils.toInt(cohortTimeFrame, 5);

        Location location = Context.getLocationService().getLocation(locationId);
        Summary summary = Context.getService(SummaryService.class).getSummary(summaryId);

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -timeFrame);
        Date startDate = calendar.getTime();

        calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, timeFrame);
        Date endDate = calendar.getTime();

        List<Index> indexes = Context.getService(IndexService.class).getIndexes(location, summary, startDate,
                endDate);

        Set<Patient> patients = new HashSet<Patient>();
        for (Index index : indexes) {
            Patient patient = index.getPatient();
            if (CollectionUtils.isNotEmpty(patient.getIdentifiers()))
                patients.add(index.getPatient());
        }

        // serialize the the search result
        XStream xStream = new XStream();
        xStream.alias("results", Set.class);
        xStream.alias("patient", Patient.class);
        xStream.registerConverter(new PatientConverter());
        xStream.registerConverter(new PatientIdentifierConverter());
        xStream.registerConverter(new PersonNameConverter());
        xStream.toXML(patients, response.getOutputStream());
    } catch (ContextAuthenticationException e) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
* ?/*from  www .j a v a2  s.  c  om*/
* 
*/
public static List getEndWeekDate(Date startDate, Date endDate, SimpleDateFormat sdf) {

    Calendar cal = Calendar.getInstance();
    int days = getDaysBetween(startDate, endDate);
    List list = new ArrayList<String>();
    for (int i = 1; i < days; i++) {
        startDate = getNextDay(startDate);
        cal.setTime(startDate);
        // ?????
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// ?
        if (1 == dayWeek) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        cal.setFirstDayOfWeek(Calendar.MONDAY);// 
        int day = cal.get(Calendar.DAY_OF_WEEK);// ?
        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);// ???
        String imptimeBegin = sdf.format(cal.getTime());
        cal.add(Calendar.DATE, 6);
        String imptimeEnd = sdf.format(cal.getTime());
        list.add(imptimeEnd);
    }
    // ??
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        Object element = iter.next();

        if (set.add(element))
            newList.add(element);
    }
    list.clear();
    list.addAll(newList);

    return newList;
}

From source file:at.alladin.rmbt.statisticServer.UsageJSONResource.java

@Get("json")
public String request(final String entity) {
    JSONObject result = new JSONObject();
    int month = -1;
    int year = -1;
    try {//ww  w.j a v  a  2 s.com
        //parameters
        final Form getParameters = getRequest().getResourceRef().getQueryAsForm();
        try {

            if (getParameters.getNames().contains("month")) {
                month = Integer.parseInt(getParameters.getFirstValue("month"));
                if (month > 11 || month < 0) {
                    throw new NumberFormatException();
                }
            }
            if (getParameters.getNames().contains("year")) {
                year = Integer.parseInt(getParameters.getFirstValue("year"));
                if (year < 0) {
                    throw new NumberFormatException();
                }
            }
        } catch (NumberFormatException e) {
            return "invalid parameters";
        }

        Calendar now = new GregorianCalendar();
        Calendar monthBegin = new GregorianCalendar((year > 0) ? year : now.get(Calendar.YEAR),
                (month >= 0) ? month : now.get(Calendar.MONTH), 1);
        Calendar monthEnd = new GregorianCalendar((year > 0) ? year : now.get(Calendar.YEAR),
                (month >= 0) ? month : now.get(Calendar.MONTH),
                monthBegin.getActualMaximum(Calendar.DAY_OF_MONTH));
        //if now -> do not use the last day
        if (month == now.get(Calendar.MONTH) && year == now.get(Calendar.YEAR)) {
            monthEnd = now;
            monthEnd.add(Calendar.DATE, -1);
        }

        JSONObject platforms = getPlatforms(new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject usage = getClassicUsage(new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject versionsIOS = getVersions("iOS", new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject versionsAndroid = getVersions("Android", new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject versionsApplet = getVersions("Applet", new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject networkGroupNames = getNetworkGroupName(new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        JSONObject networkGroupTypes = getNetworkGroupType(new Timestamp(monthBegin.getTimeInMillis()),
                new Timestamp(monthEnd.getTimeInMillis()));
        result.put("platforms", platforms);
        result.put("usage", usage);
        result.put("versions_ios", versionsIOS);
        result.put("versions_android", versionsAndroid);
        result.put("versions_applet", versionsApplet);
        result.put("network_group_names", networkGroupNames);
        result.put("network_group_types", networkGroupTypes);
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result.toString();
}

From source file:gob.dp.simco.comun.FunctionUtil.java

public static Calendar ponerAnioMesActual(Date fecha, Date fechaActual) {
    try {// ww w  . j  a  va 2s .c  o  m
        Calendar cActual = Calendar.getInstance();
        cActual.setTime(fechaActual);
        Calendar cfecha = Calendar.getInstance();
        cfecha.setTime(fecha);
        //la fecha nueva
        Calendar c1 = Calendar.getInstance();
        c1.set(cActual.get(Calendar.YEAR), cActual.get(Calendar.MONTH), cfecha.get(Calendar.DATE));
        return c1;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.linuxbox.enkive.imap.mongo.MongoImapAccountCreator.java

public void createImapAccount(String username) throws MessageSearchException {
    HashMap<String, String> mailboxTable = new HashMap<String, String>();

    Date earliestMessageDate = searchService.getEarliestMessageDate(username);
    Date latestMessageDate = searchService.getLatestMessageDate(username);

    Calendar latestMessageCalendar = Calendar.getInstance();
    latestMessageCalendar.setTime(latestMessageDate);
    DateUtils.round(latestMessageCalendar, Calendar.DATE);
    Calendar today = Calendar.getInstance();
    DateUtils.round(today, Calendar.DATE);
    if (latestMessageCalendar.equals(today)) {
        latestMessageCalendar.add(Calendar.DATE, -1);
        latestMessageDate = latestMessageCalendar.getTime();
    }/*from w  ww . j a  v a2 s .c o  m*/

    // Setup Trash and Inbox
    BasicDBObject inboxObject = new BasicDBObject();
    String inboxPath = "INBOX";
    inboxObject.put(MongoEnkiveImapConstants.MESSAGEIDS, new HashMap<String, String>());
    imapCollection.insert(inboxObject);
    ObjectId inboxId = (ObjectId) inboxObject.get("_id");
    mailboxTable.put(inboxPath, inboxId.toString());

    BasicDBObject trashObject = new BasicDBObject();
    String trashPath = "Trash";
    trashObject.put(MongoEnkiveImapConstants.MESSAGEIDS, new HashMap<String, String>());
    imapCollection.insert(trashObject);
    ObjectId trashId = (ObjectId) inboxObject.get("_id");
    mailboxTable.put(trashPath, trashId.toString());

    BasicDBObject rootMailboxObject = new BasicDBObject();
    imapCollection.insert(rootMailboxObject);
    ObjectId id = (ObjectId) rootMailboxObject.get("_id");
    BasicDBObject userMailboxesObject = new BasicDBObject();
    userMailboxesObject.put(MongoEnkiveImapConstants.USER, username);
    mailboxTable.put(MongoEnkiveImapConstants.ARCHIVEDMESSAGESFOLDERNAME, id.toString());

    userMailboxesObject.put(MongoEnkiveImapConstants.MAILBOXES, mailboxTable);
    imapCollection.insert(userMailboxesObject);

    addImapMessages(username, earliestMessageDate, latestMessageDate);
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducerarchive.service.daemon.ZipCleanerDaemon.java

/**
 * Daemon's treatment method/*  w  w  w .  j a v  a 2 s .co m*/
 */
public void run() {
    StringBuilder sbLog = new StringBuilder();
    Plugin plugin = PluginService.getPlugin(DirectoryPDFProducerPlugin.PLUGIN_NAME);
    int nExpirationDays = AppPropertiesService.getPropertyInt(PROPERTY_DAEMON_NB_EXPIRATION_DAYS, 7);
    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.DATE, -nExpirationDays);

    for (ZipBasket zipBasket : _manageZipBasketService.loadZipBasketByDate(plugin, calendar.getTime())) {
        if (zipBasket != null) {
            sbLog.append("\n- Cleaning archive '" + zipBasket.getZipName() + " (ID : " + zipBasket.getIdZip()
                    + ")'");
            _manageZipBasketService.deleteZipBasket(plugin, zipBasket.getIdZip(),
                    Integer.toString(zipBasket.getIdRecord()), sbLog);
        }
    }

    if (StringUtils.isBlank(sbLog.toString())) {
        sbLog.append("\nNo archive to clean");
    }

    setLastRunLogs(sbLog.toString());
}

From source file:com.qdum.llhb.common.utils.DateUtils.java

/**
 * ?/*from ww  w.  jav  a 2s .  c o m*/
 *
 * @param d
 * @param day
 * @return
 */
public static Date getDateBefore(Date d, int day) {
    Calendar now = Calendar.getInstance();
    now.setTime(d);
    now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
    return now.getTime();
}

From source file:cvr.vist.stat.comps.DateFilterArea.java

public Date getDateBegin() {

    return DateUtils.truncate(dateFrom.getValue(), Calendar.DATE);
}

From source file:net.sourceforge.eclipsetrader.trading.DataCollector.java

public void update(Observable o, Object arg) {
    Security security = (Security) arg;
    Quote quote = security.getQuote();//from   w w w.  jav  a  2  s . c o m

    if (!security.isEnableDataCollector() || 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)) {
            data.history.add(data.bar);

            if (security.getKeepDays() != 0) {
                Calendar keepLimit = Calendar.getInstance();
                keepLimit.setTime(data.bar.getDate());
                keepLimit.set(Calendar.HOUR, 0);
                keepLimit.set(Calendar.MINUTE, 0);
                keepLimit.set(Calendar.SECOND, 0);
                keepLimit.set(Calendar.MILLISECOND, 0);
                keepLimit.add(Calendar.DATE, -security.getKeepDays());

                Date limit = keepLimit.getTime();
                while (data.history.size() > 0 && ((Bar) data.history.get(0)).getDate().before(limit))
                    data.history.remove(0);
            }

            try {
                log.trace("Notifying intraday data updated for " + security.getCode() + " - "
                        + security.getDescription());
                data.history.notifyObservers();
                data.changes++;
                if (data.changes >= changes) {
                    CorePlugin.getRepository().save(data.history);
                    data.changes = 0;
                }
            } catch (Exception e) {
                log.error(e, 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);
    }

    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.cemeterylistingswebtest.test.domain.SubscriberTest.java

@Test(dependsOnMethods = "read")
public void testDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DATE, 4);
    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());
    repo = ctx.getBean(SubscriberRepository.class);

    Calendar cal = Calendar.getInstance();
    cal.setTime(javaSqlDate);// w  ww . j a va  2 s .  c o  m
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DAY_OF_MONTH);
    Assert.assertEquals(year, 2008);
    Assert.assertEquals(month, 01); //counts from 0
    Assert.assertEquals(day, 4);
}