List of usage examples for org.joda.time LocalDate dayOfMonth
public Property dayOfMonth()
From source file:com.google.api.ads.adwords.awalerting.util.DateRange.java
License:Open Source License
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. *//*from ww w . j a v a2 s. c o m*/ 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); }
From source file:com.google.api.ads.adwords.awreporting.model.entities.DateRangeAndType.java
License:Open Source License
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. *///from w w w . ja v a 2 s . c o m 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); }
From source file:com.google.api.ads.adwords.awreporting.model.util.DateUtil.java
License:Open Source License
/** * Get a LocalDate for the first day of a month. * @return LocalDate/*from w ww . java 2 s . c o m*/ */ public static LocalDate firstDayMonth(LocalDate localDate) { return localDate.dayOfMonth().withMinimumValue(); }
From source file:com.google.api.ads.adwords.awreporting.model.util.DateUtil.java
License:Open Source License
/** * Get a LocalDate for the last day of a month. * @return LocalDate/*from w w w . j a va 2 s. co m*/ */ public static LocalDate lastDayMonth(LocalDate localDate) { return localDate.dayOfMonth().withMaximumValue(); }
From source file:com.gst.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static LocalDate adjustDate(final LocalDate date, final LocalDate seedDate, final PeriodFrequencyType frequencyType) { LocalDate adjustedVal = date; if (frequencyType.isMonthly() && seedDate.getDayOfMonth() > 28) { switch (date.getMonthOfYear()) { case 2:/*from w w w . java2 s .c o m*/ if (date.year().isLeap()) { adjustedVal = date.dayOfMonth().setCopy(29); } break; case 4: case 6: case 9: case 11: if (seedDate.getDayOfMonth() > 30) { adjustedVal = date.dayOfMonth().setCopy(30); } else { adjustedVal = date.dayOfMonth().setCopy(seedDate.getDayOfMonth()); } break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: adjustedVal = date.dayOfMonth().setCopy(seedDate.getDayOfMonth()); break; } } return adjustedVal; }
From source file:com.gst.portfolio.savings.domain.interest.PostingPeriod.java
License:Apache License
private static LocalDate determineInterestPeriodEndDateFrom(final LocalDate periodStartDate, final SavingsCompoundingInterestPeriodType interestPeriodType, final LocalDate upToInterestCalculationDate) { LocalDate periodEndDate = upToInterestCalculationDate; switch (interestPeriodType) { case INVALID: break;//from w w w . j a v a2 s . c om case DAILY: periodEndDate = periodStartDate; break; // case WEEKLY: // periodEndDate = periodStartDate.dayOfWeek().withMaximumValue(); // break; // case BIWEEKLY: // final LocalDate closestEndOfWeek = // periodStartDate.dayOfWeek().withMaximumValue(); // periodEndDate = closestEndOfWeek.plusWeeks(1); // break; case MONTHLY: // produce period end date on last day of current month periodEndDate = periodStartDate.dayOfMonth().withMaximumValue(); break; case QUATERLY: // // jan 1st to mar 31st, 1st apr to jun 30, jul 1st to sept // 30, // // oct 1st to dec 31 int year = periodStartDate.getYearOfEra(); int monthofYear = periodStartDate.getMonthOfYear(); if (monthofYear <= 3) { periodEndDate = new DateTime().withDate(year, 3, 31).toLocalDate(); } else if (monthofYear <= 6) { periodEndDate = new DateTime().withDate(year, 6, 30).toLocalDate(); } else if (monthofYear <= 9) { periodEndDate = new DateTime().withDate(year, 9, 30).toLocalDate(); } else if (monthofYear <= 12) { periodEndDate = new DateTime().withDate(year, 12, 31).toLocalDate(); } break; case BI_ANNUAL: // // jan 1st to 30, jul 1st to dec 31 year = periodStartDate.getYearOfEra(); monthofYear = periodStartDate.getMonthOfYear(); if (monthofYear <= 6) { periodEndDate = new DateTime().withDate(year, 6, 30).toLocalDate(); } else if (monthofYear <= 12) { periodEndDate = new DateTime().withDate(year, 12, 31).toLocalDate(); } break; case ANNUAL: periodEndDate = periodStartDate.monthOfYear().withMaximumValue(); periodEndDate = periodEndDate.dayOfMonth().withMaximumValue(); break; // case NO_COMPOUNDING_SIMPLE_INTEREST: // periodEndDate = periodStartDate.monthOfYear().withMaximumValue(); // periodEndDate = periodEndDate.dayOfMonth().withMaximumValue(); // break; } return periodEndDate; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private LocalDate setDayOfMonth(LocalDate nextDueLocalDate) { int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth(); int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth; nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth); return nextDueLocalDate; }
From source file:com.gst.portfolio.savings.domain.SavingsHelper.java
License:Apache License
private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate, final SavingsPostingInterestPeriodType interestPostingPeriodType, final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) { LocalDate periodEndDate = interestPostingUpToDate; final Integer monthOfYear = periodStartDate.getMonthOfYear(); financialYearBeginningMonth--;//from www.j a v a 2 s . com if (financialYearBeginningMonth == 0) financialYearBeginningMonth = 12; final ArrayList<LocalDate> quarterlyDates = new ArrayList<>(); quarterlyDates .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); Collections.sort(quarterlyDates); final ArrayList<LocalDate> biannualDates = new ArrayList<>(); biannualDates .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue()); biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); Collections.sort(biannualDates); boolean isEndDateSet = false; switch (interestPostingPeriodType) { case INVALID: break; case MONTHLY: // produce period end date on last day of current month periodEndDate = periodStartDate.dayOfMonth().withMaximumValue(); break; case QUATERLY: for (LocalDate quarterlyDate : quarterlyDates) { if (quarterlyDate.isAfter(periodStartDate)) { periodEndDate = quarterlyDate; isEndDateSet = true; break; } } if (!isEndDateSet) periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue(); break; case BIANNUAL: for (LocalDate biannualDate : biannualDates) { if (biannualDate.isAfter(periodStartDate)) { periodEndDate = biannualDate; isEndDateSet = true; break; } } if (!isEndDateSet) periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue(); break; case ANNUAL: if (financialYearBeginningMonth < monthOfYear) { periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth); periodEndDate = periodEndDate.plusYears(1); } else { periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth); } periodEndDate = periodEndDate.dayOfMonth().withMaximumValue(); break; } // interest posting always occurs on next day after the period end date. periodEndDate = periodEndDate.plusDays(1); return periodEndDate; }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
protected static LocalDate parse(final int nYear, final FixedWeekdayInMonth aFixedWeekdayInMonth) { LocalDate aDate = PDTFactory.createLocalDate(nYear, XMLUtil.getMonth(aFixedWeekdayInMonth.getMonth()), 1); int nDirection = 1; if (aFixedWeekdayInMonth.getWhich() == Which.LAST) { aDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); nDirection = -1;/*from ww w .ja v a 2 s .c o m*/ } final int nWeekDay = XMLUtil.getWeekday(aFixedWeekdayInMonth.getWeekday()); while (aDate.getDayOfWeek() != nWeekDay) { aDate = aDate.plusDays(nDirection); } switch (aFixedWeekdayInMonth.getWhich()) { case FIRST: break; case SECOND: aDate = aDate.plusDays(7); break; case THIRD: aDate = aDate.plusDays(14); break; case FOURTH: aDate = aDate.plusDays(21); break; case LAST: break; } return aDate; }
From source file:com.ideaspymes.arthyweb.ventas.service.impl.GestionComercialService.java
public static String getConsultaCantidadCajasAcum(Integer vendedorId, String bd) { LocalDate localDate = new LocalDate(); int ultimoDia = localDate.dayOfMonth().getMaximumValue(); int mes = localDate.getMonthOfYear(); int anio = localDate.getYear(); return "select sum(x.cant_caja) from \n" + "(SELECT \n" + " FD.[ID Sucursales] as sucursal_key\n" + " ,FD.[ID Vendedores] as cod_vendedor --\n" + " ,FD.[ID Comprobantes Ventas] as comprobante\n" + " ,FD.[Numero] as numero_fac\n" + " ,FD.[ID Linea] as linea_fac \n" + " ,DATEADD(dd, 0, DATEDIFF(dd, 0, F.[Fecha])) as fecha_key\n" + " ,F.[ID Clientes] as cod_cliente --\n" + " ,(SELECT \n" + " --OBTENEMOS LA DESCRIPCION DE LA ZONA EN LA QUE SE EJECUTO LA VENTA\n" + " CASE WHEN [Clasificacion 8] = '1' OR [Clasificacion 8] IS NULL THEN 'NO DEFINIDO' ELSE [Clasificacion 8] END\n" + " " + bd + ".FROM [VTA_Clientes] C WHERE C.[ID Clientes]=F.[ID Clientes] AND C.[ID Sucursales] = FD.[ID Sucursales]) as zona_desc,\n" + " --OBTENEMOS LA DESCRIPCION EL TERRITORIO EN LA QUE SE EJECUTO LA VENTA\n" + " (SELECT \n" + " CASE WHEN [Clasificacion 2] = '1' OR [Clasificacion 2] IS NULL THEN 'NO DEFINIDO' ELSE [Clasificacion 2] END\n" + " " + bd + ".FROM [VTA_Clientes] C WHERE C.[ID Clientes]=F.[ID Clientes] AND C.[ID Sucursales] = FD.[ID Sucursales]) as territorio_desc\n" + " ,FD.[ID Productos] as cod_producto --\n" + " ,FD.[ID Unidades Medidas] as unidad_key\n" + " ,FD.[Cantidad Envase] as cantidad_envase\n" + " ,FD.[Total Linea ML] as importe \n" + " ,ISNULL (CAST (FD.[Promocion] AS INT),0) as bonicicacion\n" + " ,ISNULL (FD.[PromoPLM3] ,0) as cantidad_promo\n" + " ,(CASE WHEN FD.[PromoId]=0 THEN NULL ELSE FD.[PromoId] END) as promo_key\n" + " --CALCULOS PARA OBTENER VOLUMENES DE VENTA POR CAJAS,GRUESAS Y CAJETILLAS\n" + " ,CAST (case when U.[ID Unidades Medidas] = 15 then cast (FD.[Cantidad Envase] as numeric(14,3)) / 50 else (case when U.[ID Unidades Medidas] = 25 then cast (FD.[Cantidad Envase] as numeric(14,3)) / calc.cantidad_caje_por_gruesa / 50 else (case when U.[ID Unidades Medidas] <> 16 then 0 else FD.[Cantidad Envase] end) end ) end AS numeric (14,3) ) as cant_caja\n" + "\n" + " ,CAST ( case when U.[ID Unidades Medidas] = 16 then cast (FD.[Cantidad Envase] as numeric(14,3)) * 50 else (case when U.[ID Unidades Medidas] = 25 then cast (FD.[Cantidad Envase] as numeric(14,3)) / calc.cantidad_caje_por_gruesa else (case when U.[ID Unidades Medidas] <> 15 then 0 else FD.[Cantidad Envase] end) end ) end AS numeric (14,3) )as cant_gruesa\n" + "\n" + " ,CAST (case when U.[ID Unidades Medidas] <> 29 then cast (FD.[Cantidad Envase] as numeric(14,3)) * U.[Cantidad] else 0 end AS numeric (14,3) )as cant_cajetilla\n" + " \n" + "FROM " + bd + ".[VTA_D Comprobantes de Ventas] FD WITH (NOLOCK)\n" + "INNER JOIN " + bd + ".[VTA_C Comprobantes de Ventas] F WITH (NOLOCK) \n" + " ON FD.Origen = F.Origen \n" + " AND FD.[ID Sucursales] = F.[ID Sucursales] \n" + " AND FD.[ID Vendedores] = F.[ID Vendedores] \n" + " AND FD.[ID Comprobantes Ventas] = F.[ID Comprobantes Ventas] \n" + " AND FD.numero = F.numero\n" + "--\n" + "LEFT JOIN " + bd + ".[STK_UM de Productos] U WITH (NOLOCK)\n" + " ON FD.[ID Unidades Medidas] = U.[ID Unidades Medidas]\n" + " AND FD.[ID Productos] = U.[ID Productos]\n" + "-- TABLA VIRTUAL PARA OBTENER CANTIDA DE PABILOS POR CAJETILLA\n" + "LEFT JOIN " + bd + ".calc_pabilo calc ON FD.[ID Productos] = calc.[ID Productos]\n" + "WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, F.[Fecha])) between " + convertFechaSQL(1, mes, anio) + " and " + convertFechaSQL(ultimoDia, mes, anio) + " \n" + " AND F.[Status] <> '11' \n" + " AND FD.[ID Vendedores] = " + vendedorId + ") x"; }