For the following array-object-thing structure:
Events : {
events : [
{
startDTG : {day: 0, month: 0, year: 0, time: "" },
endDTG : {day: 0, month: 0, year: 0, time: "" },
mode: ""
},
...
],
blah...,
blah...,
blah...
}
I am struggling to find a more efficient way to sort the events
objects based on the startDTG
key (Date-Time Group). Currently I use the following, but I feel there has to be a better way to do it!
SortEvents: function() {
this.Events.events.sort(function(a, b){return a.startDTG.time - b.startDTG.time});
this.Events.events.sort(function(a, b){return a.startDTG.day - b.startDTG.day});
this.Events.events.sort(function(a, b){return a.startDTG.month - b.startDTG.month});
this.Events.events.sort(function(a, b){return a.startDTG.year - b.startDTG.year});
},
Edit 1: The desire is to be sorted by Year > Month > Day > Time
I am at a critical point in which I am to abandon this custom DTG in the name of efficiency it is needed. I can post the entire code if requested, but might not make total sense as it is JS written to work within a Proprietary Control system called "Medialon"
Edit 2: Added a quick-made JSON
code dump below to assist with readability of structure. Ignore the fact they are all "strings" it is how Medialon stringifies for persistence
{
"events": [
{
"startDTG": {
"day": "8",
"month": "2",
"year": "2019",
"time": "06:35",
"dayName": "5"
},
"endDTG": {
"day": "9",
"month": "2",
"year": "2019",
"time": "08:35",
"dayName": "6"
},
"mode": "1"
},
{
"startDTG": {
"day": "27",
"month": "2",
"year": "2019",
"time": "17:35",
"dayName": "3"
},
"endDTG": {
"day": "28",
"month": "2",
"year": "2019",
"time": "06:35",
"dayName": "4"
},
"mode": "1"
},
{
"startDTG": {
"day": "1",
"month": "2",
"year": "2019",
"time": "14:35",
"dayName": "5"
},
"endDTG": {
"day": "2",
"month": "2",
"year": "2019",
"time": "12:35",
"dayName": "6"
},
"mode": "1"
}
],