src/date-util.js
function getPeriod(dates, granularity, forced) {
  var isArray = angular.isArray(dates);
  var isRange = (isArray && dates.length > 1);

  if ((isArray && dates.length === 0) || dates === null || dates === undefined) {
    return null;
  }

  if (granularity === 'month') {
    return (isRange || forced) ? getMonthPeriod(dates) : getYearPeriod(dates);
  }

  if (granularity === 'day') {
    return (isRange || forced) ? getDayPeriod(dates) : getMonthPeriod(dates);
  }

  if (granularity === 'week' && !isRange) {
    // Special case. Week is no actual granularity. This returns a week period
    // starting at the specified date. No checks are made to determine if the
    // provided date actually is the first day in a week.
    var start = (isArray) ? dates[0] : dates;
    var end = new Date(start.getTime());
    end.setDate(end.getDate() + 6);

    return getDayPeriod([start, end]);
  }

  return getDayPeriod(dates);
}
function getPeriod(dates, granularity, forced) {
  var isArray = angular.isArray(dates);
  var isRange = (isArray && dates.length > 1);

  if ((isArray && dates.length === 0) || dates === null || dates === undefined) {
    return null;
  }

  if (granularity === 'month') {
    return (isRange || forced) ? getMonthPeriod(dates) : getYearPeriod(dates);
  }

  if (granularity === 'day') {
    return (isRange || forced) ? getDayPeriod(dates) : getMonthPeriod(dates);
  }

  if (granularity === 'week' && !isRange) {
    // Special case. Week is no actual granularity. This returns a week period
    // starting at the specified date. No checks are made to determine if the
    // provided date actually is the first day in a week.
    var start = (isArray) ? dates[0] : dates;
    var end = new Date(start.getTime());
    end.setDate(end.getDate() + 6);

    return getDayPeriod([start, end]);
  }

  return getDayPeriod(dates);
}
function getPeriod ( dates , granularity , forced ) { var isArray = angular . isArray ( dates ) ; var isRange = ( isArray && dates . length > 1 ) ; if ( ( isArray && dates . length === 0 ) || dates === null || dates === undefined ) { return null ; } if ( granularity === 'month' ) { return ( isRange || forced ) ? getMonthPeriod ( dates ) : getYearPeriod ( dates ) ; } if ( granularity === 'day' ) { return ( isRange || forced ) ? getDayPeriod ( dates ) : getMonthPeriod ( dates ) ; } if ( granularity === 'week' && ! isRange ) { // Special case. Week is no actual granularity. This returns a week period // starting at the specified date. No checks are made to determine if the // provided date actually is the first day in a week. var start = ( isArray ) ? dates [ 0 ] : dates ; var end = new Date ( start . getTime ( ) ) ; end . setDate ( end . getDate ( ) + 6 ) ; return getDayPeriod ( [ start , end ] ) ; } return getDayPeriod ( dates ) ; }
Returns a period for the provided date range, or single date. Will auto-calculate period style depending on granularity, unless force is set to true. E.g. when getting day granularity for a single date, the function will assume you want day values for the date's month.
Returns a period for the provided date range or single date . Will auto - calculate period style depending on granularity unless force is set to true . E . g . when getting day granularity for a single date the function will assume you want day values for the date s month .