When using PI data, one often wants to do arithmetic on time values. A very common case is the expression " *-4h " (current time minus four hours).
For month-to-date, year-to-date, and week-to-date calculations, we need to get the start of the current month, year, or week respectively.
We may want to find the time difference between two events, expressed in days, hours, minutes, or some other interval.
We may want to find out what happened exactly three days, or one month, or five years, before or after a known event.
All these calculations must be done correctly, in spite of time zone differences and Summer Time (DST) changes.
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:
|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|
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.
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:
Plant days may start at times other than midnight.
The day may be divided into shifts, which may be scheduled in various ways, some rather complex.
A company may calculate production according to fiscal years, months, and quarters, which may not correspond to calendar month boundaries.
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.