func (c businessCalendar) add(origin date.Date, days int) date.Date {
	if days == 0 {
		// In order for the method to be idempotent, the same result must
		// be obtained by shifting forwards and backwards (or viceversa)
		// by a single day. If the origin is already a business day, no
		// shift is applied.
		return c.previousBusinessDay(origin)
	}

	if days > 0 {
		current := c.nextBusinessDay(origin)
		signedDays := days
		if c.isWeekend(origin) {
			signedDays--
		}

		// Count from the first day of the week and go back to the previous
		// business day when landing on a weekend.
		weekDay := int(current.Weekday())
		dayShift := signedDays%5 + weekDay
		weekShift := signedDays/5 + dayShift/5

		return c.previousBusinessDay(current.Add(7*weekShift + dayShift%5 - weekDay))
	}

	// The algorithm runs in linear time for negative shifts.
	// This should be improved at some point.
	current := c.previousBusinessDay(origin)
	for shiftDays := (-days) % 5; shiftDays > 0; {
		current = current.Add(-1)
		if c.isBusinessDay(current) {
			shiftDays--
		}
	}

	return current.Add((days / 5) * 7)
}
// add adds an input number of active days to the input origin date.
// The days parameter is allowed to be negative.
// This method is idempotent when a zero-days shift is requested.
add adds an input number of active days to the input origin date.
The days parameter is allowed to be negative.
This method is idempotent when a zero-days shift is requested.
// add adds an input number of active days to the input origin date . // The days parameter is allowed to be negative . // This method is idempotent when a zero - days shift is requested .
func (c businessCalendar) add(origin date.Date, days int) date.Date {
	if days == 0 {
		return c.previousBusinessDay(origin)
	}
	if days > 0 {
		current := c.nextBusinessDay(origin)
		signedDays := days
		if c.isWeekend(origin) {
			signedDays--
		}
		weekDay := int(current.Weekday())
		dayShift := signedDays%5 + weekDay
		weekShift := signedDays/5 + dayShift/5
		return c.previousBusinessDay(current.Add(7*weekShift + dayShift%5 - weekDay))
	}
	current := c.previousBusinessDay(origin)
	for shiftDays := (-days) % 5; shiftDays > 0; {
		current = current.Add(-1)
		if c.isBusinessDay(current) {
			shiftDays--
		}
	}
	return current.Add((days / 5) * 7)
}
func ( c businessCalendar ) add ( origin date . Date , days int ) date . Date { if days == 0 { return c . previousBusinessDay ( origin ) } if days > 0 { current := c . nextBusinessDay ( origin ) signedDays := days if c . isWeekend ( origin ) { signedDays -- } weekDay := int ( current . Weekday ( ) ) dayShift := signedDays % 5 + weekDay weekShift := signedDays / 5 + dayShift / 5 return c . previousBusinessDay ( current . Add ( 7 * weekShift + dayShift % 5 - weekDay ) ) } current := c . previousBusinessDay ( origin ) for shiftDays := ( - days ) % 5 ; shiftDays > 0 ; { current = current . Add ( - 1 ) if c . isBusinessDay ( current ) { shiftDays -- } } return current . Add ( ( days / 5 ) * 7 ) }
add adds an input number of active days to the input origin date.
add adds an input number of active days to the input origin date .
// In order for the method to be idempotent, the same result must // be obtained by shifting forwards and backwards (or viceversa) // by a single day. If the origin is already a business day, no // shift is applied. // Count from the first day of the week and go back to the previous // business day when landing on a weekend. // The algorithm runs in linear time for negative shifts. // This should be improved at some point.