List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:Time.java
/** * Return true if the year of this day is a leap year. * //from w w w. j a va2s .c o m * @return True if this year is a leap year, false otherwise. */ public boolean isLeapYear() { return getDaysInYear() == calendar_.getMaximum(Calendar.DAY_OF_YEAR); }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java
@Override public Date firstMissingWorklogsDate(final String selectedUser) throws GenericEntityException { Calendar scannedDate = Calendar.getInstance(); // one week/*w w w .j a v a 2 s .c om*/ scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) - DateTimeConverterUtil.DAYS_PER_WEEK); for (int i = 0; i < DateTimeConverterUtil.DAYS_PER_WEEK; i++) { // convert date to String Date scanedDateDate = scannedDate.getTime(); String scanedDateString = DateTimeConverterUtil.dateToString(scanedDateDate); // check excludse - pass if (excludeDatesSet.contains(scanedDateString)) { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); continue; } // check includes - not check weekend // check weekend - pass if (!includeDatesSet.contains(scanedDateString) && ((scannedDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (scannedDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); continue; } // check worklog. if no worklog set result else ++ scanedDate boolean isDateContainsWorklog = isContainsWorklog(scanedDateDate); if (!isDateContainsWorklog) { return scanedDateDate; } else { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); } } // if we find everything all right then return with the current date return scannedDate.getTime(); }
From source file:com.fdu.jira.plugin.report.timesheet.TimeSheet.java
public void getTimeSpents(User remoteUser, Date startDate, Date endDate, String targetUserName, boolean excelView, String priority, String[] targetGroups, Long projectId, Long filterId, Boolean showWeekends, Boolean showUsers, String groupByField) throws SearchException, GenericEntityException { JiraServiceContext jiraServiceContext = new JiraServiceContextImpl(remoteUser); TimeZone timezone = timeZoneManager.getLoggedInUserTimeZone(); Set<Long> filteredIssues = new TreeSet<Long>(); if (filterId != null) { log.info("Using filter: " + filterId); SearchRequest filter = searchRequestService.getFilter(jiraServiceContext, filterId); if (filter != null) { // not logged in SearchResults issues = searchProvider.search(filter.getQuery(), remoteUser, PagerFilter.getUnlimitedFilter()); for (Iterator<Issue> i = issues.getIssues().iterator(); i.hasNext();) { Issue value = i.next();/*from w ww . ja va 2 s . co m*/ filteredIssues.add(value.getId()); } } } EntityExpr startExpr = new EntityExpr("startdate", EntityOperator.GREATER_THAN_EQUAL_TO, new Timestamp(startDate.getTime())); EntityExpr endExpr = new EntityExpr("startdate", EntityOperator.LESS_THAN, new Timestamp(endDate.getTime())); List<EntityExpr> entityExprs = UtilMisc.toList(startExpr, endExpr); Set<String> assigneeIds = null; if (targetGroups != null && targetGroups.length > 0 && permissionManager.hasPermission(Permissions.USER_PICKER, remoteUser)) { Set<User> users = userUtil.getAllUsersInGroupNames(Arrays.asList(targetGroups)); assigneeIds = new TreeSet<String>(); for (User user : users) { assigneeIds.add(user.getName()); // TIME-156: risky :-\ assigneeIds.add(user.getName().toLowerCase()); } log.info("Searching worklogs created since '" + startDate + "', till '" + endDate + "', by group '" + Arrays.asList(targetGroups) + "'"); } else { EntityExpr userExpr = new EntityExpr("author", EntityOperator.EQUALS, targetUserName); entityExprs.add(userExpr); log.info("Searching worklogs created since '" + startDate + "', till '" + endDate + "', by '" + targetUserName + "'"); } List<String> orderBy = new ArrayList<String>(); orderBy.add("author"); orderBy.add("created"); orderBy.add("issue"); List<GenericValue> worklogs = ComponentManager.getComponent(DelegatorInterface.class).findByAnd("Worklog", entityExprs, orderBy); List<Worklog> worklogObjects = new ArrayList<Worklog>(); for (Iterator<GenericValue> worklogsIterator = worklogs.iterator(); worklogsIterator.hasNext();) { GenericValue genericWorklog = worklogsIterator.next(); Worklog worklog = WorklogUtil.convertToWorklog(genericWorklog, worklogManager, issueManager); boolean isValidVisibility = visibilityValidator.isValidVisibilityData(jiraServiceContext, "worklog", worklog.getIssue(), worklog.getGroupLevel(), worklog.getRoleLevelId() != null ? worklog.getRoleLevelId().toString() : null); if (!isValidVisibility) { continue; } Issue issue = issueManager.getIssueObject(genericWorklog.getLong("issue")); if ((filterId != null && !filteredIssues.contains(issue.getId())) || (assigneeIds != null && !assigneeIds.contains(worklog.getAuthor()))) { continue; } Project project = issue.getProjectObject(); if (priority != null && priority.length() != 0 && !issue.getString("priority").equals(priority)) { continue; // exclude issues with other priorities than (if) selected } if (projectId != null && !project.getId().equals(projectId)) { continue; // exclude issues from other projects than (if) selected } User workedUser = userUtil.getUserObject(genericWorklog.getString("author")); if (workedUser == null) { continue; // TIME-221: user may have been deleted } Date dateCreated = worklog.getStartDate(); Calendar cal = Calendar.getInstance(timezone); cal.setTimeInMillis(dateCreated.getTime()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date dateOfTheDay = cal.getTime(); Long dateCreatedLong = cal.getTimeInMillis(); WeekPortletHeader weekDay = new WeekPortletHeader(cal); // timeZone addjusted if (showWeekends != null && !showWeekends.booleanValue() && weekDay.isNonBusinessDay()) { continue; // exclude worklogs and issues that were started on weekends if no weekends desired to show } long spent; if (!permissionManager.hasPermission(Permissions.BROWSE, issue, remoteUser)) { continue; // exclude issues that users can't (shouldn't be // allowed to) see } if (excelView) { // excel view shows complete work log worklogObjects.add(worklog); } else { // html view shows summary hours per issue for each user // per entry (report) // per issue (portlet) Map<Date, Long> weekTimeSpents = weekWorkLogShort.get(issue); if (weekTimeSpents == null) { weekTimeSpents = new Hashtable<Date, Long>(); weekWorkLogShort.put(issue, weekTimeSpents); // portlet } spent = worklog.getTimeSpent(); Long dateSpent = weekTimeSpents.get(dateOfTheDay); if (dateSpent != null) { spent += dateSpent; } weekTimeSpents.put(dateOfTheDay, spent); // per user (group portlet) updateUserWorkLog(worklog, workedUser, dateOfTheDay); // per project per day Map<Date, Long> projectWorkLog = projectTimeSpents.get(project); if (projectWorkLog == null) { projectWorkLog = new Hashtable<Date, Long>(); projectTimeSpents.put(project, projectWorkLog); } spent = worklog.getTimeSpent(); Long projectSpent = projectWorkLog.get(dateOfTheDay); if (projectSpent != null) { spent += projectSpent; } projectWorkLog.put(dateOfTheDay, spent); // per project and field calculateTimesForProjectGroupedByField(groupByField, worklog, issue, project, dateOfTheDay); // total per day spent = worklog.getTimeSpent(); dateSpent = weekTotalTimeSpents.get(dateCreatedLong); if (dateSpent != null) { spent += dateSpent; } weekTotalTimeSpents.put(dateCreatedLong, spent); spent = worklog.getTimeSpent(); if (showUsers != null && showUsers.booleanValue()) { // is nul in portlet Map<Issue, Map<Worklog, Long>> userWorkLog = weekWorkLog.get(workedUser); if (userWorkLog == null) { userWorkLog = new TreeMap<Issue, Map<Worklog, Long>>(new IssueProjectComparator<Issue>()); weekWorkLog.put(workedUser, userWorkLog); } Map<Worklog, Long> issueWorkLog = userWorkLog.get(issue); if (issueWorkLog == null) { issueWorkLog = new Hashtable<Worklog, Long>(); userWorkLog.put(issue, issueWorkLog); } issueWorkLog.put(worklog, spent); // totals per user/week Map<Long, Long> userTotalTimeSpents = userWeekTotalTimeSpents.get(workedUser); if (userTotalTimeSpents == null) { userTotalTimeSpents = new HashMap<Long, Long>(); userWeekTotalTimeSpents.put(workedUser, userTotalTimeSpents); } Long weekDaySpent = userTotalTimeSpents.get(dateCreatedLong); if (weekDaySpent != null) { spent += weekDaySpent; } userTotalTimeSpents.put(dateCreatedLong, spent); // totals per user/issue spent = worklog.getTimeSpent(); Map<Issue, Long> issueTotalTimeSpents = userIssueTotalTimeSpents.get(workedUser); if (issueTotalTimeSpents == null) { issueTotalTimeSpents = new HashMap<Issue, Long>(); userIssueTotalTimeSpents.put(workedUser, issueTotalTimeSpents); } Long issueSpent = issueTotalTimeSpents.get(issue); if (issueSpent != null) { spent += issueSpent; } issueTotalTimeSpents.put(issue, spent); } } } if (excelView) allWorklogsByUser = getWorklogMapByUser(worklogObjects); // fill dates (ordered list) and week days (corresponding to each date) Calendar calendarDate = Calendar.getInstance(timezone); calendarDate.setTimeInMillis(startDate.getTime()); Calendar today = Calendar.getInstance(timezone); while (endDate.after(calendarDate.getTime())) { WeekPortletHeader wph = new WeekPortletHeader((Calendar) calendarDate.clone()); String businessDay = ""; if (calendarDate.get(Calendar.DATE) == today.get(Calendar.DATE) && calendarDate.get(Calendar.MONTH) == today.get(Calendar.MONTH) && calendarDate.get(Calendar.YEAR) == today.get(Calendar.YEAR)) { businessDay = "toDay"; } else if (wph.isNonBusinessDay() || wph.isHoliday()) { businessDay = "nonBusinessDay"; } wph.setWeekDayCSS(businessDay); //rowHeaderDark redText red-highlight if (showWeekends == null || showWeekends.booleanValue() || !wph.isNonBusinessDay()) { // check if allowed to show weekends and if this it is a weekend weekDays.add(wph); } calendarDate.add(Calendar.DAY_OF_YEAR, 1); } }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
@SuppressWarnings("unchecked") public License findUnExpiredLicense(String pin, String key, int gracePeriodInDays) { log.debug("finding unexpired License instance by pin and key: " + pin + ", key: " + key); License license = null;//from w w w . j a v a2 s. com try { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, gracePeriodInDays); Date maxDate = cal.getTime(); String qs = "from License as lic where lic.endUserPin= :pin and lic.licKey= :key and lic.dateExpires >= :maxDate"; Query query = getSession().createQuery(qs); query.setParameter("pin", pin); query.setParameter("key", key); query.setParameter("maxDate", maxDate); List<License> licenses = query.list(); if (licenses != null && licenses.size() > 0) license = licenses.get(0); } catch (RuntimeException re) { log.error("findUnExpiredLicense", re); throw re; } return license; }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object getDayNumber(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { if (ArgList.length == 2) { try {// w ww . j a v a 2 s. com if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return Context.getUndefinedValue(); else { java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); String strType = Context.toString(ArgList[1]); Calendar startDate = Calendar.getInstance(); startDate.setTime(dIn); if (strType.toLowerCase().equals("y")) return new Double(startDate.get(Calendar.DAY_OF_YEAR)); else if (strType.toLowerCase().equals("m")) return new Double(startDate.get(Calendar.DAY_OF_MONTH)); else if (strType.toLowerCase().equals("w")) return new Double(startDate.get(Calendar.DAY_OF_WEEK)); else if (strType.toLowerCase().equals("wm")) return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH)); else if (strType.toLowerCase().equals("l")) return new Long(startDate.getTimeInMillis()); return new Double(startDate.get(Calendar.DAY_OF_YEAR)); } } catch (Exception e) { return null; //throw Context.reportRuntimeError(e.toString()); } } else { throw Context.reportRuntimeError("The function call getDayNumber requires 2 arguments."); } }
From source file:persistence.OrderDao.java
private Date getThreeDaysAgo() { Calendar cl = Calendar.getInstance(); cl.add(Calendar.DAY_OF_YEAR, -3); return cl.getTime(); }
From source file:com.huateng.ebank.framework.util.DateUtil.java
/** * ?/*from w w w . j a va 2 s.c om*/ * * @param endDate * @param days * @return */ public static Date getStartDateByDays(Date endDate, int days) { Calendar calendarEndDate = Calendar.getInstance(); calendarEndDate.setTime(endDate); calendarEndDate.add(Calendar.DAY_OF_YEAR, 0 - days); return calendarEndDate.getTime(); }
From source file:service.OrderService.java
private void setDeadlineDateToNewOrder(Order order) { Date real = order.getRealDate(); if (real != null) { Calendar cl = Calendar.getInstance(); cl.setTime(real);// ww w . ja va 2 s .c om cl.add(Calendar.DAY_OF_YEAR, -1); Date deadline = cl.getTime(); order.setDeadlineDate(deadline); } }
From source file:edu.northwestern.bioinformatics.studycalendar.service.SubjectService.java
private Date idealDate(int studySegmentDay, Date startDate) { Calendar cal = Calendar.getInstance(); cal.setTime(startDate);/* w w w . j a va 2 s . co m*/ cal.add(Calendar.DAY_OF_YEAR, studySegmentDay - 1); return cal.getTime(); }
From source file:org.tolven.analysis.bean.SnapshotBean.java
/** * Based on the age and gender of the patient, this function validated the patients who satisfies * the two cohort properties - Age Ranges and gender.Return either true or false. *//*from ww w . j a va 2 s . c o m*/ @Override public Boolean validateCohortProperties(String type, MenuData patient, AppEvalAdaptor app) { Boolean genderCondition = false; Boolean ageCondition = false; String lowRangeType = ""; String highRangeType = ""; String calcType = ""; int lowRange = 0; int highRange = 0; int ageY = 0; int ageM = 0; int ageD = 0; int ageW = 0; int calcAge = 0; //gender Condition if (app.getAccount().getProperty().get("org.tolven.cohort." + type + ".gender") == null) { genderCondition = true; } else if (app.getAccount().getProperty().get("org.tolven.cohort." + type + ".gender").equals("")) { genderCondition = true; } else if ((app.getAccount().getProperty().get("org.tolven.cohort." + type + ".gender") .equals(patient.getString04().trim())) || (app.getAccount().getProperty().get("org.tolven.cohort." + type + ".gender").equals("Both"))) { genderCondition = true; } //age Condition if (app.getAccount().getProperty().get("org.tolven.cohort." + type + ".ageRangeCodes") == null) { ageCondition = true; } else if (app.getAccount().getProperty().get("org.tolven.cohort." + type + ".ageRangeCodes").equals("")) { ageCondition = true; } else { for (int i = 1; i < app.getAccount().getProperty().get("org.tolven.cohort." + type + ".ageRangeCodes") .split(",").length; i++) { ageCondition = false; lowRange = Integer.parseInt(app.getAccount().getProperty() .get("org.tolven.cohort." + type + ".ageRangeCodes").split(",")[i].split("~")[0]); lowRangeType = app.getAccount().getProperty().get("org.tolven.cohort." + type + ".ageRangeCodes") .split(",")[i].split("~")[1]; highRange = Integer.parseInt(app.getAccount().getProperty() .get("org.tolven.cohort." + type + ".ageRangeCodes").split(",")[i].split("~")[2]); highRangeType = app.getAccount().getProperty().get("org.tolven.cohort." + type + ".ageRangeCodes") .split(",")[i].split("~")[3]; GregorianCalendar n = new GregorianCalendar(); n.setTime(new Date()); GregorianCalendar b = new GregorianCalendar(); b.setTime(patient.getDate01()); int years = n.get(Calendar.YEAR) - b.get(Calendar.YEAR); int days = n.get(Calendar.DAY_OF_YEAR) - b.get(Calendar.DAY_OF_YEAR); if (days < 0) { years--; days = days + 365; } if (years > 1) { calcAge = years; calcType = "year"; } else if (years == 0 && days < 30) { calcAge = days; calcType = "days"; } else { calcAge = years * 12 + (days / 30); calcType = "months"; } if (calcType.equals("year")) { ageD = calcAge * 365; ageM = calcAge * 12; ageY = calcAge; ageW = calcAge * 52; } if (calcType.equals("months")) { ageD = calcAge * 30; ageM = calcAge; ageY = 0; ageW = calcAge / 7; } if (calcType.equals("days")) { ageD = calcAge; ageM = 0; ageY = 0; ageW = calcAge / 7; } if ((lowRangeType.equals("year")) && (highRangeType.equals("year"))) { if ((ageY >= lowRange) && (ageY <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("year")) && (highRangeType.equals("month"))) { if ((ageY >= lowRange) && (ageM <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("year")) && (highRangeType.equals("week"))) { if ((ageY >= lowRange) && (ageW <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("year")) && (highRangeType.equals("day"))) { if ((ageY >= lowRange) && (ageD <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("month")) && (highRangeType.equals("year"))) { if ((ageM >= lowRange) && (ageY <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("month")) && (highRangeType.equals("month"))) { if ((ageM >= lowRange) && (ageM <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("month")) && (highRangeType.equals("week"))) { if ((ageM >= lowRange) && (ageW <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("month")) && (highRangeType.equals("day"))) { if ((ageM >= lowRange) && (ageD <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("week")) && (highRangeType.equals("year"))) { if ((ageW >= lowRange) && (ageY <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("week")) && (highRangeType.equals("month"))) { if ((ageW >= lowRange) && (ageM <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("week")) && (highRangeType.equals("week"))) { if ((ageW >= lowRange) && (ageW <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("week")) && (highRangeType.equals("day"))) { if ((ageW >= lowRange) && (ageD <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("day")) && (highRangeType.equals("year"))) { if ((ageD >= lowRange) && (ageY <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("day")) && (highRangeType.equals("month"))) { if ((ageD >= lowRange) && (ageM <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("day")) && (highRangeType.equals("week"))) { if ((ageD >= lowRange) && (ageW <= highRange)) { ageCondition = true; } } if ((lowRangeType.equals("day")) && (highRangeType.equals("day"))) { if ((ageD >= lowRange) && (ageD <= highRange)) { ageCondition = true; } } if (ageCondition == true) break; } } if (genderCondition == true && ageCondition == true) { return true; } else { return false; } }