Post #166306
April 02, 2022, 02:39:52 AM
I get it. Usually, popular programming languages have standardized functions to deal with stuff like DST or obtaining epoch timestamps, manipulating them and converting them back to readable human time and so on. I know that's pretty easily done in Java.
I'm an industrial controls guy and our platforms usually aren't so full featured. On North America's most used platform, you have to sync the controller to a time server or roll your own calendar math to adjust for DST because it doesn't do it on its own. On most of my clients' OT networks, a workable "time server" is not available, so roll the calendar math it is. You've gotta check for the first Sunday on March and November and flip the time then. You don't get a day of week integer from the controller so you have to calculate it from the given date.
Another fun time problem I've had to wrestle with recently was how to get the right best before date into a controller from an SQL server that stored the product's shelf life in number of days. The timestamp I could get from the controller was an array of two 32-bit integers representing milliseconds since Unix, because of course that platform semi-handles 64-bit types on the latest firmware (it'll do basic arithmetic but that's it), but did not at all on my client's firmware (and upgrading is a can of worms I'm not gonna get into in this post). Instead of dealing with that, I did calendar math to get the Julian day, added the shelf life to that day and reconverted it to a date.
At least the stupid calendar math has mostly already been done for us but you've gotta know it exists and actually can be done. Incidentally, I later got a sister plant's solution to the problem and it involved nearly a thousand lines of code doing logical comparisons.