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:com.hangame.tera.action.event.TeraAttendenceLondonEventAction.java

/**
 * ?./*from  ww w. j  a v  a2 s .  c om*/
 *
 * @return the string
 * @throws Exception the exception
 */
@Override
public String execute() throws Exception {

    if (!getUser().isLoggedin()) {
        setAttribute("MACBOOK", 0);
        setAttribute("GRAPHICCARD", 0);
        setAttribute("MUNSANG", 0);
        setAttribute("HANCOIN", 0);
        return SUCCESS;
    }

    CommonUser currentUser = (CommonUser) getUser();

    String memberId = currentUser.getMemberid();
    String memberNo = currentUser.getMemberno();

    try {
        List<DataMap> listDays = teraEventNewBO.selectUserAttendenceDays(memberId);

        int allPoint = 0;
        int usePoint = 0;
        try {
            usePoint = teraEventNewBO.selectUserAttendenceUsePoint(memberId);
        } catch (Exception e) {
            LOG.debug("? ? ?? ", e);
        }

        LinkedHashMap<Integer, Integer> mapDays = new LinkedHashMap<Integer, Integer>();

        allPoint = setMapDays(listDays, mapDays);

        setEnterInfo(memberId);

        Calendar todayCal = Calendar.getInstance();

        int todayD = todayCal.get(Calendar.DATE);

        setAttribute("today", todayD);
        setAttribute("attendenceDays", mapDays);
        setAttribute("allPoint", allPoint);
        setAttribute("usePoint", usePoint);
        setAttribute("availablePoint", ((allPoint - usePoint) < 0 ? 0 : (allPoint - usePoint)));
    } catch (Exception e) {
        LOG.error("?? list   memberId : " + memberId + " memberNo : " + memberNo, e);
    }

    return SUCCESS;
}

From source file:org.createnet.raptor.db.couchbase.CouchbaseConnection.java

@Override
public void set(String id, JsonNode data, int ttlDays) {

    JsonObject obj = JsonObject.fromJson(data.toString());

    int ttl = ttlDays;
    if (ttlDays > 0) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, ttlDays);
        ttl = (int) (c.getTime().getTime() / 1000);
    }//from  www . j a  va  2  s. co  m

    JsonDocument doc = JsonDocument.create(id, ttl, obj);
    bucket.upsert(doc);
}

From source file:cn.mypandora.util.MyDateUtils.java

/**
 * //from ww  w.  j  a  v  a 2s .co m
 *
 * @return
 */
public static String getPreviousMonthFirst() {
    Calendar cal = Calendar.getInstance();
    Calendar f = (Calendar) cal.clone();
    f.clear();
    // 
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
    // f.set(Calendar.DATE, 1);
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // 
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DATE));
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // (?)
    cal.set(Calendar.DATE, 1);// ?1?
    cal.add(Calendar.MONTH, -1);
    return DateFormatUtils.format(cal, DATE_FORMAT);
}

From source file:Main.java

/**
 * Check if the given dates match on day and month.
 *
 * @param cal//from w w w .j a v  a 2 s  . c o m
 *            The Calendar representing the first date.
 * @param other
 *            The Calendar representing the second date.
 * @return true if they match, false otherwise.
 */
private static boolean checkDate(Calendar cal, Calendar other) {
    return checkDate(cal, other.get(Calendar.DATE), other.get(Calendar.MONTH));
}

From source file:net.groupbuy.controller.admin.SalesController.java

/**
 * //w ww.java2s.  co  m
 */
@RequestMapping(value = "/view", method = RequestMethod.GET)
public String view(Type type, Date beginDate, Date endDate, Model model) {
    if (type == null) {
        type = Type.month;
    }
    if (beginDate == null) {
        beginDate = DateUtils.addMonths(new Date(), -11);
    }
    if (endDate == null) {
        endDate = new Date();
    }
    Map<Date, BigDecimal> salesAmountMap = new LinkedHashMap<Date, BigDecimal>();
    Map<Date, Integer> salesVolumeMap = new LinkedHashMap<Date, Integer>();
    Calendar beginCalendar = DateUtils.toCalendar(beginDate);
    Calendar endCalendar = DateUtils.toCalendar(endDate);
    int beginYear = beginCalendar.get(Calendar.YEAR);
    int endYear = endCalendar.get(Calendar.YEAR);
    int beginMonth = beginCalendar.get(Calendar.MONTH);
    int endMonth = endCalendar.get(Calendar.MONTH);
    for (int year = beginYear; year <= endYear; year++) {
        if (salesAmountMap.size() >= MAX_SIZE) {
            break;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        if (type == Type.year) {
            calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH));
            calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
            calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
            calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
            calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
            Date begin = calendar.getTime();
            calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
            calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
            calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
            calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
            calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
            Date end = calendar.getTime();
            BigDecimal salesAmount = orderService.getSalesAmount(begin, end);
            Integer salesVolume = orderService.getSalesVolume(begin, end);
            salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO);
            salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0);
        } else {
            for (int month = year == beginYear ? beginMonth
                    : calendar.getActualMinimum(Calendar.MONTH); month <= (year == endYear ? endMonth
                            : calendar.getActualMaximum(Calendar.MONTH)); month++) {
                if (salesAmountMap.size() >= MAX_SIZE) {
                    break;
                }
                calendar.set(Calendar.MONTH, month);
                calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
                calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
                calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
                calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
                Date begin = calendar.getTime();
                calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
                calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
                calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
                calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
                Date end = calendar.getTime();
                BigDecimal salesAmount = orderService.getSalesAmount(begin, end);
                Integer salesVolume = orderService.getSalesVolume(begin, end);
                salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO);
                salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0);
            }
        }
    }
    model.addAttribute("types", Type.values());
    model.addAttribute("type", type);
    model.addAttribute("beginDate", beginDate);
    model.addAttribute("endDate", endDate);
    model.addAttribute("salesAmountMap", salesAmountMap);
    model.addAttribute("salesVolumeMap", salesVolumeMap);
    return "/admin/sales/view";
}

From source file:org.ala.util.BieAccessLogReader.java

protected void processLine(String aLine, String url) throws Exception {
    String month = "";
    ctr++;/*from  ww w. ja v a2  s  .  c  om*/
    if (aLine != null && aLine.indexOf('[') + 1 < aLine.indexOf(']')) {
        String timestamp = aLine.substring(aLine.indexOf('[') + 1, aLine.indexOf(']'));
        Date date = (Date) formatter.parse(timestamp);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int mth = cal.get(Calendar.MONTH) + 1;
        month = cal.get(Calendar.YEAR) + "" + (mth > 9 ? "" + mth : "0" + mth) + ""
                + (cal.get(Calendar.DATE) > 9 ? "" + cal.get(Calendar.DATE) : "0" + cal.get(Calendar.DATE));
    }

    if (aLine != null && aLine.contains("GET /repo/")) {
        String tmp = aLine.substring(aLine.indexOf("GET /repo/") + "GET /repo/".length());
        String repo = tmp.substring(0, tmp.indexOf('/'));

        addImageSourceMap(repo);
    } else {
        if (!recordCounts.isEmpty()) {
            //send message to logger service
            sendLoggerMessage(url, month);
            recordCounts.clear();
        }
    }
}

From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataFormEntryOverviewController.java

@RequestMapping("/module/facilitydata/formEntryOverview.form")
public void formEntryOverview(ModelMap map, @RequestParam(required = true) FacilityDataForm form,
        @RequestParam(required = false) Integer yearIncrement,
        @RequestParam(required = false) Integer monthIncrement) throws Exception {

    FacilityDataService service = Context.getService(FacilityDataService.class);

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 1);

    if (yearIncrement != null) {
        cal.add(Calendar.YEAR, yearIncrement);
    }/*from  w w  w .  j a  va  2s.co m*/
    if (monthIncrement != null) {
        cal.add(Calendar.DATE, monthIncrement * 21);
    }

    if (form.getFrequency() == Frequency.MONTHLY) {
        cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
    }

    Date endDate = cal.getTime();
    if (form.getFrequency() == Frequency.MONTHLY) { // For monthly reports, display last year
        cal.set(Calendar.DATE, 1);
        cal.add(Calendar.YEAR, -1);
    } else if (form.getFrequency() == Frequency.DAILY) { // For daily reports, display last 3 weeks
        cal.add(Calendar.DATE, -21);
    } else {
        throw new RuntimeException("Unable to handle a report with frequency: " + form.getFrequency());
    }
    Date startDate = cal.getTime();

    Map<Integer, Map<String, Integer>> questionsAnswered = service.getNumberOfQuestionsAnswered(form, startDate,
            endDate);

    DateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
    DateFormat monthFormat = new SimpleDateFormat("MMM");
    List<Integer> daysOfWeekSupported = FacilityDataConstants.getDailyReportDaysOfWeek();

    Map<Integer, Integer> yearCols = new LinkedHashMap<Integer, Integer>(); // Year -> Number of columns
    Map<String, Integer> monthCols = new LinkedHashMap<String, Integer>(); // Month -> Number of columns
    Map<String, Date> dayCols = new LinkedHashMap<String, Date>();
    Map<Integer, Map<String, Integer>> dayData = new HashMap<Integer, Map<String, Integer>>(); // LocationId -> Day -> Number of questions
    Map<Object, String> displayKeys = new HashMap<Object, String>(); // Map key -> Display format
    Set<String> datesSupported = new HashSet<String>(); // Dates support entry

    while (cal.getTime().before(endDate)) {

        String dateStr = ymdFormat.format(cal.getTime());
        Integer year = cal.get(Calendar.YEAR);
        String month = monthFormat.format(cal.getTime());
        Integer day = cal.get(Calendar.DAY_OF_MONTH);

        yearCols.put(year, yearCols.get(year) == null ? 1 : yearCols.get(year) + 1);
        monthCols.put(year + month, monthCols.get(year + month) == null ? 1 : monthCols.get(year + month) + 1);
        dayCols.put(dateStr, cal.getTime());

        if (form.getFrequency() == Frequency.MONTHLY
                || daysOfWeekSupported.contains(cal.get(Calendar.DAY_OF_WEEK))) {
            datesSupported.add(dateStr);
        }

        for (Integer locationId : questionsAnswered.keySet()) {
            Map<String, Integer> questionsAnsweredAtLocation = questionsAnswered.get(locationId);
            Integer numAnswered = questionsAnsweredAtLocation == null ? null
                    : questionsAnsweredAtLocation.get(dateStr);
            Map<String, Integer> locationData = dayData.get(locationId);
            if (locationData == null) {
                locationData = new HashMap<String, Integer>();
                dayData.put(locationId, locationData);
            }
            locationData.put(dateStr, numAnswered == null ? 0 : numAnswered);
        }

        displayKeys.put(year, year.toString());
        displayKeys.put(year + month, month);
        displayKeys.put(dateStr, day.toString());

        cal.add(form.getFrequency().getCalendarField(), form.getFrequency().getCalendarIncrement());
    }

    Map<FacilityDataFormSchema, Integer> numQuestionsBySchema = new HashMap<FacilityDataFormSchema, Integer>();
    for (FacilityDataFormSchema schema : form.getSchemas()) {
        numQuestionsBySchema.put(schema, schema.getTotalNumberOfQuestions());
    }

    map.addAttribute("today", new Date());
    map.addAttribute("form", form);
    map.addAttribute("yearIncrement", yearIncrement);
    map.addAttribute("monthIncrement", monthIncrement);
    map.addAttribute("yearCols", yearCols);
    map.addAttribute("monthCols", monthCols);
    map.addAttribute("dayCols", dayCols);
    map.addAttribute("dayData", dayData);
    map.addAttribute("displayKeys", displayKeys);
    map.addAttribute("numQuestionsBySchema", numQuestionsBySchema);
    map.addAttribute("questionsAnswered", questionsAnswered);
    map.addAttribute("locations", FacilityDataConstants.getSupportedFacilities());
    map.addAttribute("datesSupported", datesSupported);
}

From source file:cat.albirar.framework.utilities.DatesUtilities.java

/**
 * Compare two dates, with care of null. The time part of both dates are ignored (from hour and bellow)
 * /*www.j ava2s.co  m*/
 * @param d1 The first date
 * @param d2 The second date
 * @return Zero if both are equals (even if both are nulls), a number less than zero if d1 is minor than d2 and a
 *         number greater than zero if d1 is greater than d2.
 * @see DateUtils#truncatedCompareTo(Calendar, Calendar, int)
 */
public static final int nullSafeCompareDate(Date d1, Date d2) {
    if (d1 == null || d2 == null) {
        if (d1 == d2) {
            return 0;
        }
        if (d1 == null) {
            return -1;
        }
        return 1;
    }
    return DateUtils.truncatedCompareTo(d1, d2, Calendar.DATE);
}

From source file:edu.stanford.muse.email.Filter.java

/** takes current date and converts it to something like 20130709 for July 9 2013 */
private static String dateToString(Date d) {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(d);/*from  w ww.j  a  va 2  s . c om*/
    int yyyy = c.get(Calendar.YEAR);
    int mm = c.get(Calendar.MONTH) + 1; // rememeber + 1 adj cos calendar is 0 based
    int dd = c.get(Calendar.DATE);
    return String.format("%04d", yyyy) + String.format("%02d", mm) + String.format("%02d", dd);
}

From source file:org.esupportail.twitter.web.MinimizedStateHandlerInterceptor.java

@Override
public boolean preHandleRender(RenderRequest request, RenderResponse response, Object handler)
        throws Exception {

    if (WindowState.MINIMIZED.equals(request.getWindowState())) {

        log.debug("preHandleRender");

        int newCount = 0;

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);

        final PortletPreferences prefs = request.getPreferences();
        String twitterUsername = prefs.getValue(PREF_TWITTER_USERNAME, DEFAULT_TWITTER_USERNAME);

        String applicationOnlyBearerToken = oAuthTwitterApplicationOnlyService.getApplicationOnlyBearerToken();

        String twitterUserToken = prefs.getValue(PREF_TWITTER_USER_TOKEN, null);
        String twitterUserSecret = prefs.getValue(PREF_TWITTER_USER_SECRET, null);

        int tweetsNumber = (new Integer(prefs.getValue(PREF_TWITTER_TWEETS_NUMBER, "-1"))).intValue();

        // get username timeline with oAuth authentication
        log.debug("twitterUserToken:" + twitterUserToken);
        log.debug("twitterUserSecret:" + twitterUserSecret);

        Twitter twitter;/*from  w  ww .j a  v  a  2 s  .  c o m*/
        List<Tweet> tweetList;

        if (twitterUserToken != null && twitterUserSecret != null) {
            twitter = new TwitterTemplate(oAuthTwitterConfig.getConsumerKey(),
                    oAuthTwitterConfig.getConsumerSecret(), twitterUserToken, twitterUserSecret);
            tweetList = twitter.timelineOperations().getHomeTimeline(tweetsNumber);
        } else {
            twitter = new TwitterTemplate(applicationOnlyBearerToken);
            tweetList = twitter.timelineOperations().getUserTimeline(twitterUsername, tweetsNumber);
        }

        for (Tweet tweet : tweetList) {
            if (tweet.getCreatedAt().getTime() > cal.getTime().getTime()) {
                newCount++;
            }
        }

        response.setProperty("newItemCount", String.valueOf(newCount));
        log.debug("newItemCount:" + newCount);
        return false;
    }

    return true;
}