List of usage examples for org.joda.time DateTimeConstants DAYS_PER_WEEK
int DAYS_PER_WEEK
To view the source code for org.joda.time DateTimeConstants DAYS_PER_WEEK.
Click Source Link
From source file:com.gst.portfolio.savings.domain.DepositTermDetail.java
License:Apache License
private Integer convertToSafeDays(final Integer period, final SavingsPeriodFrequencyType periodFrequencyType) { Integer toDays = 0;/*from w w w. java 2 s. c om*/ switch (periodFrequencyType) { case DAYS: toDays = period; break; case WEEKS: toDays = period * DateTimeConstants.DAYS_PER_WEEK; break; case MONTHS: toDays = period * 30;// converting to stard 30 days break; case YEARS: toDays = period * 365; break; case INVALID: toDays = 0;// default value break; } return toDays; }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addWeeklyReportUrls(PrintWriter pw, int numWeeklyReports, String metricsServiceUrl) { DateTime input = newDateTime();/*from ww w .j a v a 2s .c om*/ LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numWeeklyReports; i++) { try { DateMidnight startOfLastWeek = new DateMidnight( input.minusWeeks(i).withDayOfWeek(DateTimeConstants.MONDAY)); String startDate = urlEncodeDate(startOfLastWeek); LOGGER.debug("Previous Week {} (start): {}", i, startDate); DateTime endOfLastWeek = startOfLastWeek.plusDays(DateTimeConstants.DAYS_PER_WEEK).toDateTime() .minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastWeek); LOGGER.debug("Previous Week {} (end): ", i, endDate); startTableRow(pw, i); addCellLabelForRange(pw, startOfLastWeek, endOfLastWeek); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding weekly reports", e); } } }
From source file:fi.craplab.roameo.ui.StatisticsWeekFragment.java
License:Open Source License
private void setupData() { DateTime dateTime = getFirstDayOfWeek(); DebugLog.d(TAG, String.format(Locale.US, "Setting up data for week %2d %d starting %s", mWeekNumber, mWeekYear, dateTime));// w ww . j ava2 s. c om for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) { DateTime dt = dateTime.plusDays(day); long steps = CallSession.getStepsForDay(dt.getMillis()); float duration = CallSession.getDurationsForDay(dt.getMillis()) / 1000; float pace = (duration > 0) ? (steps / (duration / 60f)) : 0.0f; mStepValues.add(new PointValue(day, steps)); mDurationValues.add(new PointValue(day, duration)); mPaceValues.add(new PointValue(day, pace)); mDayNameValues.add(day, new AxisValue(day).setLabel(dt.dayOfWeek().getAsShortText())); mDateValues.add(day, new AxisValue(day) .setLabel(String.format(Locale.US, "%02d/%02d", dt.getDayOfMonth(), dt.getMonthOfYear()))); } }
From source file:fi.craplab.roameo.ui.StatisticsWeekFragment.java
License:Open Source License
private LineChartData getData() { Line line = new Line(); List<PointValue> nullValues = new ArrayList<>(); for (int i = 0; i < DateTimeConstants.DAYS_PER_WEEK; i++) { nullValues.add(new PointValue(i, 0)); }//from w w w . ja v a2 s . c om line.setValues(nullValues); line.setColor(ContextCompat.getColor(getContext(), R.color.week_stat_chart_lines)); line.setHasPoints(true); line.setHasLabels(true); line.setFilled(false); line.setPointRadius(8); line.setStrokeWidth(4); line.setCubic(true); List<Line> lines = new ArrayList<>(); lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); Axis dayNameAxis = new Axis(); dayNameAxis.setName(""); dayNameAxis.setTextColor(ContextCompat.getColor(getContext(), R.color.week_stat_axes)); dayNameAxis.setMaxLabelChars(3); dayNameAxis.setValues(mDayNameValues); dayNameAxis.setHasLines(false); dayNameAxis.setHasSeparationLine(false); dayNameAxis.setHasTiltedLabels(true); data.setAxisXTop(dayNameAxis); Axis dateAxis = new Axis(); dateAxis.setName(""); dateAxis.setTextColor(ContextCompat.getColor(getContext(), R.color.week_stat_axes)); dateAxis.setMaxLabelChars(5); dateAxis.setValues(mDateValues); dateAxis.setHasLines(false); dateAxis.setHasSeparationLine(false); dateAxis.setHasTiltedLabels(true); data.setAxisXBottom(dateAxis); Axis valueAxis = new Axis(); valueAxis.setName(""); valueAxis.setTextColor(ContextCompat.getColor(getContext(), R.color.week_stat_axes)); valueAxis.setMaxLabelChars(5); valueAxis.setHasSeparationLine(false); valueAxis.setHasLines(true); valueAxis.setFormatter(new ValueAxisFormatter()); data.setAxisYLeft(valueAxis); return data; }
From source file:kr.debop4j.core.tools.DateTool.java
License:Apache License
/** * Gets end of week.//from ww w. ja va2s . c om * * @param moment the moment * @return the end of week */ public static DateTime getEndOfWeek(final DateTime moment) { return getStartOfWeek(moment).plusDays(DateTimeConstants.DAYS_PER_WEEK).minus(1); }
From source file:org.kuali.kpme.tklm.leave.calendar.LeaveCalendar.java
License:Educational Community License
public LeaveCalendar(String principalId, CalendarEntry calendarEntry, List<String> assignmentKeys) { super(calendarEntry); DateTime currentDisplayDateTime = getBeginDateTime(); DateTime endDisplayDateTime = getEndDateTime(); // Fill in the days if the first day or end day is in the middle of the week if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) { currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek()); }/*from w ww . j a v a 2s . c om*/ if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) { endDisplayDateTime = endDisplayDateTime .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek()); } LeaveCalendarWeek leaveCalendarWeek = new LeaveCalendarWeek(); Integer dayNumber = 0; List<LeaveBlock> blocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Map<String, List<LeaveBlock>> leaveBlockMap = new HashMap<String, List<LeaveBlock>>(); for (LeaveBlock lb : blocks) { String key = lb.getLeaveLocalDate().toString(); if (leaveBlockMap.containsKey(key)) { leaveBlockMap.get(key).add(lb); } else { leaveBlockMap.put(key, createNewLeaveBlockList(lb)); } } //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. Boolean dayEditableFlag = true; LeaveCalendarDocumentHeader header = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getDocumentHeader(principalId, calendarEntry.getBeginPeriodFullDateTime(), calendarEntry.getEndPeriodFullDateTime()); if (header != null && header.getDocumentStatus().equals(HrConstants.ROUTE_STATUS.FINAL)) dayEditableFlag = false; while (currentDisplayDateTime.isBefore(endDisplayDateTime) || currentDisplayDateTime.isEqual(endDisplayDateTime)) { LeaveCalendarDay leaveCalendarDay = new LeaveCalendarDay(); // If the day is not within the current pay period, mark them as read only (gray) if (currentDisplayDateTime.isBefore(getBeginDateTime()) || currentDisplayDateTime.isEqual(getEndDateTime()) || currentDisplayDateTime.isAfter(getEndDateTime())) { leaveCalendarDay.setGray(true); } else { // This is for the div id of the days on the calendar. // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript. // leaveCalendarDay.setDayNumberDelta(currDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT)); // leaveCalendarDay.setDayNumberDelta(currDateTime.getDayOfMonth()); leaveCalendarDay.setDayNumberDelta(dayNumber); LocalDate leaveDate = currentDisplayDateTime.toLocalDate(); List<LeaveBlock> lbs = leaveBlockMap.get(currentDisplayDateTime.toLocalDate().toString()); if (lbs == null) { lbs = Collections.emptyList(); } // use given assignmentKeys to control leave blocks displayed on the calendar if (CollectionUtils.isNotEmpty(lbs) && CollectionUtils.isNotEmpty(assignmentKeys)) { List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService() .filterLeaveBlocksForLeaveCalendar(lbs, assignmentKeys); leaveCalendarDay.setLeaveBlocks(leaveBlocks); } else { leaveCalendarDay.setLeaveBlocks(lbs); } if (HrServiceLocator.getHRPermissionService().canViewLeaveTabsWithNEStatus()) { TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService() .getDocumentHeaderForDate(principalId, leaveDate.toDateTimeAtStartOfDay()); if (tdh != null) { if (DateUtils.isSameDay(leaveDate.toDate(), tdh.getEndDate()) || leaveDate.isAfter(LocalDate.fromDateFields(tdh.getEndDate()))) { leaveCalendarDay.setDayEditable(true); } } else { leaveCalendarDay.setDayEditable(true); } } else { leaveCalendarDay.setDayEditable(true); } //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. if (!dayEditableFlag) leaveCalendarDay.setDayEditable(false); dayNumber++; } leaveCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText()); leaveCalendarDay.setDateString(currentDisplayDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT)); leaveCalendarWeek.getDays().add(leaveCalendarDay); if (leaveCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) { getWeeks().add(leaveCalendarWeek); leaveCalendarWeek = new LeaveCalendarWeek(); } currentDisplayDateTime = currentDisplayDateTime.plusDays(1); } if (!leaveCalendarWeek.getDays().isEmpty()) { getWeeks().add(leaveCalendarWeek); } boolean isPlanningCal = LmServiceLocator.getLeaveCalendarService().isLeavePlanningCalendar(principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Map<String, String> earnCodes = HrServiceLocator.getEarnCodeService().getEarnCodesForDisplay(principalId, isPlanningCal); setEarnCodeList(earnCodes); }
From source file:org.kuali.kpme.tklm.leave.calendar.LeaveRequestCalendar.java
License:Educational Community License
public LeaveRequestCalendar(DateTime beginDateTime, DateTime endDateTime, Map<String, List<LeaveRequestDocument>> leaveReqDocsMap, Map<String, List<LeaveBlock>> leaveBlocksMap, Map<String, List<LeaveBlockHistory>> disapprovedLBMap, String calendarType) { this.calendarType = calendarType; setBeginDateTime(beginDateTime);/*from w ww .ja v a2 s. co m*/ setEndDateTime(endDateTime); DateTime currentDisplayDateTime = new DateTime(beginDateTime.getMillis()); DateTime endDisplayDateTime = new DateTime(endDateTime.getMillis()); // Fill in the days if the first day or end day is in the middle of the week if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) { currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek()); } if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) { endDisplayDateTime = endDisplayDateTime .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek()); } LeaveRequestCalendarWeek leaveReqCalendarWeek = new LeaveRequestCalendarWeek(); Integer dayNumber = 0; while (currentDisplayDateTime.isBefore(endDisplayDateTime) || currentDisplayDateTime.isEqual(endDisplayDateTime)) { LeaveRequestCalendarDay leaveReqCalendarDay = new LeaveRequestCalendarDay(); // If the day is not within the current pay period, mark them as read only (gray) if (StringUtils.equalsIgnoreCase("M", calendarType) && (currentDisplayDateTime.isBefore(getBeginDateTime()) || currentDisplayDateTime.isEqual(getEndDateTime()) || currentDisplayDateTime.isAfter(getEndDateTime()))) { leaveReqCalendarDay.setGray(true); } else { // This is for the div id of the days on the calendar. // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript. leaveReqCalendarDay.setDayNumberDelta(dayNumber); List<LeaveRequestDocument> reqDocs = leaveReqDocsMap .get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveBlock> leaveBlocks = leaveBlocksMap.get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveBlockHistory> disapprovedBlocks = disapprovedLBMap .get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveRequestApprovalRow> rowList = new ArrayList<LeaveRequestApprovalRow>(); if (reqDocs == null) { reqDocs = Collections.emptyList(); } if (leaveBlocks == null) { leaveBlocks = Collections.emptyList(); } List<String> leaveBlockIds = new ArrayList<String>(); if (!reqDocs.isEmpty()) { for (LeaveRequestDocument lrd : reqDocs) { LeaveBlock lb = lrd.getLeaveBlock(); leaveBlockIds.add(lb.getLmLeaveBlockId()); String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveRequestDocId(lrd.getDocumentNumber()); aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setDescription( lrd.getDescription() == null ? lb.getDescription() : lrd.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); rowList.add(aRow); } } if (!leaveBlocks.isEmpty()) { for (LeaveBlock lb : leaveBlocks) { if (!leaveBlockIds.contains(lb.getLmLeaveBlockId())) { String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator .getIdentityService().getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); aRow.setDescription(lb.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); rowList.add(aRow); } } } // Adding disapproved blocks. if (disapprovedBlocks != null && !disapprovedBlocks.isEmpty()) { for (LeaveBlockHistory lb : disapprovedBlocks) { String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); aRow.setDescription(lb.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); rowList.add(aRow); } } leaveReqCalendarDay.setLeaveReqRows(rowList); if (!rowList.isEmpty() && rowList.size() > 0) { requestList.addAll(rowList); } dayNumber++; } leaveReqCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText()); leaveReqCalendarDay .setDateString(currentDisplayDateTime.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); leaveReqCalendarWeek.getDays().add(leaveReqCalendarDay); if (leaveReqCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) { getWeeks().add(leaveReqCalendarWeek); leaveReqCalendarWeek = new LeaveRequestCalendarWeek(); } currentDisplayDateTime = currentDisplayDateTime.plusDays(1); } if (!leaveReqCalendarWeek.getDays().isEmpty()) { getWeeks().add(leaveReqCalendarWeek); } }
From source file:se.toxbee.sleepfighter.text.DateTextUtils.java
License:Open Source License
/** * Returns an array of strings with weekday names. * * @param indiceLength how long each string should be. * @param locale the desired locale.//from w w w . j a va2 s . com * @return the array of strings. */ public static final String[] getWeekdayNames(int indiceLength, Locale locale) { DateTimeFormatter fmt = DateTimeFormat.forPattern(Strings.repeat("E", indiceLength)).withLocale(locale); MutableDateTime time = new MutableDateTime(); time.setDayOfWeek(DateTimeConstants.MONDAY); String[] names = new String[DateTimeConstants.DAYS_PER_WEEK]; for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) { String name = fmt.print(time); if (name.length() > indiceLength) { name = name.substring(0, indiceLength); } names[day] = name; time.addDays(1); } return names; }