You are here

function xmlsitemap_calculate_changefreq in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_calculate_changefreq()
  2. 6.2 xmlsitemap.module \xmlsitemap_calculate_changefreq()
  3. 7.2 xmlsitemap.module \xmlsitemap_calculate_changefreq()

Calculates the average interval between UNIX timestamps.

Parameters

array $timestamps: An array of UNIX timestamp integers.

Return value

int An integer of the average interval.

1 call to xmlsitemap_calculate_changefreq()
XmlSitemapUnitTest::testCalculateChangefreq in tests/src/Functional/XmlSitemapUnitTest.php
Tests for xmlsitemap_calculate_changereq().

File

./xmlsitemap.module, line 1098
xmlsitemap XML sitemap

Code

function xmlsitemap_calculate_changefreq(array $timestamps) {
  sort($timestamps);
  $count = count($timestamps) - 1;
  $diff = 0;
  for ($i = 0; $i < $count; $i++) {
    $diff += $timestamps[$i + 1] - $timestamps[$i];
  }
  return $count > 0 ? round($diff / $count) : 0;
}