List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:org.hippoecm.repository.query.lucene.ServicingNodeIndexer.java
private void indexDateFacet(Document doc, String fieldName, Calendar calendar) { Map<String, String> resolutions = new HashMap<String, String>(); resolutions.put("year", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.YEAR)); resolutions.put("month", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.MONTH)); resolutions.put("week", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.WEEK)); resolutions.put("day", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.DAY)); resolutions.put("hour", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.HOUR)); resolutions.put("minute", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.MINUTE)); resolutions.put("second", DateTools.timeToString(calendar.getTimeInMillis(), DateTools.Resolution.SECOND)); Map<String, Integer> byDateNumbers = new HashMap<String, Integer>(); byDateNumbers.put("year", calendar.get(Calendar.YEAR)); byDateNumbers.put("month", calendar.get(Calendar.MONTH)); byDateNumbers.put("week", calendar.get(Calendar.WEEK_OF_YEAR)); byDateNumbers.put("dayofyear", calendar.get(Calendar.DAY_OF_YEAR)); byDateNumbers.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK)); byDateNumbers.put("day", calendar.get(Calendar.DAY_OF_MONTH)); byDateNumbers.put("hour", calendar.get(Calendar.HOUR_OF_DAY)); byDateNumbers.put("minute", calendar.get(Calendar.MINUTE)); byDateNumbers.put("second", calendar.get(Calendar.SECOND)); String internalFacetName = ServicingNameFormat.getInternalFacetName(fieldName); String dateToString = String.valueOf(calendar.getTimeInMillis()); doc.add(new Field(internalFacetName, dateToString, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO)); for (Entry<String, String> keyValue : resolutions.entrySet()) { String compoundFieldName = fieldName + ServicingFieldNames.DATE_RESOLUTION_DELIMITER + keyValue.getKey();//from w ww . j a v a2 s .co m indexFacetProperty(doc, compoundFieldName); indexFacet(doc, compoundFieldName, keyValue.getValue()); } for (Entry<String, Integer> keyValue : byDateNumbers.entrySet()) { String compoundFieldName = fieldName + ServicingFieldNames.DATE_NUMBER_DELIMITER + keyValue.getKey(); indexFacetProperty(doc, compoundFieldName); indexFacet(doc, compoundFieldName, String.valueOf(keyValue.getValue())); } }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @ ???/* ww w. j av a 2s . c o m*/ ****************************************/ public static String getYearWeekEndDay(Date curDate) { Calendar cal = Calendar.getInstance(); cal.setTime(curDate); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR)); } else { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) + 1); } cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY+1); // ???? String tempYear = Integer.toString(cal.get(Calendar.YEAR)); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }
From source file:org.sakaiproject.tool.summarycalendar.ui.CalendarBean.java
private void prevWeek(ActionEvent e) { Calendar cal = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale()); cal.setTime(viewingDate);/*from ww w . j ava 2 s . c o m*/ cal.add(Calendar.WEEK_OF_YEAR, -1); setViewingDate(cal.getTime()); selectedDay = null; selectedEventRef = null; }
From source file:ch.entwine.weblounge.contentrepository.impl.index.elasticsearch.ElasticSearchSearchQuery.java
/** * Create the actual query. We start with a query that matches everything, * then move to the boolean conditions, finally add filter queries. */// ww w . jav a 2 s . co m private void createQuery() { queryBuilder = new MatchAllQueryBuilder(); // The boolean query builder BoolQueryBuilder booleanQuery = new BoolQueryBuilder(); // Terms if (searchTerms != null) { for (Map.Entry<String, Set<Object>> entry : searchTerms.entrySet()) { Set<Object> values = entry.getValue(); if (values.size() == 1) booleanQuery.must(new TermsQueryBuilder(entry.getKey(), values.iterator().next())); else booleanQuery .must(new TermsQueryBuilder(entry.getKey(), values.toArray(new String[values.size()]))); } this.queryBuilder = booleanQuery; } // Negative terms if (negativeSearchTerms != null) { for (Map.Entry<String, Set<Object>> entry : negativeSearchTerms.entrySet()) { Set<Object> values = entry.getValue(); if (values.size() == 1) booleanQuery.mustNot(new TermsQueryBuilder(entry.getKey(), values.iterator().next())); else booleanQuery.mustNot( new TermsQueryBuilder(entry.getKey(), values.toArray(new String[values.size()]))); } this.queryBuilder = booleanQuery; } // Date ranges if (dateRanges != null) { for (DateRange dr : dateRanges) { booleanQuery.must(dr.getQueryBuilder()); } this.queryBuilder = booleanQuery; } // Text if (text != null) { MatchQueryBuilder textQueryBuilder = QueryBuilders.matchQuery(TEXT, text); booleanQuery.must(textQueryBuilder); this.queryBuilder = booleanQuery; } // Fuzzy text if (fuzzyText != null) { FuzzyLikeThisQueryBuilder fuzzyQueryBuilder = QueryBuilders.fuzzyLikeThisQuery(TEXT_FUZZY) .likeText(fuzzyText); booleanQuery.must(fuzzyQueryBuilder); this.queryBuilder = booleanQuery; } // Fulltext if (fulltext != null) { MatchQueryBuilder textQueryBuilder = QueryBuilders.matchQuery(FULLTEXT, fulltext); booleanQuery.must(textQueryBuilder); this.queryBuilder = booleanQuery; } // Fuzzy fulltext if (fuzzyFulltext != null) { FuzzyLikeThisQueryBuilder fuzzyQueryBuilder = QueryBuilders.fuzzyLikeThisQuery(FULLTEXT_FUZZY) .likeText(fuzzyFulltext); booleanQuery.must(fuzzyQueryBuilder); this.queryBuilder = booleanQuery; } // Recency boost. We differentiate between various (random) levels of // recency if (recencyBoost) { Calendar date = Calendar.getInstance(); // Last week RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(MODIFIED); date.add(Calendar.WEEK_OF_YEAR, -1); rangeQueryBuilder.gt(date.getTimeInMillis()).boost(10); booleanQuery.should(rangeQueryBuilder); // Last month rangeQueryBuilder = QueryBuilders.rangeQuery(MODIFIED); date.add(Calendar.WEEK_OF_YEAR, -3); rangeQueryBuilder.gt(date.getTimeInMillis()).boost(5); booleanQuery.should(rangeQueryBuilder); // Last year rangeQueryBuilder = QueryBuilders.rangeQuery(MODIFIED); date.add(Calendar.MONTH, -5); rangeQueryBuilder.gt(date.getTimeInMillis()).boost(2); booleanQuery.should(rangeQueryBuilder); } QueryBuilder unfilteredQuery = queryBuilder; List<FilterBuilder> filters = new ArrayList<FilterBuilder>(); // Add filtering for AND terms if (groups != null) { for (ValueGroup group : groups) { filters.addAll(group.getFilterBuilders()); } } // Non-Empty fields if (nonEmptyFields != null) { for (String field : nonEmptyFields) { filters.add(FilterBuilders.existsFilter(field)); } } // Empty fields if (emptyFields != null) { for (String field : emptyFields) { filters.add(FilterBuilders.missingFilter(field)); } } // Filter expressions if (filter != null) { filters.add(FilterBuilders.termFilter(FULLTEXT, filter)); } // Apply the filters if (filters.size() == 1) { this.queryBuilder = QueryBuilders.filteredQuery(unfilteredQuery, filters.get(0)); } else if (filters.size() > 1) { FilterBuilder andFilter = FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()])); this.queryBuilder = QueryBuilders.filteredQuery(unfilteredQuery, andFilter); } }
From source file:org.projectforge.web.humanresources.HRPlanningEditForm.java
private HRPlanningDO getPredecessor() { if (predecessorUpdToDate == false) { predecessor = null;//from w w w .ja va2 s. c om final Integer userId = data.getUserId(); if (userId != null) { // Get the entry from the predecessor week: final DayHolder dh = new DayHolder(getData().getWeek()); dh.add(Calendar.WEEK_OF_YEAR, -1); predecessor = hrPlanningDao.getEntry(userId, dh.getSQLDate()); } predecessorUpdToDate = true; } return predecessor; }
From source file:org.sakaiproject.tool.summarycalendar.ui.CalendarBean.java
private void nextWeek(ActionEvent e) { Calendar cal = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale()); cal.setTime(viewingDate);//w w w . ja va2 s .c o m cal.add(Calendar.WEEK_OF_YEAR, +1); setViewingDate(cal.getTime()); selectedDay = null; selectedEventRef = null; }
From source file:net.groupbuy.service.impl.OrderServiceImpl.java
public void complete(Order order, Admin operator) { Assert.notNull(order);/*from w w w.java 2s . co m*/ Member member = order.getMember(); memberDao.lock(member, LockModeType.PESSIMISTIC_WRITE); if (order.getShippingStatus() == ShippingStatus.partialShipment || order.getShippingStatus() == ShippingStatus.shipped) { member.setPoint(member.getPoint() + order.getPoint()); for (Coupon coupon : order.getCoupons()) { couponCodeDao.build(coupon, member); } } if (order.getShippingStatus() == ShippingStatus.unshipped || order.getShippingStatus() == ShippingStatus.returned) { CouponCode couponCode = order.getCouponCode(); if (couponCode != null) { couponCode.setIsUsed(false); couponCode.setUsedDate(null); couponCodeDao.merge(couponCode); order.setCouponCode(null); orderDao.merge(order); } } member.setAmount(member.getAmount().add(order.getAmountPaid())); if (!member.getMemberRank().getIsSpecial()) { MemberRank memberRank = memberRankDao.findByAmount(member.getAmount()); if (memberRank != null && memberRank.getAmount().compareTo(member.getMemberRank().getAmount()) > 0) { member.setMemberRank(memberRank); } } memberDao.merge(member); if (order.getIsAllocatedStock()) { for (OrderItem orderItem : order.getOrderItems()) { if (orderItem != null) { Product product = orderItem.getProduct(); productDao.lock(product, LockModeType.PESSIMISTIC_WRITE); if (product != null && product.getStock() != null) { product.setAllocatedStock(product.getAllocatedStock() - (orderItem.getQuantity() - orderItem.getShippedQuantity())); productDao.merge(product); orderDao.flush(); staticService.build(product); } } } order.setIsAllocatedStock(false); } for (OrderItem orderItem : order.getOrderItems()) { if (orderItem != null) { Product product = orderItem.getProduct(); productDao.lock(product, LockModeType.PESSIMISTIC_WRITE); if (product != null) { Integer quantity = orderItem.getQuantity(); Calendar nowCalendar = Calendar.getInstance(); Calendar weekSalesCalendar = DateUtils.toCalendar(product.getWeekSalesDate()); Calendar monthSalesCalendar = DateUtils.toCalendar(product.getMonthSalesDate()); if (nowCalendar.get(Calendar.YEAR) != weekSalesCalendar.get(Calendar.YEAR) || nowCalendar .get(Calendar.WEEK_OF_YEAR) > weekSalesCalendar.get(Calendar.WEEK_OF_YEAR)) { product.setWeekSales((long) quantity); } else { product.setWeekSales(product.getWeekSales() + quantity); } if (nowCalendar.get(Calendar.YEAR) != monthSalesCalendar.get(Calendar.YEAR) || nowCalendar.get(Calendar.MONTH) > monthSalesCalendar.get(Calendar.MONTH)) { product.setMonthSales((long) quantity); } else { product.setMonthSales(product.getMonthSales() + quantity); } product.setSales(product.getSales() + quantity); product.setWeekSalesDate(new Date()); product.setMonthSalesDate(new Date()); productDao.merge(product); orderDao.flush(); staticService.build(product); } } } order.setOrderStatus(OrderStatus.completed); order.setExpire(null); orderDao.merge(order); OrderLog orderLog = new OrderLog(); orderLog.setType(Type.complete); orderLog.setOperator(operator != null ? operator.getUsername() : null); orderLog.setOrder(order); orderLogDao.persist(orderLog); }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ?/*from ww w.j a v a2 s .c o m*/ * * @param date * @return */ public static Date getWeekStart(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.get(Calendar.WEEK_OF_YEAR); int firstDay = calendar.getFirstDayOfWeek(); calendar.set(Calendar.DAY_OF_WEEK, firstDay); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:com.iisigroup.cap.log.TimeFolderSizeRollingFileAppender.java
public Date getNextCheckDate(Date now) { this.setTime(now); switch (type) { case TimeFolderSizeRollingFileAppender.TOP_OF_MINUTE: this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.MINUTE, 1); break;// w ww .jav a2 s.c o m case TimeFolderSizeRollingFileAppender.TOP_OF_HOUR: this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.HOUR_OF_DAY, 1); break; case TimeFolderSizeRollingFileAppender.HALF_DAY: this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); int hour = get(Calendar.HOUR_OF_DAY); if (hour < 12) { this.set(Calendar.HOUR_OF_DAY, 12); } else { this.set(Calendar.HOUR_OF_DAY, 0); this.add(Calendar.DAY_OF_MONTH, 1); } break; case TimeFolderSizeRollingFileAppender.TOP_OF_DAY: this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.DATE, 1); break; case TimeFolderSizeRollingFileAppender.TOP_OF_WEEK: this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek()); this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.WEEK_OF_YEAR, 1); break; case TimeFolderSizeRollingFileAppender.TOP_OF_MONTH: this.set(Calendar.DATE, 1); this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.MONTH, 1); break; default: throw new IllegalStateException("Unknown periodicity type."); } return getTime(); }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
@Override public void onResume() { //TODO Null check on database needed? super.onResume(); if (init)/*from w w w .ja v a2 s . co m*/ if (MainActivity.isOnline()) { if (scheduleJson != null && PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null) != null && checkDatabase() != HeliniumStudentApp.DB_REFRESHING) parseData(HeliniumStudentApp.ACTION_ONLINE); } else { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (scheduleFocus != currentWeek && scheduleFocus != currentWeek + 1) { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } else init = true; }