Cannot read property 'valueOf' of undefined
let startDay = moment('2018-01-17 08:00:00').utc();
let endDay = moment('2018-01-17 23:00:00').utc();
let day = moment.range(startDay, endDay);
function subtractRanges(longRanges, shortRanges) {
// Always return an array
if (shortRanges.length === 0)
return longRanges.hasOwnProperty("length") ? longRanges : [longRanges];
// Result is empty range
if (longRanges.length === 0) return [];
if (!longRanges.hasOwnProperty("length")) longRanges = [longRanges];
for (let long in longRanges) {
for (let short in shortRanges) {
longRanges[long] = longRanges[long].subtract(shortRanges[short]);
if (longRanges[long].length === 0) {
// Subtracted an entire range, remove it from list
longRanges.splice(long, 1);
shortRanges.splice(0, short);
return subtractRanges(longRanges, shortRanges);
} else if (longRanges[long].length === 1) {
// No subtraction made, but .subtract always returns arrays
longRanges[long] = longRanges[long][0];
} else {
// Successfully subtracted a subrange, flatten and recurse again
const flat = [].concat(...longRanges);
shortRanges.splice(0, short);
return subtractRanges(flat, shortRanges);
}
}
}
return longRanges;
}
events.forEach(item => {
var start = moment(`${item.dateStart}`).utc();
var end = moment(`${item.dateEnd}`).utc();
console.log('itemstart', item.dateStart);
console.log('start', start);
console.log('end', end);
rangeEvents.push(moment.range(start, end));
})
//rangeEvents = rangeEvents.splice(1);
let newRanges = subtractRanges(day, rangeEvents);
let newEvents = [];
newRanges.forEach(item => {
newEvents.push({
type: 'empty',
dateStart: item.start.utc().format(),
dateEnd: item.end.utc().format()
})
})
console.log(newEvents);
events.forEach(item => {
var start = moment(`${item.dateStart}`).utc(); // из бд формат 2018-01-17T08:00:00.000Z
var end = moment(`${item.dateEnd}`).utc();
console.log('start', start);
console.log('end', end);
rangeEvents.push(moment.range(start, end));
})
rangeEvents = rangeEvents.splice(1);
let newRanges = subtractRanges(day, rangeEvents);
let newEvents = [];
newRanges.forEach(item => {
newEvents.push({
type: 'empty',
dateStart: item.start.utc().format(),
dateEnd: item.end.utc().format()
})
})
start 2018-01-17T08:00:00.000Z
end moment.utc("2018-01-17T09:30:00.000+00:00")
start 2018-01-17T15:30:00.000Z
end moment.utc("2018-01-17T16:15:00.000+00:00")
start 2018-01-17T16:15:00.000Z
end moment.utc("2018-01-17T17:30:00.000+00:00")
start 2018-01-17T18:45:00.000Z
end moment.utc("2018-01-17T19:30:00.000+00:00")
{ type: 'empty',
dateStart: '2018-01-17T05:00:00Z',
dateEnd: '2018-01-17T08:00:00Z' },
{ type: 'empty',
dateStart: '2018-01-17T09:30:00Z',
dateEnd: '2018-01-17T15:30:00Z' },
{ type: 'empty',
dateStart: '2018-01-17T17:30:00Z',
dateEnd: '2018-01-17T18:45:00Z' },
{ type: 'empty',
dateStart: '2018-01-17T19:30:00Z',
dateEnd: '2018-01-17T20:00:00Z' }
//даты мероприятий из бд (sqlite)
start moment.utc("2018-01-17T08:00:00.000+00:00")
end moment.utc("2018-01-17T09:30:00.000+00:00")
start moment.utc("2018-01-17T15:30:00.000+00:00")
end moment.utc("2018-01-17T16:15:00.000+00:00")
start moment.utc("2018-01-17T16:15:00.000+00:00")
end moment.utc("2018-01-17T17:30:00.000+00:00")
start moment.utc("2018-01-17T18:45:00.000+00:00")
end moment.utc("2018-01-17T19:30:00.000+00:00")
//результат
[ { [Number: 21600000]
start: moment("2018-01-17T12:30:00.000"),
end: moment("2018-01-17T18:30:00.000") },
{ [Number: 4500000]
start: moment("2018-01-17T20:30:00.000"),
end: moment("2018-01-17T21:45:00.000") },
{ [Number: 12600000]
start: moment("2018-01-17T22:30:00.000"),
end: moment("2018-01-18T02:00:00.000") } ]
var start = new Date(2018, 0, 17, 8, 0, 0);
var end = new Date(2018, 0, 17, 23, 0, 0);
var range = moment.range(start, end);
{ [Number: 5400000]
start: moment("2018-01-17T08:00:00.000"),
end: moment("2018-01-17T09:30:00.000") }
{ [Number: 2700000]
start: moment("2018-01-17T18:30:00.000"),
end: moment("2018-01-17T19:15:00.000") }
{ [Number: 4500000]
start: moment("2018-01-17T19:15:00.000"),
end: moment("2018-01-17T20:30:00.000") }
{ [Number: 2700000]
start: moment("2018-01-17T21:45:00.000"),
end: moment("2018-01-17T22:30:00.000") }
[ { [Number: 48600000]
start: moment("2018-01-17T09:30:00.000"),
end: moment("2018-01-17T23:00:00.000") } ]
[ { [Number: 37800000]
start: moment("2018-01-17T08:00:00.000"),
end: moment("2018-01-17T18:30:00.000") },
{ [Number: 13500000]
start: moment("2018-01-17T19:15:00.000"),
end: moment("2018-01-17T23:00:00.000") } ]
[ { [Number: 40500000]
start: moment("2018-01-17T08:00:00.000"),
end: moment("2018-01-17T19:15:00.000") },
{ [Number: 9000000]
start: moment("2018-01-17T20:30:00.000"),
end: moment("2018-01-17T23:00:00.000") } ]
[ { [Number: 49500000]
start: moment("2018-01-17T08:00:00.000"),
end: moment("2018-01-17T21:45:00.000") },
{ [Number: 1800000]
start: moment("2018-01-17T22:30:00.000"),
end: moment("2018-01-17T23:00:00.000") } ]
for ($i = 1; 5 >= $i; ++$i) {
$dateArr[] = date('d-m-Y', strtotime(-24 * $i . ' hours')); // записываю даты для ссылок в массив
}
$out;
foreach ($dateArr as $key => $dateVal) {
$out .= '<div class="list_table" date="' . $dateVal . '">' . file_get_contents($url . $dateVal) . '</div>';// записываю контент по ссылкам обернув их в тэг и добавив атрибут с датой
}
$html = new simple_html_dom();
$html->load($out);//загружаю контент всех страниц из переменной (НЕ load_file)
$html->save();
//ну а дальше все как всегда
$table = $html->find('.list_table');
foreach ($table as $key => $value) {
$dd = $value->attr['date'];
foreach ($value->find('table.tb-matches tr') as $key => $tr) {
$elem = $tr->find('td', 0);
if ($elem->attr['colspan'] != '7') {
//echo $tr->find('td', 0)->plaintext;
$resultArr[$dd][] = array(
'time' => $tr->find('td', 0)->plaintext,
'home_team' => $tr->find('td.home-team', 0)->plaintext,
'away_team' => $tr->find('td.away_team', 0)->plaintext,
'status' => trim($tr->find('td.status', 0)->plaintext),
'score' => $tr->find('td.score', 0)->plaintext,
'href' => 'http://goal24.ru' . $tr->find('td.option a', 0)->href,
);
}
}
}
и все заработало код тут