Java Code Examples for org.joda.time.LocalDate#dayOfMonth()
The following examples show how to use
org.joda.time.LocalDate#dayOfMonth() .
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: DateRange.java From adwords-alerting with Apache License 2.0 | 4 votes |
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. */ private static DateRange parseEnumFormat(String dateRange) { ReportDefinitionDateRangeType dateRangeType; try { dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unknown DateRange type: " + dateRange); } LocalDate today = LocalDate.now(); LocalDate startDate; LocalDate endDate; switch (dateRangeType) { case TODAY: startDate = endDate = today; break; case YESTERDAY: startDate = endDate = today.minusDays(1); break; case LAST_7_DAYS: startDate = today.minusDays(7); endDate = today.minusDays(1); break; case LAST_WEEK: LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek(); startDate = lastWeekProp.withMinimumValue(); endDate = lastWeekProp.withMaximumValue(); break; case THIS_MONTH: LocalDate.Property thisMonthProp = today.dayOfMonth(); startDate = thisMonthProp.withMinimumValue(); endDate = thisMonthProp.withMaximumValue(); break; case LAST_MONTH: LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth(); startDate = lastMonthProp.withMinimumValue(); endDate = lastMonthProp.withMaximumValue(); break; case LAST_14_DAYS: startDate = today.minusDays(14); endDate = today.minusDays(1); break; case LAST_30_DAYS: startDate = today.minusDays(30); endDate = today.minusDays(1); break; case THIS_WEEK_SUN_TODAY: // Joda-Time uses the ISO standard Monday to Sunday week. startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue(); endDate = today; break; case THIS_WEEK_MON_TODAY: startDate = today.dayOfWeek().withMinimumValue(); endDate = today; break; case LAST_WEEK_SUN_SAT: startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue(); endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1); break; // Don't support the following enums case LAST_BUSINESS_WEEK: case ALL_TIME: case CUSTOM_DATE: default: throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange); } return new DateRange(startDate, endDate); }
Example 2
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 4 votes |
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. */ private static DateRangeAndType parseEnumFormat(ReportDefinitionDateRangeType type) { LocalDate today = LocalDate.now(); LocalDate startDate; LocalDate endDate; switch (type) { case TODAY: startDate = endDate = today; break; case YESTERDAY: startDate = endDate = today.minusDays(1); break; case LAST_7_DAYS: startDate = today.minusDays(7); endDate = today.minusDays(1); break; case LAST_WEEK: LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek(); startDate = lastWeekProp.withMinimumValue(); endDate = lastWeekProp.withMaximumValue(); break; case THIS_MONTH: LocalDate.Property thisMonthProp = today.dayOfMonth(); startDate = thisMonthProp.withMinimumValue(); endDate = thisMonthProp.withMaximumValue(); break; case LAST_MONTH: LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth(); startDate = lastMonthProp.withMinimumValue(); endDate = lastMonthProp.withMaximumValue(); break; case LAST_14_DAYS: startDate = today.minusDays(14); endDate = today.minusDays(1); break; case LAST_30_DAYS: startDate = today.minusDays(30); endDate = today.minusDays(1); break; case THIS_WEEK_SUN_TODAY: // Joda-Time uses the ISO standard Monday to Sunday week. startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue(); endDate = today; break; case THIS_WEEK_MON_TODAY: startDate = today.dayOfWeek().withMinimumValue(); endDate = today; break; case LAST_WEEK_SUN_SAT: startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue(); endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1); break; // Don't support the following enums case LAST_BUSINESS_WEEK: case ALL_TIME: case CUSTOM_DATE: default: throw new IllegalArgumentException("Unsupported DateRange type: " + type.value()); } return new DateRangeAndType(startDate, endDate, type); }