0

I want to sort my events based on the dates the user gives them. I am using react datepicker and Lodash to sort the events desc.

My code React JS

const events = _.sortBy(this.props.events, [["seconds"]])
    console.log(JSON.stringify(events))

Output console.log

[
{"date":{"seconds":416617200,"nanoseconds":0},,"title":"Past event 1983"},
{"date":{"seconds":1995231600,"nanoseconds":0},"title":"Future event 2033"},
{"date":{"seconds":1585090800,"nanoseconds":0},"title":"Present event 2020"},
{date":{"seconds":1677625200,"nanoseconds":0},"title":"Future event 2023"}
]

When I am trying orderBy "date" I also don't get the desired result

const events = _orderBy(this.props.events, "date")
console.log(JSON.stringify(events))

console.log:

[
{"date":{"seconds":1995231600,"nanoseconds":0},"title":"Future event 2033"},
{"date":{"seconds":1585090800,"nanoseconds":0},"title":"Present event 2020"},
{date":{"seconds":1677625200,"nanoseconds":0},"title":"Future event 2023"}
{"date":{"seconds":416617200,"nanoseconds":0},,"title":"Past event 1983"},
]

As you can see the seconds are not orderBy correctly in both cases.

Please advise how to use orderBy with Lodash when using React Date Picker?

Many thanks

0 Answers0