code: private static Calendar getEndOfYear(Calendar calendar) {
  
          // Get first day of next year
          Calendar endOfYear = Calendar.getInstance();
          endOfYear.clear();
          endOfYear.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1);
  
          // Transform into the last millisecond of the given year
          endOfYear.add(Calendar.MILLISECOND, -1);
  
          return endOfYear;
  
      }
docs: Returns a new calendar representing the last millisecond of the same
  year as <code>calendar</code>.
  
  @param calendar
  The calendar defining the year whose end (last millisecond) is to be
  returned.
  
  @return
  A new calendar representing the last millisecond of the same year as
  <code>calendar</code>.