lundi 16 décembre 2019

Make an if-statement understand which "time-left" format is bigger

I am trying to make an IF-statement that can calculate which "time-left" is bigger. This is my code.

if('6h : 27m : 45s' > '6h : 27m : 15s') {
    echo 'Timer to the left is bigger';
}

This code works fine, it actually prints Timer to the left is bigger.

However, when any timer (hour, minute or seconds) is only one letter instead of two. It doesn't work. Like this:

if('6h : 27m : 45s' > '6h : 27m : 5s') {
    echo 'Timer to the left is bigger';
}

This time it does not print out Timer to the left is bigger. It is because the timer to the right is only 5s left, which is less than 15s, but it is because it is only one letter instead of two, and the IF-statement don't understand that.

How can I parse this to an understandable format for the if-statement?

NOTE the string is from an API, I can't edit it in anyway.

Aucun commentaire:

Enregistrer un commentaire