socib / Leaflet.TimeDimension

Add time dimension capabilities on a Leaflet map.
MIT License
435 stars 139 forks source link

Can't use dates before 1960? #83

Open joshua-reynolds opened 8 years ago

joshua-reynolds commented 8 years ago

Hi,

I'm trying to use a gpx feature that has dates taking place in the 1800's in example #9. I'm guessing because the app uses UTC (which was formalized in 1960), dates before that cause the script to break. Is there anyway to get around this?

I'd really like to be able to display dates in the 1800's.

Greatly appreciate any help!

apulverizer commented 7 years ago

Part of the problem is in timedimension.control.js line 303-322:

_update: function() {
        if (!this._timeDimension) {
            return;
        }
        var time = this._timeDimension.getCurrentTime();
        if (time > 0) {
            var date = new Date(time);
            if (this._displayDate) {
                L.DomUtil.removeClass(this._displayDate, 'loading');
                this._displayDate.innerHTML = this._getDisplayDateFormat(date);
            }
            if (this._sliderTime && !this._slidingTimeSlider) {
                this._sliderTime.setValue(this._timeDimension.getCurrentTimeIndex());
            }
        } else {
            if (this._displayDate) {
                this._displayDate.innerHTML = this._getDisplayNoTimeError();
            }
        }
    },

If dates are before 1/1/1970 the epoch/unix timestamp will be negative. Since the time is checked to see if it is greater than 0, this fails and the NoTimeError message is rendered.

I think this might be fixed by changing line 308 to be:

if (this._timedimension.getCurrentTimeIndex() >=0) {

Also in timedimension.js, the getCurrentTime function returns 0 if the index isn't valid, maybe this should return null instead?

 getCurrentTime: function () {
        var index = -1;
        if (this._loadingTimeIndex !== -1) {
            index = this._loadingTimeIndex;
        } else {
            index = this.getCurrentTimeIndex();
        }
        if (index >= 0) {
            return this._availableTimes[index];
        } else {
            return 0;
        }
    },