@Override protected int apply(LocalDate date) { return date.getYear(); }
@Override public PeriodValue containingDate(LocalDate localDate) { return new YearValue(localDate.getYear()); } }
public static EpiWeek weekOf(LocalDate date) { LocalDate firstDayOfYear = dayOfFirstEpiWeek(date.getYear()); if(date.before(firstDayOfYear)) { return new EpiWeek(date.getYear() - 1, 52); } else { int daysBetween = LocalDate.daysBetween(firstDayOfYear, date); int weekNumber = daysBetween / 7; return new EpiWeek(date.getYear(), weekNumber + 1); } }
@Override @SuppressWarnings("deprecation") public Date parse(CharSequence text) throws ParseException { // Use a very lenient parser to allow for local input. // The result will always be formatted as a formatted string Date date; try { date = PARSER.parse(text.toString()).atMidnightInMyTimezone(); } catch (IllegalArgumentException e) { throw new ParseException(text.toString(), 0); } LocalDate localDate = new LocalDate(date); if(localDate.getYear() < 1000 || localDate.getYear() > 9999) { throw new ParseException(text.toString(), 0); } return date; }
@Override public PeriodValue containingDate(LocalDate localDate) { return new Month(localDate.getYear(), localDate.getMonthOfYear()); } }
public static int encodeLocalDate(LocalDate value) { return value.getYear() << 16 | value.getMonthOfYear() << 8 | value.getDayOfMonth(); }
@Override public void setValue(Cell cell, int row) { // Excel does not support date values prior to 1900, // so we have no choice but to render the value as text if the date occurs // prior to 1900. LocalDate localDate = renderer.render(row); if(localDate.getYear() < 1900) { cell.setCellValue(localDate.toString()); } else { cell.setCellValue(localDate.atMidnightInMyTimezone()); } } }
@VisibleForTesting static double compute(LocalDate startDate, LocalDate endDate) { int y1 = startDate.getYear(); int y2 = endDate.getYear(); int m1 = startDate.getMonthOfYear(); int m2 = endDate.getMonthOfYear(); int d1 = startDate.getDayOfMonth(); int d2 = endDate.getDayOfMonth(); // If (Date1 is the last day of February) and (Date2 is the last day of February), // then change D2 to 30. if(lastDayOfFebruary(m1, d1) && lastDayOfFebruary(m2, d2)) { d2 = 30; } if (lastDayOfFebruary(m1, d1)) { d1 = 30; } if(d2 == 31 && (d1 == 30 || d1 == 31)) { d2 = 30; } if(d1 == 31) { d1 = 30; } return Math.abs((360d * (y2-y1) + 30d * (m2-m1) + (d2-d1)) / 360d); }
private static FormulaNode dateValue(FilterConfig filter) { // GXT serializes the date value as unix time value in milliseconds long time = Long.parseLong(filter.getValue()); Date date = new Date(time); LocalDate localDate = new LocalDate(date); return new FunctionCallNode(DateFunction.INSTANCE, new ConstantNode(localDate.getYear()), new ConstantNode(localDate.getMonthOfYear()), new ConstantNode(localDate.getDayOfMonth())); }