List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:com.predic8.membrane.core.exchangestore.FileExchangeStore.java
protected void deleteOldFolders() throws IOException { if (this.maxDays < 0) { return; // don't do anything if this feature is deactivated }//from w ww . j a v a2 s . co m Calendar threshold = Calendar.getInstance(); threshold.add(Calendar.DAY_OF_MONTH, -maxDays); ArrayList<File> folders3 = new DepthWalker(3).getDirectories(new File(dir)); ArrayList<File> deletion = new ArrayList<File>(); for (File f : folders3) { int day = Integer.parseInt(f.getName()); int mon = Integer.parseInt(f.getParentFile().getName()); int year = Integer.parseInt(f.getParentFile().getParentFile().getName()); Calendar folderTime = Calendar.getInstance(); folderTime.clear(); folderTime.set(year, mon - 1, day); if (folderTime.before(threshold)) { deletion.add(f); } } for (File d : deletion) { FileUtils.deleteDirectory(d); } }
From source file:com.pagenews.zhihudaily.homepage.ZhihuDailyFragment.java
@Nullable @Override//from w w w .ja v a 2 s . co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_list, container, false); initViews(view); presenter.start(); refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { presenter.refresh(); } }); recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { boolean isSlidingToLast = false; @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager(); // ? if (newState == RecyclerView.SCROLL_STATE_IDLE) { // ??item position int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition(); int totalItemCount = manager.getItemCount(); // ?? if (lastVisibleItem == (totalItemCount - 1) && isSlidingToLast) { Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, --mDay); presenter.loadMore(c.getTimeInMillis()); } } super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); isSlidingToLast = dy > 0; // ??fab if (dy > 0) { fab.hide(); } else { fab.show(); } } }); // fab // fabactivityview // ??fragment??listener // ??main pager adapter?fragmentrecycler viewfab?? // fab?? // ?tab layout???dialog fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (tabLayout.getSelectedTabPosition() == 0) { Calendar now = Calendar.getInstance(); now.set(mYear, mMonth, mDay); DatePickerDialog dialog = DatePickerDialog .newInstance(new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; Calendar temp = Calendar.getInstance(); temp.clear(); temp.set(year, monthOfYear, dayOfMonth); presenter.loadPosts(temp.getTimeInMillis(), true); } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dialog.setMaxDate(Calendar.getInstance()); Calendar minDate = Calendar.getInstance(); // 2013.5.20api minDate.set(2013, 5, 20); dialog.setMinDate(minDate); dialog.vibrate(false); dialog.show(getActivity().getFragmentManager(), "DatePickerDialog"); } else if (tabLayout.getSelectedTabPosition() == 2) { ViewPager p = (ViewPager) getActivity().findViewById(R.id.view_pager); MainPagerAdapter ad = (MainPagerAdapter) p.getAdapter(); ad.getDoubanFragment().showPickDialog(); } } }); return view; }
From source file:org.richfaces.component.CalendarComponentTest.java
public void testPreloadRanges() throws Exception { UICalendar calendar = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE); calendar.setLocale(Locale.FRENCH); Calendar calendarObject = Calendar.getInstance(); calendarObject.clear(); calendarObject.set(2007, Calendar.JUNE, 10); Calendar preloadRangeBegin = Calendar.getInstance(); preloadRangeBegin.clear();/*from w ww . ja v a 2 s . com*/ preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime())); assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR)); assertEquals(Calendar.JUNE, preloadRangeBegin.get(Calendar.MONTH)); assertEquals(1, preloadRangeBegin.get(Calendar.DATE)); Calendar preloadRangeEnd = Calendar.getInstance(); preloadRangeEnd.clear(); preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime())); assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR)); assertEquals(Calendar.JUNE, preloadRangeEnd.get(Calendar.MONTH)); assertEquals(30, preloadRangeEnd.get(Calendar.DATE)); calendarObject.set(2007, Calendar.JANUARY, 1); preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime())); assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR)); assertEquals(Calendar.JANUARY, preloadRangeBegin.get(Calendar.MONTH)); assertEquals(1, preloadRangeBegin.get(Calendar.DATE)); calendarObject.set(2007, Calendar.JUNE, 10); calendar.setLocale(Locale.US); preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime())); assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR)); assertEquals(Calendar.JUNE, preloadRangeBegin.get(Calendar.MONTH)); assertEquals(1, preloadRangeBegin.get(Calendar.DATE)); preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime())); assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR)); assertEquals(Calendar.JUNE, preloadRangeEnd.get(Calendar.MONTH)); assertEquals(30, preloadRangeEnd.get(Calendar.DATE)); }
From source file:org.photovault.imginfo.Test_PhotoQuery.java
@BeforeClass @Override/*from w w w . java 2s .co m*/ public void setUp() { session = HibernateUtil.getSessionFactory().openSession(); HibernateDAOFactory hdf = (HibernateDAOFactory) DAOFactory.instance(HibernateDAOFactory.class); hdf.setSession(session); daoFactory = hdf; photoDAO = daoFactory.getPhotoInfoDAO(); folderDAO = daoFactory.getPhotoFolderDAO(); tx = session.beginTransaction(); // Create several photos with different shooting dates // Add them to a collection so that they are easy to delete afterwards Calendar cal = Calendar.getInstance(); cal.clear(); photos = new Vector(); uids = new Vector(); cal.set(2002, 11, 23); makePhoto(cal, 1, "Katsokaa kun Lassi ui"); cal.set(2002, 11, 24); makePhoto(cal, 1, "Lassille kuuluu hyvaa"); makePhoto(cal, 2, ""); cal.set(2002, 11, 25); makePhoto(cal, 1, ""); PhotoFolderDAO folderDAO = daoFactory.getPhotoFolderDAO(); folder = folderDAO.create("QueryTest", null); folder.reparentFolder(folderDAO.findRootFolder()); subfolder = folderDAO.create("QueryTest subfolder", folder); FolderPhotoAssocDAO assocDao = daoFactory.getFolderPhotoAssocDAO(); FolderPhotoAssociation assoc1 = assocDao.getAssociation(folder, photos.get(0)); folder.addPhotoAssociation(assoc1); photos.get(0).addFolderAssociation(assoc1); FolderPhotoAssociation assoc2 = assocDao.getAssociation(subfolder, photos.get(3)); subfolder.addPhotoAssociation(assoc2); photos.get(3).addFolderAssociation(assoc2); FolderPhotoAssociation assoc3 = assocDao.getAssociation(folder, photos.get(2)); folder.addPhotoAssociation(assoc3); photos.get(2).addFolderAssociation(assoc3); session.flush(); }
From source file:com.google.gwt.benchmark.dashboard.server.controller.BenchmarkController.java
private WeekSpan createWeekSpan(long commitTimeMsEpoch) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(commitTimeMsEpoch)); int week = cal.get(Calendar.WEEK_OF_YEAR); int year = cal.get(Calendar.YEAR); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.YEAR, year); long startSearch = calendar.getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, 7); long endSearch = calendar.getTimeInMillis(); return new WeekSpan(week, year, startSearch, endSearch); }
From source file:org.richfaces.component.CalendarComponentTest.java
public void setUp() throws Exception { super.setUp(); form = new HtmlForm(); form.setId("form"); facesContext.getViewRoot().getChildren().add(form); calendar = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE); calendar1 = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE); calendar.setLocale(Locale.UK); calendar.setDatePattern("d/MM/yyyy"); calendar.setTimeZone(TimeZone.getTimeZone("GMT-4:00")); calendar.setButtonLabel("PopUp"); // XXX test popup false // XXX test CurrentDate = null calendar.setPopup(true);//www . j av a 2 s . com Calendar calendarObject = Calendar.getInstance(); calendarObject.clear(); calendarObject.set(2001, Calendar.SEPTEMBER, 11, 10, 0, 0); calendar.setId("calendar"); calendar.setValue(calendarObject.getTime()); form.getChildren().add(calendar); calendar1.setId("_calendar"); calendar1.setPopup(false); calendar1.setCurrentDate(null); form.getChildren().add(calendar1); calendar2 = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE); calendar2.setDatePattern("dd/M/yy HH:mm"); calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36); calendar2.setValue(calendarObject.getTime()); calendar2.setId("timecalendar"); form.getChildren().add(calendar2); calendar3 = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE); calendar3.setDatePattern("dd/M/yy HH:mm"); calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36); calendar3.setValue(calendarObject.getTime()); calendar3.setId("timecalendar"); calendar3.setMode(UICalendar.AJAX_MODE); calendar3.setLocale(new Locale("ru", "RU", "")); calendar3.setCellHeight("50"); calendar3.setCellWidth("50"); form.getChildren().add(calendar3); }
From source file:com.github.amsacode.predict4java.PassPredictor.java
public Long getUplinkFreq(final Long freq, final Date date) throws SatNotFoundException { final Calendar cal = Calendar.getInstance(TZ); cal.clear(); cal.setTimeInMillis(date.getTime()); final SatPos satPos = getSatPos(cal.getTime()); final double rangeRate = satPos.getRangeRate(); return (long) ((double) freq * (SPEED_OF_LIGHT + rangeRate * 1000.0) / SPEED_OF_LIGHT); }
From source file:com.github.amsacode.predict4java.PassPredictor.java
/** * Gets the downlink frequency corrected for doppler. * /*from w w w . j ava2s . c o m*/ * @param freq * the original frequency in Hz * @return the doppler corrected frequency in Hz * @throws InvalidTleException * bad TLE passed in * @throws SatNotFoundException */ public Long getDownlinkFreq(final Long freq, final Date date) throws SatNotFoundException { // get the current position final Calendar cal = Calendar.getInstance(TZ); cal.clear(); cal.setTimeInMillis(date.getTime()); final SatPos satPos = getSatPos(cal.getTime()); final double rangeRate = satPos.getRangeRate(); return (long) ((double) freq * (SPEED_OF_LIGHT - rangeRate * 1000.0) / SPEED_OF_LIGHT); }
From source file:com.z3r0byte.magis.CalendarActivity.java
@Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.YEAR, year); date = calendar.getTime();/* w w w.j av a2s .c o m*/ getAppointmentsByDate(date); }
From source file:br.ufg.calendario.components.HomeBean.java
public void setMesListener(ActionEvent event) throws ParseException { try {//from w w w . j a va 2 s.co m int mes = Integer.parseInt((String) event.getComponent().getAttributes().get("mes")); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, calendario.getAno()); calendar.set(Calendar.MONTH, mes - 1); int diaInicio = calendar.getActualMinimum(Calendar.DAY_OF_MONTH); int diaTermino = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-M-d"); Date dataInicio = dateFormatter .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaInicio)); Date dataTermino = dateFormatter .parse(String.format("%04d-%02d-%02d", calendario.getAno(), mes, diaTermino)); setBuscaDataInicio(dataInicio); setBuscaDataTermino(dataTermino); System.out.format("%02d/%02d/%04d - %02d/%02d/%04d\n", diaInicio, mes, calendario.getAno(), diaTermino, mes, calendario.getAno()); System.out.format("periodo: %s a %s\n", dateFormatter.format(dataInicio), dateFormatter.format(dataTermino)); } catch (Exception e) { System.out.println("error: " + e.getMessage()); } }