List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:org.kuali.rice.kew.docsearch.xml.StandardGenericXMLSearchableAttributeRangesTest.java
@Test public void testDateRanges() throws Exception { WorkflowDocument doc = setUpSearchableDoc(); String userId = doc.getInitiatorPrincipalId(); String docType = doc.getDocumentTypeName(); // begin datetime attribute value testing // inclusive = ? String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY; Calendar searchAttributeDateTimeValue = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE .toGregorianCalendar();/*from w w w . jav a2 s .c o m*/ Calendar calendarValueToUse = null; // test lower bound only calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); // lower == value String valueToSearch = DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)); // NOTE: matches now assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 1); calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); calendarValueToUse.add(Calendar.DATE, -1); // lower < value valueToSearch = DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)); assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 1); calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); calendarValueToUse.add(Calendar.DATE, 1); // lower > value valueToSearch = DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)); assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 0); // test upper bound only calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); // upper == value (inclusivity true) assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 1); calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); calendarValueToUse.add(Calendar.DATE, -1); // upper < value assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 0); calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone(); calendarValueToUse.add(Calendar.DATE, 1); // upper > value assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 1); // test both bounds Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); // upper == lower == value (inclusivity true) // NOTE: matches now assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 1); lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); lowerBoundValue.add(Calendar.DATE, 2); upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); upperBoundValue.add(Calendar.DATE, 4); // upper and lower > value assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 0); lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); lowerBoundValue.add(Calendar.DATE, -4); upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); upperBoundValue.add(Calendar.DATE, -2); // upper and lower < value assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 0); lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); lowerBoundValue.add(Calendar.DATE, -2); upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); upperBoundValue.add(Calendar.DATE, 2); // lower < value, upper > value assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 1); lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); lowerBoundValue.add(Calendar.DATE, 2); upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone(); upperBoundValue.add(Calendar.DATE, -2); // lower > upper == error assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, EXPECT_EXCEPTION); }
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();// w w w . jav a 2s . c o 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:captureplugin.drivers.dreambox.connector.DreamboxConnector.java
/** * @param config//from ww w . j a v a 2 s. co m * DreamboxConfig * @return List of recordings on the dreambox */ public ProgramTime[] getRecordings(DreamboxConfig config) { ArrayList<ProgramTime> programs = new ArrayList<ProgramTime>(); ArrayList<HashMap<String, String>> timers = getTimers(); if (timers == null) { return new ProgramTime[0]; } for (HashMap<String, String> timer : timers) { DreamboxChannel channel = config.getDreamboxChannelForRef(timer.get("e2servicereference")); if (channel != null) { Channel tvbchannel = config.getChannel(channel); if (tvbchannel != null) { Calendar begin = Calendar.getInstance(); begin.setTimeInMillis(getLong(timer.get("e2timebegin")) * 1000); int beginMinutes = begin.get(Calendar.HOUR_OF_DAY) * 60 + begin.get(Calendar.MINUTE); Calendar end = Calendar.getInstance(); end.setTimeInMillis(getLong(timer.get("e2timeend")) * 1000); int endMinutes = end.get(Calendar.HOUR_OF_DAY) * 60 + end.get(Calendar.MINUTE); if (endMinutes < beginMinutes) { endMinutes += 24 * 60; } Calendar runner = (Calendar) begin.clone(); long days = end.get(Calendar.DAY_OF_YEAR) - begin.get(Calendar.DAY_OF_YEAR); if (end.get(Calendar.YEAR) != begin.get(Calendar.YEAR)) { days = 1; } for (int i = 0; i <= days; i++) { Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(new Date(runner), tvbchannel); boolean found = false; while (it.hasNext() && !found) { Program prog = it.next(); int progTime = prog.getHours() * 60 + prog.getMinutes() + (i * 24 * 60); if (progTime >= beginMinutes - 15 && progTime <= endMinutes + 15 && prog.getTitle().trim().equalsIgnoreCase(timer.get("e2name").trim())) { found = true; programs.add(new ProgramTime(prog, begin.getTime(), end.getTime())); } } runner.add(Calendar.HOUR_OF_DAY, 24); } } } } return programs.toArray(new ProgramTime[programs.size()]); }
From source file:com.alkacon.opencms.calendar.CmsSerialDateWidget.java
/** * Returns the macro resolver with initialized macros to generate the serial date input form.<p> * //from w w w . java 2 s .c o m * @param cms an initialized instance of a CmsObject * @param widgetDialog the dialog where the widget is used on * @param param the widget parameter to generate the widget for * @return the macro resolver with initialized macros */ protected CmsMacroResolver getMacroResolverForForm(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { CmsMacroResolver resolver = CmsMacroResolver.newInstance(); // set cms object and localized messages in resolver resolver.setCmsObject(cms); CmsMessages messages = new CmsMessages(CmsSerialDateWidget.class.getPackage().getName() + ".messages", widgetDialog.getLocale()); resolver.setMessages(messages); // delete empty macros which were not replaced resolver.setKeepEmptyMacros(false); // create the serial entry date object String paramValue = param.getStringValue(cms); Map params = CmsStringUtil.splitAsMap(paramValue, String.valueOf(CmsProperty.VALUE_LIST_DELIMITER), String.valueOf(CmsProperty.VALUE_MAP_DELIMITER)); // create the entry date from the field values CmsCalendarEntryDateSerial entryDate = CmsCalendarSerialDateFactory.getSerialDate(params, widgetDialog.getLocale()); if (entryDate == null) { // no entry date created yet, build an empty default date Calendar start = new GregorianCalendar(widgetDialog.getLocale()); Calendar end = (Calendar) start.clone(); entryDate = new CmsCalendarEntryDateSerial(start, end); entryDate.setSerialEndType(I_CmsCalendarSerialDateOptions.END_TYPE_NEVER); } // vars for daily options String dayDailyInterval = "1"; boolean dayEveryWorkingDay = false; // vars for weekly options String weekWeeklyInterval = "1"; // vars for monthly options int monthSelectedIndexWeekDayOfMonth = 0; int monthSelectedWeekDay = -1; String monthDayOfMonth = "1"; String monthMonthlyInterval = "1"; String monthMonthlyIntervalWeekDay = "1"; boolean monthUseWeekday = false; // vars for yearly options String yearDayOfMonth = "1"; boolean yearUseWeekday = false; int yearSelectedIndexMonth = 0; int yearSelectedIndexWeekDayOfMonth = 0; int yearSelectedWeekDayDay = -1; int yearSelectedIndexWeekDayMonth = 0; if (entryDate.getSerialOptions() != null) { // fill the variables depending on the selected serial date type String serialTypeMacroPrefix = MACRO_PREFIX_PARAMVALUE + PARAM_SERIALTYPE + "."; // set serial type radio selection resolver.addMacro(serialTypeMacroPrefix + entryDate.getSerialOptions().getSerialType(), ATTR_CHECKED); switch (entryDate.getSerialOptions().getSerialType()) { // set values for the selected serial type case I_CmsCalendarSerialDateOptions.TYPE_DAILY: CmsCalendarSerialDateDailyOptions dailyOptions = (CmsCalendarSerialDateDailyOptions) entryDate .getSerialOptions(); dayEveryWorkingDay = dailyOptions.isEveryWorkingDay(); dayDailyInterval = String.valueOf(dailyOptions.getDailyInterval()); break; case I_CmsCalendarSerialDateOptions.TYPE_WEEKLY: CmsCalendarSerialDateWeeklyOptions weeklyOptions = (CmsCalendarSerialDateWeeklyOptions) entryDate .getSerialOptions(); weekWeeklyInterval = String.valueOf(weeklyOptions.getWeeklyInterval()); // check the chosen week day checkboxes serialTypeMacroPrefix = MACRO_PREFIX_PARAMVALUE + PARAM_WEEK_WEEKDAY + "."; if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.MONDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.MONDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.TUESDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.TUESDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.WEDNESDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.WEDNESDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.THURSDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.THURSDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.FRIDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.FRIDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.SATURDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.SATURDAY, ATTR_CHECKED); } if (weeklyOptions.getWeekDays().contains(new Integer(Calendar.SUNDAY))) { resolver.addMacro(serialTypeMacroPrefix + Calendar.SUNDAY, ATTR_CHECKED); } break; case I_CmsCalendarSerialDateOptions.TYPE_MONTHLY: CmsCalendarSerialDateMonthlyOptions monthlyOptions = (CmsCalendarSerialDateMonthlyOptions) entryDate .getSerialOptions(); monthUseWeekday = monthlyOptions.isUseWeekDay(); if (!monthlyOptions.isUseWeekDay()) { monthDayOfMonth = String.valueOf(monthlyOptions.getDayOfMonth()); monthMonthlyInterval = String.valueOf(monthlyOptions.getMonthlyInterval()); } else { // set selected index of select boxes monthSelectedIndexWeekDayOfMonth = monthlyOptions.getDayOfMonth() - 1; monthSelectedWeekDay = monthlyOptions.getWeekDay(); monthMonthlyIntervalWeekDay = String.valueOf(monthlyOptions.getMonthlyInterval()); } break; case I_CmsCalendarSerialDateOptions.TYPE_YEARLY: CmsCalendarSerialDateYearlyOptions yearlyOptions = (CmsCalendarSerialDateYearlyOptions) entryDate .getSerialOptions(); yearUseWeekday = yearlyOptions.isUseWeekDay(); if (!yearlyOptions.isUseWeekDay()) { yearDayOfMonth = String.valueOf(yearlyOptions.getDayOfMonth()); yearSelectedIndexMonth = yearlyOptions.getMonth(); } else { yearSelectedIndexWeekDayOfMonth = yearlyOptions.getDayOfMonth() - 1; yearSelectedWeekDayDay = yearlyOptions.getWeekDay(); yearSelectedIndexWeekDayMonth = yearlyOptions.getMonth(); } break; default: // nothing do do here, should never happen } } else { // no serial entry created yet, add some defaults resolver.addMacro( MACRO_PREFIX_PARAMVALUE + PARAM_SERIALTYPE + "." + I_CmsCalendarSerialDateOptions.TYPE_DAILY, ATTR_CHECKED); resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_WEEK_WEEKDAY + "." + Calendar.MONDAY, ATTR_CHECKED); } // set time settings String startTime = getCalendarLocalizedTime(widgetDialog.getLocale(), widgetDialog.getMessages(), entryDate.getStartDate().getTimeInMillis(), false, true); resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_STARTTIME, startTime); String endTime = ""; if (!entryDate.getStartDate().equals(entryDate.getEndDate())) { // end time is different from start time, get localized value endTime = getCalendarLocalizedTime(widgetDialog.getLocale(), widgetDialog.getMessages(), entryDate.getEndDate().getTimeInMillis(), false, true); } resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_ENDTIME, endTime); resolver.addMacro("select.durationdays", buildSelectDurationDays(PARAM_DURATIONDAYS, messages, entryDate.getDuration())); // set found values to serial option tabs // daily options resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_DAY_DAILYINTERVAL, dayDailyInterval); resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_DAY_EVERYWORKINGDAY + "." + dayEveryWorkingDay, ATTR_CHECKED); // weekly options resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_WEEK_WEEKLYINTERVAL, weekWeeklyInterval); // monthly options // mark the correct radio resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_MONTH_SERIALMONTHDAY + "." + monthUseWeekday, ATTR_CHECKED); // set the macros for the day of month options resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_MONTH_DAYOFMONTH, monthDayOfMonth); resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_MONTH_MONTHLYINTERVAL, monthMonthlyInterval); // set the macros for the week day of month options resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_MONTH_MONTHLYINTERVALWEEKDAY, monthMonthlyIntervalWeekDay); // build the select boxes resolver.addMacro("select.monthnumberofweekday", buildSelectNumberOfWeekDayOfMonth( PARAM_MONTH_NUMBEROFWEEKDAYOFMONTH, "onfocus=\"document.getElementById('" + PARAM_MONTH_SERIALMONTHDAY + ".true').checked = true;\"", messages, monthSelectedIndexWeekDayOfMonth)); resolver.addMacro("select.monthweekday", buildSelectWeekDay(PARAM_MONTH_WEEKDAY, "onfocus=\"document.getElementById('" + PARAM_MONTH_SERIALMONTHDAY + ".true').checked = true;\"", messages, monthSelectedWeekDay)); // yearly options // mark the correct radio resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_YEAR_SERIALYEARDAY + "." + yearUseWeekday, ATTR_CHECKED); // set the macros for the day of month options resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_YEAR_DAYOFMONTH, yearDayOfMonth); resolver.addMacro("select.yearmonth", buildSelectMonth(PARAM_YEAR_MONTH, "onfocus=\"document.getElementById('" + PARAM_YEAR_SERIALYEARDAY + ".false').checked = true;\"", messages, yearSelectedIndexMonth)); // set the macros for the week day of month options resolver.addMacro("select.yearnumberofweekday", buildSelectNumberOfWeekDayOfMonth(PARAM_YEAR_WEEKDAYOFMONTH, "onfocus=\"document.getElementById('" + PARAM_YEAR_SERIALYEARDAY + ".true').checked = true;\"", messages, yearSelectedIndexWeekDayOfMonth)); resolver.addMacro("select.yearweekday", buildSelectWeekDay(PARAM_YEAR_WEEKDAY, "onfocus=\"document.getElementById('" + PARAM_YEAR_SERIALYEARDAY + ".true').checked = true;\"", messages, yearSelectedWeekDayDay)); resolver.addMacro("select.yearmonthweekday", buildSelectMonth(PARAM_YEAR_WEEKDAYMONTH, "onfocus=\"document.getElementById('" + PARAM_YEAR_SERIALYEARDAY + ".true').checked = true;\"", messages, yearSelectedIndexWeekDayMonth)); // set serial duration values // set start date resolver.addMacro("calendar.startdate", buildDateInput("startdate", widgetDialog, entryDate.getStartDate())); Calendar serialEndDate = entryDate.getSerialEndDate(); if (serialEndDate == null) { serialEndDate = entryDate.getStartDate(); } resolver.addMacro("calendar.serialenddate", buildDateInput("serialenddate", widgetDialog, serialEndDate)); // set occurences int occurences = 10; if (entryDate.getSerialEndType() == I_CmsCalendarSerialDateOptions.END_TYPE_TIMES) { occurences = entryDate.getOccurences(); } resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_OCCURENCES, String.valueOf(occurences)); // set the end type radio buttons resolver.addMacro(MACRO_PREFIX_PARAMVALUE + PARAM_ENDTYPE + "." + entryDate.getSerialEndType(), ATTR_CHECKED); return resolver; }
From source file:com.wdullaer.materialdatetimepicker.date.DatePickerDialog.java
/** * Sets the minimal date supported by this DatePicker. Dates before (but not including) the * specified date will be disallowed from being selected. * @param calendar a Calendar object set to the year, month, day desired as the mindate. *//*from w w w . j ava 2 s . com*/ @SuppressWarnings("unused") public void setMinDate(Calendar calendar) { mMinDate = trimToMidnight((Calendar) calendar.clone()); if (mDayPickerView != null) { mDayPickerView.onChange(); } }
From source file:com.wdullaer.materialdatetimepicker.date.DatePickerDialog.java
/** * Sets the minimal date supported by this DatePicker. Dates after (but not including) the * specified date will be disallowed from being selected. * @param calendar a Calendar object set to the year, month, day desired as the maxdate. *//*ww w .java2 s . c o m*/ @SuppressWarnings("unused") public void setMaxDate(Calendar calendar) { mMaxDate = trimToMidnight((Calendar) calendar.clone()); if (mDayPickerView != null) { mDayPickerView.onChange(); } }
From source file:com.nadmm.airports.ActivityBase.java
protected void showFaddsEffectiveDate(Cursor c) { TextView tv = (TextView) findViewById(R.id.effective_date); if (tv != null) { String s = c.getString(c.getColumnIndex(Airports.EFFECTIVE_DATE)); Date date = TimeUtils.parseFaaDate(s); if (date != null) { Calendar start = Calendar.getInstance(); start.setTime(date);//from www. j av a2 s . com start.add(Calendar.MINUTE, 9 * 60 + 1); Calendar end = (Calendar) start.clone(); end.add(Calendar.DATE, 56); s = TimeUtils.formatDateRange(this, start, end); tv.setText(s); } } }
From source file:com.s3d.webapps.util.time.DateUtils.java
/** * <p>This constructs an <code>Iterator</code> over each day in a date * range defined by a focus date and range style.</p> * * <p>For instance, passing Thursday, July 4, 2002 and a * <code>RANGE_MONTH_SUNDAY</code> will return an <code>Iterator</code> * that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, * 2002, returning a Calendar instance for each intermediate day.</p> * * <p>This method provides an iterator that returns Calendar objects. * The days are progressed using {@link Calendar#add(int, int)}.</p> * * @param focus the date to work with/*from ww w . j a v a 2 s. com*/ * @param rangeStyle the style constant to use. Must be one of * {@link DateUtils#RANGE_MONTH_SUNDAY}, * {@link DateUtils#RANGE_MONTH_MONDAY}, * {@link DateUtils#RANGE_WEEK_SUNDAY}, * {@link DateUtils#RANGE_WEEK_MONDAY}, * {@link DateUtils#RANGE_WEEK_RELATIVE}, * {@link DateUtils#RANGE_WEEK_CENTER} * @return the date iterator * @throws IllegalArgumentException if the date is <code>null</code> * @throws IllegalArgumentException if the rangeStyle is invalid */ @SuppressWarnings("rawtypes") public static Iterator iterator(Calendar focus, int rangeStyle) { if (focus == null) { throw new IllegalArgumentException("The date must not be null"); } Calendar start = null; Calendar end = null; int startCutoff = Calendar.SUNDAY; int endCutoff = Calendar.SATURDAY; switch (rangeStyle) { case RANGE_MONTH_SUNDAY: case RANGE_MONTH_MONDAY: //Set start to the first of the month start = truncate(focus, Calendar.MONTH); //Set end to the last of the month end = (Calendar) start.clone(); end.add(Calendar.MONTH, 1); end.add(Calendar.DATE, -1); //Loop start back to the previous sunday or monday if (rangeStyle == RANGE_MONTH_MONDAY) { startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; } break; case RANGE_WEEK_SUNDAY: case RANGE_WEEK_MONDAY: case RANGE_WEEK_RELATIVE: case RANGE_WEEK_CENTER: //Set start and end to the current date start = truncate(focus, Calendar.DATE); end = truncate(focus, Calendar.DATE); switch (rangeStyle) { case RANGE_WEEK_SUNDAY: //already set by default break; case RANGE_WEEK_MONDAY: startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; break; case RANGE_WEEK_RELATIVE: startCutoff = focus.get(Calendar.DAY_OF_WEEK); endCutoff = startCutoff - 1; break; case RANGE_WEEK_CENTER: startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3; endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3; break; } break; default: throw new IllegalArgumentException("The range style " + rangeStyle + " is not valid."); } if (startCutoff < Calendar.SUNDAY) { startCutoff += 7; } if (startCutoff > Calendar.SATURDAY) { startCutoff -= 7; } if (endCutoff < Calendar.SUNDAY) { endCutoff += 7; } if (endCutoff > Calendar.SATURDAY) { endCutoff -= 7; } while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) { start.add(Calendar.DATE, -1); } while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) { end.add(Calendar.DATE, 1); } return new DateIterator(start, end); }
From source file:org.mule.modules.salesforce.SalesforceModule.java
/** * Retrieves the list of individual records that have been created/updated within the given timespan for the specified object. * <p/>//w ww .j a va 2s . c o m * {@sample.xml ../../../doc/mule-module-sfdc.xml.sample sfdc:get-updated-range} * * @param type Object type. The specified value must be a valid object for your organization. * @param startTime Starting date/time (Coordinated Universal Time (UTC)not local timezone) of the timespan for * which to retrieve the data. The API ignores the seconds portion of the specified dateTime value ' * (for example, 12:30:15 is interpreted as 12:30:00 UTC). * @param endTime Ending date/time (Coordinated Universal Time (UTC)not local timezone) of the timespan for * which to retrieve the data. The API ignores the seconds portion of the specified dateTime value * (for example, 12:35:15 is interpreted as 12:35:00 UTC). If it is not provided, the current * server time will be used. * @return {@link GetUpdatedResult} * @throws Exception * @api.doc <a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_getupdatedrange.htm">getUpdatedRange()</a> */ @Processor @InvalidateConnectionOn(exception = SoapConnection.SessionTimedOutException.class) public GetUpdatedResult getUpdatedRange( @Placement(group = "Information") @FriendlyName("sObject Type") String type, @Placement(group = "Information") @FriendlyName("Start Time Reference") Calendar startTime, @Placement(group = "Information") @FriendlyName("End Time Reference") @Optional Calendar endTime) throws Exception { if (endTime == null) { Calendar serverTime = connection.getServerTimestamp().getTimestamp(); endTime = (Calendar) serverTime.clone(); if (endTime.getTimeInMillis() - startTime.getTimeInMillis() < 60000) { endTime.add(Calendar.MINUTE, 1); } } return connection.getUpdated(type, startTime, endTime); }
From source file:org.mule.modules.salesforce.SalesforceModule.java
/** * Retrieves the list of individual records that have been deleted within the given timespan for the specified object. * <p/>/*from w ww.ja v a2 s . com*/ * {@sample.xml ../../../doc/mule-module-sfdc.xml.sample sfdc:get-deleted-range} * {@sample.java ../../../doc/mule-module-sfdc.java.sample sfdc:get-deleted-range} * * @param type Object type. The specified value must be a valid object for your organization. * @param startTime Starting date/time (Coordinated Universal Time (UTC)not local timezone) of the timespan for * which to retrieve the data. The API ignores the seconds portion of the specified dateTime value ' * (for example, 12:30:15 is interpreted as 12:30:00 UTC). * @param endTime Ending date/time (Coordinated Universal Time (UTC)not local timezone) of the timespan for * which to retrieve the data. The API ignores the seconds portion of the specified dateTime value * (for example, 12:35:15 is interpreted as 12:35:00 UTC). If not specific, the current server * time will be used. * @return {@link GetDeletedResult} * @throws Exception * @api.doc <a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_getdeletedrange.htm">getDeletedRange()</a> * @since 4.0 */ @Processor @InvalidateConnectionOn(exception = SoapConnection.SessionTimedOutException.class) public GetDeletedResult getDeletedRange( @Placement(group = "Information") @FriendlyName("sObject Type") String type, @Placement(group = "Information") @FriendlyName("Start Time Reference") Calendar startTime, @Placement(group = "Information") @FriendlyName("End Time Reference") @Optional Calendar endTime) throws Exception { if (endTime == null) { Calendar serverTime = connection.getServerTimestamp().getTimestamp(); endTime = (Calendar) serverTime.clone(); if (endTime.getTimeInMillis() - startTime.getTimeInMillis() < 60000) { endTime.add(Calendar.MINUTE, 1); } } return connection.getDeleted(type, startTime, endTime); }