List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:Dates.java
/** * Given a date, a proper TimeZone, return the last millisecond date of the * specified date and TimeZone. If TimeZone is null, meaning use Defult * TimeZone of the JVM.//from www .j av a 2s . co m */ final public static Date endOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());// don't call cal.setTime(Date) which // will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); cal.clear(); cal.set(year, month, day + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
From source file:com.pureinfo.tgirls.servlet.WelcomeMsgUtils.java
public static RandomEvent doGetWelcomEvent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("to get welcome event."); User loginUser = CookieUtils.getLoginUser(request, response); if (loginUser == null) { return null; }/*from w ww . ja v a 2s . c om*/ IUserMgr usermgr = null;//(IUserMgr) ArkContentHelper.getContentMgrOf(User.class); try { usermgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); if (loginUser.getLastLoginTime() == null) { loginUser.setLastLoginTime(new Date()); usermgr.save(loginUser); } } catch (Exception e1) { logger.error(e1); return null; } if (DateUtils.isSameDay(loginUser.getLastLoginTime(), new Date())) { return null; } else { //???? createNormalRandomEvent(loginUser); } 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(WELCOME_EVENT_KEY + "." + m + "." + d); if (todayEvents == null) { todayEvents = new ArrayList<RandomEvent>(); logger.debug("today events is empty. reload."); List<RandomEvent> allWelcomeRandomEvents = null; try { allWelcomeRandomEvents = getWelcomeEvents(); } catch (PureException e) { logger.error("error when get welcome events.", e); } if (allWelcomeRandomEvents == null || allWelcomeRandomEvents.isEmpty()) { logger.debug("all welcome events is empty."); return null; } List<RandomEvent> normalEvents = new ArrayList<RandomEvent>();// Calendar c1 = Calendar.getInstance();// Calendar.getInstance(); Calendar today = Calendar.getInstance(); for (Iterator<RandomEvent> iterator = allWelcomeRandomEvents.iterator(); iterator.hasNext();) { 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)) { todayEvents.add(randomEvent); } } catch (Exception e) { } } else { normalEvents.add(randomEvent); } } if (todayEvents == null || todayEvents.isEmpty()) { if (normalEvents.isEmpty()) { logger.debug("today events is empty, and normal events is empty too."); return null; } else { todayEvents.addAll(normalEvents); } } Collections.sort(todayEvents, new BeanComparator("eventScale")); todayTotalScale = 0; for (Iterator<RandomEvent> iterator = todayEvents.iterator(); iterator.hasNext();) { RandomEvent randomEvent2 = iterator.next(); todayTotalScale += randomEvent2.getEventScale(); } cache.put(WELCOME_EVENT_KEY + "." + m + "." + d, todayEvents); } if (todayEvents == null || todayEvents.isEmpty()) { logger.debug("today events is empty, system events is empty ."); return null; } 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 null; } try { logger.info("welcome event[" + todayEvent.getEventInfo() + "]"); loginUser.setFunds(loginUser.getFunds() + todayEvent.getEventMoney()); loginUser.setAssets(loginUser.getAssets() + todayEvent.getEventMoney()); loginUser.setLastLoginTime(new Date()); usermgr.save(loginUser); //ScriptWriteUtils.reBuildUserInfoScript(loginUser); } catch (Exception e) { logger.error(e); return null; } return todayEvent; }
From source file:Dates.java
/** * Given a date, a proper TimeZone, return the ending date of the month of the * specified date and TimeZone. If TimeZone is null, meaning use default * TimeZone of the JVM.//from w w w. ja v a2 s .co m */ final public static Date endOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which // will reset the TimeZone. final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); final int monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.clear(); cal.set(year, month, monthDays + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java
public static Date parseTimelineHour(final String hourString, final int year) { final BigDecimal hours = NumberUtils.parseQuietDecimal(hourString); if (hours == null) return null; // REMARK: we read the calculation core time with the time zone, as defined in Kalypso Preferences final Calendar calendar = Calendar.getInstance(KalypsoCorePlugin.getDefault().getTimeZone()); calendar.clear(); calendar.set(year, 0, 1);/*from w w w .ja v a 2 s .com*/ BigDecimal wholeHours = hours.setScale(0, BigDecimal.ROUND_DOWN); final BigDecimal wholeMinutes = hours.subtract(wholeHours).multiply(new BigDecimal("60")); //$NON-NLS-1$ if (wholeHours.intValue() > 1) { wholeHours = new BigDecimal(wholeHours.intValue() - 1); } calendar.add(Calendar.HOUR, wholeHours.intValue()); calendar.add(Calendar.MINUTE, wholeMinutes.intValue()); final boolean lBoolLeapYear = DateUtilities.isLeapYear(calendar); if (lBoolLeapYear && calendar.get(Calendar.DAY_OF_YEAR) > 59) { calendar.clear(); calendar.set(year, 0, 1); calendar.add(Calendar.HOUR, wholeHours.intValue() - 24); calendar.add(Calendar.MINUTE, wholeMinutes.intValue()); } return calendar.getTime(); }
From source file:com.aan.girsang.server.dao.transaksi.ReturPembelianDao.java
public List<ReturPembelian> filterBulanRP(int bulan, int tahun) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.MONTH, bulan); calendar.set(Calendar.YEAR, tahun); Date date = calendar.getTime(); String tgl = new SimpleDateFormat("MM yyyy").format(date); return sessionFactory.getCurrentSession() .createQuery("from ReturPembelian p where TO_CHAR(p.tanggal, 'MM yyyy') LIKE :bulan " + "Order By p.tanggal Desc") .setParameter("bulan", "%" + tgl + "%").list(); }
From source file:com.aan.girsang.server.dao.transaksi.PelunasanHutangDao.java
public List<PelunasanHutang> filterBulanPH(int bulan, int tahun) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.MONTH, bulan); calendar.set(Calendar.YEAR, tahun); Date date = calendar.getTime(); String tgl = new SimpleDateFormat("MM yyyy").format(date); return sessionFactory.getCurrentSession() .createQuery("from PelunasanHutang p where TO_CHAR(p.tanggal, 'MM yyyy') LIKE :bulan " + "Order By p.tanggal Desc") .setParameter("bulan", "%" + tgl + "%").list(); }
From source file:com.aan.girsang.server.dao.transaksi.PenjualanDao.java
public List<Penjualan> filterBulanTahun(int bulan, int tahun) { Boolean isPending = false;/*ww w . j a v a2s . co m*/ Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.MONTH, bulan); calendar.set(Calendar.YEAR, tahun); Date date = calendar.getTime(); String tgl = new SimpleDateFormat("MM yyyy").format(date); return sessionFactory.getCurrentSession().createQuery( "from Penjualan p where p.isPending=:isPending AND TO_CHAR(p.tanggal, 'MM yyyy') LIKE :bulan " + "Order By p.tanggal Desc") .setParameter("isPending", isPending).setParameter("bulan", "%" + tgl + "%").list(); }
From source file:com.aan.girsang.server.dao.transaksi.PembelianDao.java
public List<Pembelian> filterBulanTahun(int bulan, int tahun) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.MONTH, bulan); calendar.set(Calendar.YEAR, tahun); Date date = calendar.getTime(); String tgl = new SimpleDateFormat("MM yyyy").format(date); return sessionFactory.getCurrentSession().createQuery( "from Pembelian p where TO_CHAR(p.tanggal, 'MM yyyy') LIKE :bulan " + "order by p.noRef desc") .setParameter("bulan", "%" + tgl + "%").list(); }
From source file:com.netflix.genie.server.metrics.impl.TestJobCountManagerImpl.java
/** * Test getting number of running jobs on one instance. * * @throws GenieException if there is any error during this test */// ww w . j a v a 2 s .c o m @Test @DatabaseSetup("testNumInstanceJobs.xml") public void testNumInstanceJobs() throws GenieException { //Force the hostname of the jobs to be the machine running the build final String hostName = NetUtil.getHostName(); for (final Job job : this.jobRepo.findAll()) { job.setHostName(hostName); } this.jobRepo.flush(); final Calendar one = Calendar.getInstance(); one.clear(); one.set(2014, Calendar.JULY, 1, 16, 27, 38); final Calendar two = Calendar.getInstance(); two.clear(); two.set(2014, Calendar.JULY, 1, 16, 27, 39); final Calendar three = Calendar.getInstance(); three.clear(); three.set(2014, Calendar.JULY, 1, 16, 27, 40); Assert.assertEquals(2, this.manager.getNumInstanceJobs()); Assert.assertEquals(2, this.manager.getNumInstanceJobs(0L, System.currentTimeMillis())); Assert.assertEquals(1, this.manager.getNumInstanceJobs(one.getTimeInMillis(), two.getTimeInMillis())); Assert.assertEquals(1, this.manager.getNumInstanceJobs(hostName, two.getTimeInMillis(), three.getTimeInMillis())); Assert.assertEquals(0, this.manager.getNumInstanceJobs(0L, 0L)); }
From source file:org.scub.foundation.framework.base.messagesource.MessageSourceUtil.java
/** * Retourne la conversion de la date en fonction du Locale utilis. * @param date la date.//from w ww . ja v a 2 s. c o m * @return la conversion. * @throws ParseException erreur de parsing de la date. * @throws java.text.ParseException . */ public Calendar getDateParse(final String date) throws ParseException { final SimpleDateFormat format = new SimpleDateFormat(messageSourceDetails.loadLocalInfo().getDatePattern()); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.setTimeInMillis(format.parse(date).getTime()); return cal; }