Time Arithmetic

All these calculations must be done correctly, in spite of time zone differences and Summer Time (DST) changes.

Time Interval Objects

The PI SDK uses a generic scheme for performing time arithmetic, based on time interval objects. These are COM objects that implement the ITimeInterval interface, whose methods the SDK uses to do time arithmetic.

Nine time interval objects are built into the SDK:

Name Abbrev Range Names Comment
Year y 1970-9999 No
Month mo 1-12 Yes
Week w 0-53 No Week of year
Day d 1-31 No Day of month
Yearday yd 1-366 No Day of year
Weekday wd 1-7 Yes Day of week
Hour h 0-23 No
Minute m 0-59 No
Second s 0-59.99999 No

These objects are fully localized. From the Windows NT configuration, we get the names of weeks and months, whether the week begins on Sunday or Monday, and how the first week of the year is numbered. We handle these differences according to the operating system rules.

Custom Time Intervals

The built-in time intervals are all generic; they can be used anywhere. However, some time intervals are unique to a company or a plant:

Clearly, we cannot supply built-in time interval objects that would conflict with some customers’ practices, but we can and do make it possible for customers to build their own custom time interval objects.

Custom time intervals, once built and registered on a client machine, are handled just the same as built-in time intervals. If you have a Shift interval whose abbreviation is sh, you can type "*-2sh" anywhere you could type "*-10m".

This tutorial will show you how to build such interval objects. Our example will be a COM server that serves two time interval objects to the SDK: PlantDay and Shift.

Enabling Operational Intelligence