How to sort cron expressions in typescript?

Viewed 196

I am working on an angularjs application, and I need to sort in ascending order a list of jobs by schedule attribute (which is a cron expression that could be hourly, daily, monthly, quarterly, yearly, etc), Example:

[
  0: object{ schedule: '0 0 2 * * ?' },
  1: object{ schedule: '0 0 10 * * ? '},
  2: object{ schedule: '0 0 23 * * ? ' },
  3: object{ schedule: '0 0 20 * * ? ' },
  4: object{ schedule: '0 0 3 * * ? ' },
  5: object{ schedule: '0 55 * * * ? ' }
]

What i want to achieve:

[
  0: object{ schedule: '0 55 * * * ? ' },
  1: object{ schedule: '0 0 2 * * ?' },
  2: object{ schedule: '0 0 3 * * ? ' },
  3: object{ schedule: '0 0 10 * * ? '},
  4: object{ schedule: '0 0 20 * * ? ' },
  5: object{ schedule: '0 0 23 * * ? ' }
]

I already use cronstrue library to make cron expressions more human readable, , i thought about parsing the expressions and manually sort them , but it turned out to have many edge cases to handle, any suggestions how to achieve sorting of a list of cron jobs in typescript ?

0 Answers
Related