seanlowe / obsidian-timelines

Create a timeline view of all notes with the specified combination of tags
https://seanlowe.github.io/obsidian-timelines/
MIT License
39 stars 2 forks source link

Timelines with negative dates render in the wrong order #22

Closed tr00datp00nar closed 3 weeks ago

tr00datp00nar commented 4 months ago

I have a timeline that ranges from -1000-00-00-00 to 0001-00-00-00. I am using the default sorting order (old => new) and padding (5) in obsidian settings

When rendering, the timeline sorts incorrectly.

Actual sort: -100 -250 -400 -750 -1000 0001

Expected sort: -1000 -750 -400 -250 -100 0001

I am using the html method of declaring events and all of my dates use the YYYY-MM-DD-HH format as in the example below:

<div
  class='ob-timelines'
  data-title='Event Title'
  data-start-date='-1000-00-00-00'
  data-end-date='-1000-00-00-00'
  data-era='SC'
  data-type='point'
  >
A short description
</div>

Other timelines that aren't using negative dates do sort properly.

ReconVirus commented 4 months ago

Hello again @seanlowe . so i also had a problem with dealing with this from legacy code. my work around to getting the it to work correctly was

getStartEndDates(event: any): [Date, Date] {
        const getDate = (dateStr: string): Date => {
            let date = dateStr?.replace(/(.*)-\d*$/g, '$1');
            if (date && date[0] == '-') {
                let dateComp = date.substring(1, date.length).split('-');
                return new Date(+`-${dateComp[0]}`, +dateComp[1] - 1, +dateComp[2]);
            } else {
                return new Date(date);
            }
        };
        let start = getDate(event.date);
        let end = getDate(event.endDate);
        return [start, end];
    }

but mainly how the code itself is reading negative dates. But i believe legacy was just using string types for the dates. so there really anything telling it the -1000 should be before 1000 as "-" and nothing more than a typeface and not a operation.

if you want please take a look at my dev branch and that might be more of a help to you than me trying to explain it .

seanlowe commented 4 months ago

@ReconVirus I'll make a note to take a look at your dev branch, any particular spot you'd like to highlight?

As of right now, I'm still using string dates but unfortunately this puts a bit of a damper on just how custom dates can get due to limitations with vis-timeline. I am currently exploring other horizontal timeline solutions

seanlowe commented 3 weeks ago

@tr00datp00nar, It only took me 4 months..... but this is fixed in release 2.1.13

@ReconVirus, thanks for the tip, I took some of what you did as a starting point for the solution I eventually went with.