How to add a negative date to the timeline

195 views Asked by At

How can I add a negative date to the timeline? My current code is:

let items = new vis.DataSet([
    {id: 1, content: 'today', start: '2018-11-02'}
])

new vis.Timeline(document.getElementById('timeline'), items, {})

To add an event to the timeline, I just add it to items:

items.add({id: 2 content: 'tomorrow', start: '2018-11-03'})

If I zoom the timeline out I see that it shows dates before year 1. How can I add an event to a negative date, without needing to drag the event?

2

There are 2 answers

0
user24312 On BEST ANSWER

I got it!

new Date(-2018, 11, 26)

This will produce a negative date.

0
Nicolai Zoëga On

I dont know if it works on your lay out, but i use timestamps (if you import timestamps from php you should add 3 0's to the end as php use seconds and js use miliseconds )

but that works for me.

alternative what happens if you add this

items.add({id: 3 content: 'past', start: '2018-10-03'})

would that not show the item before current time ?