/* (non-Javadoc)
@see net.finmath.time.daycount.DayCountConventionInterface#getDaycount(org.threeten.bp.LocalDate, org.threeten.bp.LocalDate)
321724
@Override
	public double getDaycount(LocalDate startDate, LocalDate endDate) {
		if(startDate.isAfter(endDate)) {
			return -getDaycount(endDate,startDate);
		}

		int startDateDay 	= startDate.getDayOfMonth();
		int startDateMonth 	= startDate.getMonthValue();
		int startDateYear 	= startDate.getYear();

		int endDateDay 		= endDate.getDayOfMonth();
		int endDateMonth 	= endDate.getMonthValue();
		int endDateYear 	= endDate.getYear();


		// Check if we have last day of February
		boolean isStartDateLastDayOfFebruary = (startDateMonth == Month.FEBRUARY.getValue() && startDateDay == startDate.lengthOfMonth());
		boolean isEndDateLastDayOfFebruary = (endDateMonth == Month.FEBRUARY.getValue() && endDateDay == endDate.lengthOfMonth());

		// Last day of February and 31st of a month are both treated as "30".
		if(isStartDateLastDayOfFebruary || startDateDay == 31) {
			startDateDay = 30;
		}
		if((isEndDateLastDayOfFebruary && !isTreatEndDateAsTerminationDate) || endDateDay == 31) {
			endDateDay = 30;
		}

		return (endDateYear - startDateYear) * 360.0 + (endDateMonth - startDateMonth) * 30.0 + (endDateDay - Math.min(startDateDay, 30.0));
	}
433867
public LocalDate getEndAsLocalDate() {

        PlainDate date = this.getEndAsCalendarDate();
        return ((date == null) ? null : date.toTemporalAccessor());

    }
783458
public int getRemainingDays(String startDate, String endDate, Date currentDate) throws java.text.ParseException {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

		Calendar iterationEndDate = Calendar.getInstance();
		iterationEndDate.setTime(dateFormat.parse(endDate));

		Calendar iterationStartDate = Calendar.getInstance();
		iterationStartDate.setTime(dateFormat.parse(startDate));

		Calendar currentCalendarDate = Calendar.getInstance();
		currentCalendarDate.setTime(currentDate);

		int remainingDays = 0;

		if ((iterationStartDate.compareTo(currentCalendarDate) == 1)
				|| (iterationEndDate.compareTo(currentCalendarDate) == -1)) {

			return remainingDays;
		}

		while (iterationEndDate.compareTo(currentCalendarDate) == 1) {
			if ((currentCalendarDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
					&& (currentCalendarDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY)) {
				++remainingDays;
			}
			currentCalendarDate.add(Calendar.DAY_OF_MONTH, 1);
		}

		return remainingDays;
	}
989802
@Override
    public DateCalculator<LocalDate> moveByDays(final int days) {
        setCurrentIncrement(days);

        setCurrentBusinessDate(getCurrentBusinessDate().plusDays(days));

        if (getHolidayHandler() != null) {
            setCurrentBusinessDate(getHolidayHandler().moveCurrentDate(this));
        }

        return this;
    }
967296
public static Calendar toCalendar(final LocalDate self) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DATE, self.getDayOfMonth());
        cal.set(Calendar.MONTH, self.getMonthValue() - 1);
        cal.set(Calendar.YEAR, self.getYear());
        clearTimeCommon(cal);
        return cal;
    }
507995
public static long getTwoDaysBetweenNumber(String startDate, String endDate, Format format) {
        SimpleDateFormat localFormat = (SimpleDateFormat) format;
        long day = 0;
        try {
            java.util.Date startDay = localFormat.parse(startDate);
            java.util.Date endDay = localFormat.parse(endDate);
            day = (endDay.getTime() - startDay.getTime()) / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            return 0;
        }
        return day;
    }
375269
@Override
    public int getFirstDayOfWeek(Locale country) {

        String fw = country.getUnicodeLocaleType("fw");

        if (fw != null) {
            Weekday wd = toEnum(fw);
            if (wd != null) { // else ignore fw-extension
                return wd.getValue();
            }
        }

        if (this.firstDayOfWeek.isEmpty()) {
            // fallback
            GregorianCalendar gc = new GregorianCalendar(country);
            int fd = gc.getFirstDayOfWeek();
            return ((fd == 1) ? 7 : (fd - 1));
        }

        String key = FormatUtils.getRegion(country);
        Weekday first = Weekday.MONDAY;

        if (this.firstDayOfWeek.containsKey(key)) {
            first = this.firstDayOfWeek.get(key);
        }

        return first.getValue();

    }
884617
static LocalDate toLocalDate(final Calendar self) {
        return LocalDate.of(self.get(Calendar.YEAR), toMonth(self), self.get(Calendar.DAY_OF_MONTH));
    }
42405
private static String getDaytimeReply(
        String address,
        int port,
        int timeout
    ) throws IOException {

        IOException ioe = null;
        Socket socket = null;
        StringBuilder sb = null;

        try {

            socket = new Socket(address, port);
            socket.setSoTimeout(timeout * 1000);

            InputStream is = socket.getInputStream();
            InputStreamReader ir = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(ir);

            int len;
            char[] chars = new char[100];
            sb = new StringBuilder();

            while ((len = br.read(chars)) != -1) {
                sb.append(chars, 0, len);
            }

            is.close();
            ir.close();
            br.close();

        } catch (IOException ex) {

            ioe = ex;

        } finally {

            try {
                if (socket != null) {
                    socket.close();
                }
            } catch (IOException ex) {
                System.err.println(
                    "Ignored exception while closing time server socket: "
                    + ex.getMessage()
                );
                ex.printStackTrace(System.err);
            }

        }

        if (ioe == null) {
            return sb.toString();
        } else {
            throw ioe;
        }

    }
1297928
protected Calendar getLocalTimeAsCalendar(BigDecimal localTimeParam, Calendar date) {
        if (localTimeParam == null) {
            return null;
        }

        // Create a clone of the input calendar so we get locale/timezone information.
        Calendar resultTime = (Calendar) date.clone();

        BigDecimal localTime = localTimeParam;
        if (localTime.compareTo(BigDecimal.ZERO) == -1) {
            localTime = localTime.add(BigDecimal.valueOf(24.0D));
            resultTime.add(Calendar.HOUR_OF_DAY, -24);
        }
        String[] timeComponents = localTime.toPlainString().split("\\.");
        int hour = Integer.parseInt(timeComponents[0]);

        BigDecimal minutes = new BigDecimal("0." + timeComponents[1]);
        minutes = minutes.multiply(BigDecimal.valueOf(60)).setScale(0, RoundingMode.HALF_EVEN);
        if (minutes.intValue() == 60) {
            minutes = BigDecimal.ZERO;
            hour += 1;
        }
        if (hour == 24) {
            hour = 0;
        }

        // Set the local time
        resultTime.set(Calendar.HOUR_OF_DAY, hour);
        resultTime.set(Calendar.MINUTE, minutes.intValue());
        resultTime.set(Calendar.SECOND, 0);
        resultTime.set(Calendar.MILLISECOND, 0);
        resultTime.setTimeZone(date.getTimeZone());

        return resultTime;
    }
834151
public static int getDaysOfMonth(Date date) {
		DateTime dt = new DateTime(date.getTime());
		return getDaysOfMonth(dt.getYear(), dt.getMonthOfYear());
	}
876576
public static Long getSunday() {
		cal.setTimeInMillis(System.currentTimeMillis());
		cal.add(Calendar.DATE, -dayOfWeek() + 7);
		return cal.getTimeInMillis();
	}
386149
@Override
	public long getCount(long when){
		Long recWhen = when - (when % granularity);
		AtomicLong times = counters.get(recWhen);
		return times == null ? 0 : times.longValue(); 
	}
622949
@Override
    public Iterator<LocalDate> iterator() {

        return new Iterator<LocalDate>() {

            final IntIterator intIterator = intIterator();

            @Override
            public boolean hasNext() {
                return intIterator.hasNext();
            }

            @Override
            public LocalDate next() {
                return PackedLocalDate.asLocalDate(intIterator.nextInt());
            }
        };
    }
1341328
public int getMinutesPerDay()
   {
      return m_minutesPerDay == null ? NumberHelper.getInt(getParentFile().getProjectProperties().getMinutesPerDay()) : m_minutesPerDay.intValue();
   }
585587
public static LocalDateTime firstDay(String localDate) {
        LocalDateTime parse = parse(localDate, DEFAULT_PATTERN);
        return LocalDateTime.of(parse.getYear(), parse.getMonth(), 1, 0, 0, 0);
    }
1159853
public boolean activeOn (LocalDate date) {
        // first check for exceptions
        CalendarDate exception = calendar_dates.get(date);

        if (exception != null)
            return exception.exception_type == 1;

        else if (calendar == null)
            return false;

        else {
            int gtfsDate = date.getYear() * 10000 + date.getMonthValue() * 100 + date.getDayOfMonth();
            boolean withinValidityRange = calendar.end_date >= gtfsDate && calendar.start_date <= gtfsDate;

            if (!withinValidityRange) return false;

            switch (date.getDayOfWeek()) {
                case MONDAY:
                    return calendar.monday == 1;
                case TUESDAY:
                    return calendar.tuesday == 1;
                case WEDNESDAY:
                    return calendar.wednesday == 1;
                case THURSDAY:
                    return calendar.thursday == 1;
                case FRIDAY:
                    return calendar.friday == 1;
                case SATURDAY:
                    return calendar.saturday == 1;
                case SUNDAY:
                    return calendar.sunday == 1;
                default:
                    throw new IllegalArgumentException("unknown day of week constant!");
            }
        }
    }