Java Code Examples for org.joda.time.LocalDate#getDayOfWeek()
The following examples show how to use
org.joda.time.LocalDate#getDayOfWeek() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UDFTypeOfDay.java From hive-third-functions with Apache License 2.0 | 6 votes |
/** * Get whether is holiday or not. * * @param dateString the dateString in the format of "yyyyMMdd". * @return 1: 法定节假日, 2: 正常周末, 3: 正常工作日 4:攒假的工作日 */ public IntWritable evaluate(Text dateString) { if (dateString == null) { return null; } try { String value = dayMap.get(dateString.toString()); if (DayType.HOLIDAY.getCode().equalsIgnoreCase(value)) { result.set(1); } else if (DayType.WORKDAY.getCode().equalsIgnoreCase(value)) { result.set(4); } else { LocalDate date = LocalDate.parse(dateString.toString(), DEFAULT_DATE_FORMATTER); if (date.getDayOfWeek() < 6) { result.set(3); } else { result.set(2); } } return result; } catch (Exception e) { return null; } }
Example 2
Source File: CronExpression.java From chronos with BSD 3-Clause "New" or "Revised" License | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfWeek() == part.from && dato.getDayOfMonth() > (dato.dayOfMonth().getMaximumValue() - DAYS_PER_WEEK); } else if ("#".equals(part.incrementModifier)) { if (dato.getDayOfWeek() == part.from) { int num = dato.getDayOfMonth() / 7; return part.increment == (dato.getDayOfMonth() % 7 == 0 ? num : num + 1); } return false; } else if (matches(dato.getDayOfWeek(), part)) { return true; } } return false; }
Example 3
Source File: CronExpression.java From chronos with BSD 3-Clause "New" or "Revised" License | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfMonth() == (dato.dayOfMonth().getMaximumValue() - (part.from == null ? 0 : part.from)); } else if ("W".equals(part.modifier)) { if (dato.getDayOfWeek() <= 5) { if (dato.getDayOfMonth() == part.from) { return true; } else if (dato.getDayOfWeek() == 5) { return dato.plusDays(1).getDayOfMonth() == part.from; } else if (dato.getDayOfWeek() == 1) { return dato.minusDays(1).getDayOfMonth() == part.from; } } } else if (matches(dato.getDayOfMonth(), part)) { return true; } } return false; }
Example 4
Source File: CronExpression.java From cron with Apache License 2.0 | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfWeek() == part.from && dato.getDayOfMonth() > (dato.dayOfMonth().getMaximumValue() - DAYS_PER_WEEK); } else if ("#".equals(part.incrementModifier)) { if (dato.getDayOfWeek() == part.from) { int num = dato.getDayOfMonth() / 7; return part.increment == (dato.getDayOfMonth() % 7 == 0 ? num : num + 1); } return false; } else if (matches(dato.getDayOfWeek(), part)) { return true; } } return false; }
Example 5
Source File: CronExpression.java From cron with Apache License 2.0 | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfMonth() == (dato.dayOfMonth().getMaximumValue() - (part.from == null ? 0 : part.from)); } else if ("W".equals(part.modifier)) { if (dato.getDayOfWeek() <= 5) { if (dato.getDayOfMonth() == part.from) { return true; } else if (dato.getDayOfWeek() == 5) { return dato.plusDays(1).getDayOfMonth() == part.from; } else if (dato.getDayOfWeek() == 1) { return dato.minusDays(1).getDayOfMonth() == part.from; } } } else if (matches(dato.getDayOfMonth(), part)) { return true; } } return false; }
Example 6
Source File: CronExpression.java From actframework with Apache License 2.0 | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfWeek() == part.from && dato.getDayOfMonth() > (dato.dayOfMonth().getMaximumValue() - DAYS_PER_WEEK); } else if ("#".equals(part.incrementModifier)) { if (dato.getDayOfWeek() == part.from) { int num = dato.getDayOfMonth() / 7; return part.increment == (dato.getDayOfMonth() % 7 == 0 ? num : num + 1); } return false; } else if (matches(dato.getDayOfWeek(), part)) { return true; } } return false; }
Example 7
Source File: CronExpression.java From actframework with Apache License 2.0 | 6 votes |
boolean matches(LocalDate dato) { for (FieldPart part : parts) { if ("L".equals(part.modifier)) { return dato.getDayOfMonth() == (dato.dayOfMonth().getMaximumValue() - (part.from == null ? 0 : part.from)); } else if ("W".equals(part.modifier)) { if (dato.getDayOfWeek() <= 5) { if (dato.getDayOfMonth() == part.from) { return true; } else if (dato.getDayOfWeek() == 5) { return dato.plusDays(1).getDayOfMonth() == part.from; } else if (dato.getDayOfWeek() == 1) { return dato.minusDays(1).getDayOfMonth() == part.from; } } } else if (matches(dato.getDayOfMonth(), part)) { return true; } } return false; }
Example 8
Source File: DateTimeFunctions.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the number of working days between two dates (inclusive). Saturday and Sunday are not considered working days. */ @Function("NETWORKDAYS") @FunctionParameters({ @FunctionParameter("startDate"), @FunctionParameter("endDate")}) public Integer NETWORKDAYS(Object startDate, Object endDate){ Date startDateObj = convertDateObject(startDate); if(startDateObj==null) { logCannotConvertToDate(); return null; } Date endDateObj = convertDateObject(endDate); if(endDateObj==null){ logCannotConvertToDate(); return null; } else{ LocalDate cursorLocalDate=new LocalDate(startDateObj); LocalDate endLocalDate=new LocalDate(endDateObj); int workingDays=0; if(cursorLocalDate.isAfter(endLocalDate)){ // Swap data information LocalDate tmp=cursorLocalDate; cursorLocalDate=endLocalDate; endLocalDate=tmp; } while (Days.daysBetween(cursorLocalDate, endLocalDate).getDays()>0){ int dayOfWeek = cursorLocalDate.getDayOfWeek(); if(!(dayOfWeek==DateTimeConstants.SATURDAY || dayOfWeek==DateTimeConstants.SUNDAY)){ workingDays++; } cursorLocalDate=cursorLocalDate.plusDays(1); } return workingDays; } }
Example 9
Source File: BiWeeklyPeriodFilter.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DateTime getStartDayOfFirstBiWeek(DateTime date){ LocalDate localDate = new LocalDate( date.getYear(), date.getMonthOfYear(), 1 ); while ( localDate.getDayOfWeek() != DateTimeConstants.MONDAY ) { localDate = localDate.plusDays( 1 ); } return localDate.toDateTimeAtStartOfDay(); }