Tuesday, December 4, 2012

How the @OSIsoftPI System Tracks Time

Here's a primer on how PI tracks time.

GMT

The first thing you need to know is that everything is archived Greenwich Mean Time, so it doesn't matter what timezone the server is in. It doesn't matter what timezone you're in. Everything gets archived GMT.


When you create a PI point, you have to tell the PI server what data type it ought to store with the pointtype attribute. This is important because some data types can be converted to others while others cannot. Date/times happen to be one of those that can be tracked in at least two ways:

Time as Integer

One convention that PI uses to track time is using integers where the numerical value refers to the number of seconds since 31-Dec-1969 16:00. I'm not entirely certain of the significance of this date.... maybe prior to this date, no computers existed? Whatever the case, 0 refers to 12/31/1969 @ 4pm.

To get Jan 1, 1970 @ midnight, that's 8-hours. So 8 hour is the same as 480 minutes... which is 28800 seconds. So if you wanted to write the date 1/1/1970 to PI using integers, you'd send the numerical value 28800 as the timestamp field.

Time as Float32

Another convention that PI follows to track time is using floating points where the numerical value of the floating point refers to the number of days since 1/1/1900. Incidentally, this is the same as the Excel convention.

As an example, Marty McFly goes back on 5-Nov-55 (11/5/1955). To figure out what this is in the Float32 format, you simply do this:

1955 is 55 years after 1900... so 55 years * 365 days per year = 20088 days



Credit ©1985 Universal Pictures

November 5th is the 309th day of the year, so 20088 + 309 = 20398

Handling Local Time

PI uses the local time of the PI server or the local time of the PI client (ProcessBook as it were) to figure out how to display the time.  No data is deleted because all of it archived against GMT.

So take the silly American ritual of Daylight Savings where during the summer hours, we adjust our clocks forward and then in the winter, we adjust the clock back.

On 11/4, when we got to 2am, we set the clocks back to 1am and repeat the time from 1am to 2am.  This is what it looks like on PI:

OSI PI daylight savings
You can see that in the 1-day period between 11/4 and 11/5, 1.04 days is shown.

You can also see in the sinusoid trend (which is based on local clock time apparently), the trend repeats the hour between 1am and 2am.

In summary:

  • PI works off of GMT and the translation to local time depends on your computer or the PI server's local time.  
  • PI can store timestamps as integers representing seconds since 12/31/1969 @ 4pm
          - or -
  • PI can store timestamps as float32 representing days since 1/1/1900

No comments: