Return a list of the context with start or end date in $year
@param int|string $year
@param bool $matchEndDate True if the year should match only the end date.  Otherwise the start date is compared as well.
@return ContextsFilter
19901
public function ContextsForYear( $year, $matchEndDate = true )
	{
		$filtered = array_filter( $this->contexts, function ( $context ) use( $year, $matchEndDate ) {

			// The context may be invalid in which case exclude
			if ( ! isset( $context['period'] ) ) return false;

			// All contexts have start so get the year
			$parts = explode( "-", $context['period'][ $matchEndDate ? 'endDate' : 'startDate' ] );

			// If the year matches then it's good
			// if ( $parts[0] == $year ) return true;

			// // If the context is an instant then start == end and since the start failed the end will also fail
			// if ( $context['period']['is_instant'] ) return false;
            //
			// // Its a duration so check the end
			// $parts = explode( "-", $context['period']['C'] );
			return $parts[0] == $year;

		}  );

		return new ContextsFilter( $this->instance, $filtered );
	}
566366
public static long betweenMonth(Date beginDate, Date endDate, boolean isReset) {
		return new DateBetween(beginDate, endDate).betweenMonth(isReset);
	}
663405
final public static function formatDateDiff($start, $end = null, $parts = 0)
    {
        if (!($start instanceof \DateTimeInterface)) {
            $start = self::asDateTime($start);
        }

        if ($end === null) {
            $end = self::now();
        } else {
            if (!($end instanceof \DateTimeInterface)) {
                $end = self::asDateTime($end);
            }
        }

        $interval = $end->diff($start);

        return self::formatInterval($interval, $parts);
    }
999321
public function contains(CarbonDate $date, $equal = true)
    {
        return $date->between($this->startDate, $this->endDate, $equal);
    }
1222518
private function getDatesByYearMonthAndPeriodType($dates)
    {
        $result = array();
        foreach ($dates as $date) {
            $yearMonth = ArchiveTableCreator::getTableMonthFromDate($date);
            $result[$yearMonth][null][] = $date->toString();

            // since we're removing all periods, we must make sure to remove year periods as well.
            // this means we have to make sure the january table is processed.
            $janYearMonth = $date->toString('Y') . '_01';
            $result[$janYearMonth][null][] = $date->toString();
        }
        return $result;
    }
405352
public function setDates($start, $end)
    {
        $this->setStartDate($start);
        $this->setEndDate($end);

        return $this;
    }
209099
public function getPeriodLabel()
	{
		$contexts = $this->contexts; // Protect the contexts
		try
		{
			// If there are only instant context and all the contexts have the same date...
			if ( ! $this->DurationContexts()->count() && count( $this->AllYears() ) == 1 )
			{
				$context = reset( $this->contexts );
				return $context['period']['endDate'];
			}
			else
			{
				$this->sortByStartDate();
				$startContext = reset( $this->contexts );
				$this->sortByEndDate();
				$endContext = end( $this->contexts );
				return "{$startContext['period']['startDate']} - {$endContext['period']['endDate']}";
			}
		}
		finally
		{
			$this->contexts = $contexts; // Restore
		}
	}
1130520
public static function match(string $str, string $start, string $end) {
		$start = preg_quote($start);
		$end = preg_quote($end);
		if (preg_match('/' . $start . '(.*)' . $end . '/', $str, $matches)) {
			return $matches[1] . '';
		}
		return false;
	}
1296208
public function trailEndsAt($endDate = null)
    {
        if ($endDate === null) {
            return $this->trail_ends_at;
        } else {
            $this->trail_ends_at = $endDate;
            return $this;
        }
    }
1285219
public function whereBetween(string $fieldName, $begin, $end, string $logicalOperator = LogicalOperator::AND)
    {
        return $this->where($fieldName, 'between', [$begin, $end], $logicalOperator);
    }
630991
def this_year(self):
        
        start_date, end_date = get_date_range_this_year()
        return self.filter(start_time__gte=start_date, start_time__lte=end_date)
1097481
function(startDate, endDate) {
    var current = new Date(startDate);
    var end = new Date(endDate); 
    var dates = [];

    while(current <= end) {

        var m = current.getMonth() + 1;
        var d = current.getDate();
        var oneDate = [
            current.getFullYear(),
            m < 10 ? "0" + m : m,
            d < 10 ? "0" + d : d].join('-');

        dates.push(oneDate);
        current.setDate(current.getDate() + 1);
    }

    return dates;
}
518216
private function determineDateForPrefix($startDate, $endDate)
    {
        // The default date value should look like "*/*/*" after joining
        $dateParts = array_fill_keys(['Y', 'm', 'd'], self::PREFIX_WILDCARD);

        // Narrow down the date by replacing the WILDCARDs with values if they
        // are the same for the start and end date.
        if ($startDate && $endDate) {
            foreach ($dateParts as $key => &$value) {
                $candidateValue = date($key, $startDate);
                if ($candidateValue === date($key, $endDate)) {
                    $value = $candidateValue;
                } else {
                    break;
                }
            }
        }

        return join('/', $dateParts);
    }
546689
public function setDateEnd($end, $field = null)
    {
        $param = $this->buildParam('facet.date.end', $field);
        return $this->set($param, $end);
    }
1045124
protected function getVisitorsFilteredByDateRange(Carbon $start, Carbon $end)
    {
        return $this->getCachedVisitors()->filter(function (Visitor $session) use ($start, $end) {
            return $session->updated_at->between($start, $end);
        });
    }
1264497
public function setEndDate($date, $inclusive = null)
    {
        if (!is_null($date) && !$date = call_user_func([$this->dateClass, 'make'], $date)) {
            throw new InvalidArgumentException('Invalid end date.');
        }

        if (!$date) {
            return $this->removeFilter(static::END_DATE_FILTER);
        }

        $this->endDate = $date;

        if ($inclusive !== null) {
            $this->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive);
        }

        if (!$this->hasFilter(static::END_DATE_FILTER)) {
            return $this->addFilter(static::END_DATE_FILTER);
        }

        $this->handleChangedParameters();

        return $this;
    }
1110899
def imply_dates
      return unless !@properties['end'].nil? && !@properties['start'].nil?

      start_date = nil

      @properties['start'].each do |start_val|
        if start_val =~ /^(\d{4}-[01]\d-[0-3]\d)/
          start_date = Regexp.last_match(1) if start_date.nil?
        elsif start_val =~ /^(\d{4}-[0-3]\d\d)/
          start_date = Regexp.last_match(1) if start_date.nil?
        end
      end

      unless start_date.nil?
        @properties['end'].map! do |end_val|
          if end_val.match?(/^\d{4}-[01]\d-[0-3]\d/)
            end_val
          elsif end_val.match?(/^\d{4}-[0-3]\d\d/)
            end_val
          else
            start_date + ' ' + end_val
          end
        end
      end
    end