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:org.spring.data.gemfire.cache.UserDataStoreCacheLoader.java

protected static Calendar createCalendar(final int year, final int month, final int dayOfMonth,
        final int hourOfDay, final int minute, final int second) {
    Calendar dateTime = Calendar.getInstance();

    dateTime.clear();//from   www  . ja v  a2  s .c  om
    dateTime.set(Calendar.YEAR, year);
    dateTime.set(Calendar.MONTH, month);
    dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    dateTime.set(Calendar.HOUR_OF_DAY, dayOfMonth);
    dateTime.set(Calendar.MINUTE, minute);
    dateTime.set(Calendar.SECOND, second);

    return dateTime;
}

From source file:com.sammyun.util.DateUtil.java

/**
 * ?//from w w w.  j a  va 2s .  co m
 * 
 * @param dateString String
 * @return int
 * @throws ParseException
 */
public static int getWeekDays(Date date) throws ParseException {
    Calendar calendar = DateUtils.toCalendar(date);
    int year = getYear(date);
    int month = getMonth(date);
    int maxDay = calendar.get(Calendar.DAY_OF_MONTH);
    int days = 0;
    // ??
    if (isEqualYM(date)) {
        for (int day = 1; day < maxDay; day++) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date datestr = simpleDateFormat.parse(year + "-" + month + "-" + day);
            Calendar c = Calendar.getInstance();
            c.setTime(datestr);
            if (c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7) {
                days++;
            }
        }
    } else {
        for (int day = 1; day <= maxDay; day++) {

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date datestr = simpleDateFormat.parse(year + "-" + month + "-" + day);
            Calendar c = Calendar.getInstance();
            c.setTime(datestr);
            if (c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7) {
                days++;
            }
        }
    }
    return days;
}

From source file:be.fedict.eid.idp.model.applet.SecureCardReaderServiceBean.java

@Override
public String getTransactionMessage() {
    Boolean transactionMessageSigning = this.configuration.getValue(ConfigProperty.TRANSACTION_MESSAGE_SIGNING,
            Boolean.class);
    if (null == transactionMessageSigning) {
        return null;
    }/*from w ww.  j  a va  2  s  . c  o m*/
    if (Boolean.FALSE.equals(transactionMessageSigning)) {
        return null;
    }
    RPEntity relyingPartyEntity = AppletUtil.getSessionAttribute(Constants.RP_SESSION_ATTRIBUTE);
    String applicationName;
    if (null != relyingPartyEntity) {
        applicationName = relyingPartyEntity.getName();
    } else {
        applicationName = AppletUtil.getSessionAttribute(Constants.RP_DOMAIN_SESSION_ATTRIBUTE);
    }
    Calendar calendar = Calendar.getInstance();
    String transactionMessage = applicationName + " @ " + calendar.get(Calendar.DAY_OF_MONTH) + "/"
            + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR) + " "
            + calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":"
            + calendar.get(Calendar.SECOND);
    LOG.debug("transaction message: " + transactionMessage);
    return transactionMessage;
}

From source file:org.openmrs.module.pharmacyapi.api.prescription.util.NewPrescriptionItemGenerator.java

private Date getExpirationDateMinus2Days(final PrescriptionItem item) {

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(item.getDrugOrder().getEncounter().getDateCreated());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, 10);

    while ((calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            || (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {

        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }//w  w w .  j  av a2 s .  co m

    return calendar.getTime();
}

From source file:ru.org.linux.auth.BanIPController.java

@RequestMapping(value = "/banip.jsp", method = RequestMethod.POST)
public ModelAndView banIP(HttpServletRequest request, @RequestParam("ip") String ip,
        @RequestParam("reason") String reason, @RequestParam("time") String time,
        @RequestParam(value = "allow_posting", required = false, defaultValue = "false") boolean allowPosting,
        @RequestParam(value = "captcha_required", required = false, defaultValue = "false") boolean captchaRequired)
        throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
        throw new IllegalAccessException("Not authorized");
    }//from ww  w. j av  a 2  s.  c  o  m

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

    if ("hour".equals(time)) {
        calendar.add(Calendar.HOUR_OF_DAY, 1);
    } else if ("day".equals(time)) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    } else if ("month".equals(time)) {
        calendar.add(Calendar.MONTH, 1);
    } else if ("3month".equals(time)) {
        calendar.add(Calendar.MONTH, 3);
    } else if ("6month".equals(time)) {
        calendar.add(Calendar.MONTH, 6);
    } else if ("remove".equals(time)) {
    } else if ("custom".equals(time)) {
        int days = ServletRequestUtils.getRequiredIntParameter(request, "ban_days");

        if (days <= 0 || days > 180) {
            throw new UserErrorException("Invalid days count");
        }

        calendar.add(Calendar.DAY_OF_MONTH, days);
    }

    Timestamp ts;
    if ("unlim".equals(time)) {
        ts = null;
    } else {
        ts = new Timestamp(calendar.getTimeInMillis());
    }

    User user = tmpl.getCurrentUser();

    user.checkCommit();

    ipBlockDao.blockIP(ip, user, reason, ts, allowPosting, captchaRequired);

    return new ModelAndView(new RedirectView("sameip.jsp?ip=" + URLEncoder.encode(ip, "UTF-8")));
}

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

public String prepareTimesheet(String[] args) {
    String response = null;//from   w w  w  . ja  v a  2  s  . co  m
    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:net.ceos.project.poi.annotated.bean.UniqueDecoratorObjectBuilder.java

/**
 * Validate the UniqueDecoratorObject based on the object build with the method
 * 'buildUniqueDecoratorObject'//from   w  ww  .j  av a  2  s.c  om
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validateUniqueDecoratorObject(UniqueDecoratorObject toValidate) {
    UniqueDecoratorObject base = buildUniqueDecoratorObject();

    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());
}

From source file:com.pureinfo.tgirls.servlet.NormalRandomEventMsg.java

public void createEvent(User loginUser) throws ServletException, IOException {
    if (loginUser == null) {
        return;//from   w  w  w.  j a va 2s .  co m
    }

    Calendar now = Calendar.getInstance();
    int m = now.get(Calendar.MONTH);
    int d = now.get(Calendar.DAY_OF_MONTH);

    List<RandomEvent> todayEvents = (List<RandomEvent>) cache.get(NORMAL_EVENT_KEY + "." + m + "." + d);
    if (todayEvents == null) {
        todayEvents = new ArrayList<RandomEvent>();

        logger.debug("today events is empty. reload.");

        List<RandomEvent> allNormalEvents = null;
        try {
            allNormalEvents = getNormalEvents();
            // cache.put(WELCOME_EVENT_KEY, allWelcomeRandomEvents);
        } catch (PureException e) {
            logger.error("error when get normal events.", e);
        }

        if (allNormalEvents == null || allNormalEvents.isEmpty()) {

            logger.debug("all normal events is empty.");

            return;
        }

        List<RandomEvent> noDayEvents = new ArrayList<RandomEvent>();// 

        Calendar c1 = Calendar.getInstance();// Calendar.getInstance();
        Calendar today = Calendar.getInstance();
        for (Iterator iterator = allNormalEvents.iterator(); iterator.hasNext();) {
            RandomEvent randomEvent = (RandomEvent) iterator.next();
            String month_day = randomEvent.getEventMonthDay();
            if (StringUtils.isNotEmpty(month_day)) {
                try {
                    int i = month_day.indexOf("-");
                    int month = NumberUtils.toInt(month_day.substring(0, i), -1);
                    int day = NumberUtils.toInt(month_day.substring(i + 1), -1);
                    c1.clear();
                    c1 = Calendar.getInstance();

                    //                        logger.debug("the random event [" + randomEvent.getEventInfo() + "] month:" + month + " day:"
                    //                                + day);

                    if (month != -1) {
                        c1.set(Calendar.MONTH, month - 1);
                    }
                    if (day != -1) {
                        c1.set(Calendar.DAY_OF_MONTH, day);
                    }

                    if (DateUtils.isSameDay(c1, today)) {

                        logger.debug("today event:" + randomEvent.getEventInfo());

                        todayEvents.add(randomEvent);
                    }
                } catch (Exception e) {
                }
            } else {
                noDayEvents.add(randomEvent);
            }
        }

        if (todayEvents == null || todayEvents.isEmpty()) {
            if (noDayEvents.isEmpty()) {

                logger.debug("today events is empty, and noDay events is empty too.");

                return;
            }
        }

        // //////////////////////////////
        // //////////////////////////////
        todayEvents.addAll(noDayEvents);
        // //////////////////////
        // //////////////////////

        Collections.sort(todayEvents, new BeanComparator("eventScale"));
        todayTotalScale = 0;
        for (Iterator iterator = todayEvents.iterator(); iterator.hasNext();) {
            RandomEvent randomEvent2 = (RandomEvent) iterator.next();
            todayTotalScale += randomEvent2.getEventScale();
        }
        cache.put(NORMAL_EVENT_KEY + "." + m + "." + d, todayEvents);
    }

    int random = new Random().nextInt(todayTotalScale);
    RandomEvent todayEvent = null;
    int start = 0;
    int end = 0;
    for (int i = 0; i < todayEvents.size(); i++) {
        if (i == 0) {
            start = 0;
            end = todayEvents.get(i).getEventScale();
        } else {
            start = end;
            end = end + todayEvents.get(i).getEventScale();
        }

        if (random >= start && random < end) {
            todayEvent = todayEvents.get(i);
            break;
        }
    }
    if (todayEvent == null) {
        return;
    }

    try {

        logger.info("normal event[" + todayEvent.getEventInfo() + "]");

        //            loginUser.setFunds(loginUser.getFunds() + todayEvent.getEventMoney());
        //            loginUser.setAssets(loginUser.getAssets() + todayEvent.getEventMoney());

        createInformation(loginUser, todayEvent);

        UserMoneySaveEntry userMoney = new UserMoneySaveEntry();

        userMoney.setTaobaoId(loginUser.getTaobaoID());
        userMoney.setFunds(todayEvent.getEventMoney());
        userMoney.setAssets(todayEvent.getEventMoney());

        UserMoneySaveCache.getInstance().add(userMoney);

        //            UserInfoSaveCache.getInstance().add(loginUser);

    } catch (Exception e) {
        logger.error(e);
        return;
    }

    return;
}

From source file:org.openmrs.contrib.metadatarepository.util.DateConverterTest.java

public void testConvertStringToDate() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);/* w  w  w  . j  a v a 2  s .c om*/
    final String datePart = DateUtil.convertDateToString(today);
    // test empty time
    Date date = (Date) converter.convert(Date.class, "");
    assertNull(date);
    date = (Date) converter.convert(Date.class, datePart);

    final Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
}

From source file:com.l2jfree.gameserver.instancemanager.GameTimeManager.java

private GameTimeManager() {
    new File("data/serial").mkdirs();

    final Calendar cal = loadData();

    if (cal != null) {
        _calendar.setTimeInMillis(cal.getTimeInMillis());
    } else {/*ww w  .jav  a  2  s.  co  m*/
        _calendar.set(Calendar.YEAR, 1281);
        _calendar.set(Calendar.MONTH, 5);
        _calendar.set(Calendar.DAY_OF_MONTH, 5);
        _calendar.set(Calendar.HOUR_OF_DAY, 23);
        _calendar.set(Calendar.MINUTE, 45);

        saveData();
    }

    ThreadPoolManager.getInstance().scheduleAtFixedRate(new MinuteCounter(), 0, 60000 / Config.DATETIME_MULTI);

    _log.info("GameTimeController: Initialized.");
}