Skip to content

Proposed intersectDateSpans() example doesn't work #6

@kler

Description

@kler

Observed Behaviour

When executing th example code for the intersectDateSpans(), there is an error:

TypeError: Cannot read property '0' of undefined
    at run (/app/logic.js:155:9)
    at Command.<anonymous> (/app/contact.js:50:17)
    at Command.listener (/app/node_modules/commander/index.js:291:8)
    at Command.emit (events.js:209:13)
    at Command.parseArgs (/app/node_modules/commander/index.js:672:12)
    at Command.parse (/app/node_modules/commander/index.js:459:21)
    at Object.<anonymous> (/app/contact.js:101:9)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)

Expected Behaviour

result.length; // 1 overlap between spanB and spanC
result[0].getBegin(); // 10:00am
result[0].getEnd(); // 10:30am

Steps to Reproduce

From https://github.com/mickmcc/node-caltime#intersectdatespans

const caltime = require('caltime');
const datespanCtor = caltime.dateSpan;
const intersectDateSpans = caltime.intersectDateSpans;
let spanListA = null;
let spanListB = null;
// DateSpan object which represents 09:00am - 10:00am.
var beginDate = new Date(2017, 10, 15, 9, 0, 0, 0);
var spanA = datespanCtor(beginDate, 60, 0, 0);
// create a DateSpan object which represents 10:00am - 11:00am.
beginDate = new Date(2017, 10, 15, 10, 0, 0, 0);
var spanB = datespanCtor(beginDate, 60, 0, 0);
// create a DateSpan object which represents 10:00am - 10:30am.
beginDate = new Date(2017, 10, 15, 10, 0, 0, 0);
var spanC = datespanCtor(beginDate, 15, 0, 0);
// create a DateSpan object which represents 14:00 - 15:00.
beginDate = new Date(2017, 10, 15, 14, 0, 0, 0);
var spanD = datespanCtor(beginDate, 60, 0, 0);
// populate the arrays
spanListA = [ spanA, spanB ];
spanListB = [ spanC, spanD ];
// sort in descending order
let result = intersectDateSpans(spanListA, spanListB);
result.length; // 1 overlap between spanB and spanC
result[0].getBegin(); // 10:00am
result[0].getEnd(); // 10:30am

System Configuration

caltime version: 1.4.5
Node.js version: v12.10.0
NPM version:6.10.3
lodash version: 4.17.15
moment-timezone version: 0.5.26

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions