If it were simply the number of seconds since 1900 (or even 2000, when all computers were supposed to crash!), it
would be a lot simpler!
Unfortunately, the result of the "uptime" command is 'manipulated' from such a basic value before we get the result. If you look at the string offered by the OS, you'll note that there are not the 'standard' 3 sets of numbers
Stu kindly provides for the WC uptime.
Instead, there are a variety of formats. On each(?) hour, there will be a one or two digit value, along with the "hour/s" text, but there seems to be no "0 minutes". I think an exact 1 day result (again, with no hours or minutes) will simply appear as "1 day" (or X number of 'days'), instead of the WC 'standard' of "01:00:00". At least that's the formula for "1 hour", it is not presented as "1:00" or even as "00:01:00".
My solution is to chop the first part of any result, the local (24 hour) time, and the " up " from the original string. That leaves the 'uptime' as the next few characters. The job then becomes how many characters make up that days (if any), the hour (if any), and the minutes... (if any)! The rest of the text, I couldn't care less about.
So far, my line of attack has been to next find where the "," is and use that character position as the end of the needed text, with position of the " up " as the beginning. This allows me to use the php 'explode' function (with ":" as the dellmiter) to create a one, two, or three part array depending on how many ":" are found. After that, it is basically testing for the integer values of the one, two, or three parts of the array.
For example, if the uptime is "3 mins", there will be only one item in the array; there is really nothing to 'explode', so "3 mins" gets written into array[0]. But now we have a number and some non-numeric characters! Fortunately, with only one array item, the length of the entire array is usually (so far!) much more than one would need for 1 or 2 numbers. This means it is possible to figure out what the actual number is. I haven't got to the case where there are only hours with no minutes, but I think the same format will appear; only one array[0] item which will most likely have something like " hour" sitting in it along with the actual number.
In the meantime, I'm watching the temperature change 1 degree an hour.
Actually, I'm waiting to catch the mini at whole day intervals, along with single and double-digit hours (with no minutes), and single and double minutes (without hours) to verify the output.