Skip to main content
OSIsoft PI
Programming
AF SDK

Transitioning from PI-SDK to AF-SDK: Navigating the Deprecation with Timestamp and Timezone Conversion

Explore effective strategies for transitioning from PI-SDK to AF-SDK, focusing on converting timestamps with timezone offsets to UTC seconds and adapting legacy systems.

Roshan Soni

4 min read

Transitioning from PI-SDK to AF-SDK: Navigating the Deprecation with Timestamp and Timezone Conversion

The deprecation of PI-SDK in favor of AF-SDK presents a unique challenge for businesses relying on legacy systems implemented in plain C++. A key task during this transition involves adapting processes to extract UTC seconds from timestamps using AF-SDK. This blog post delves into practical strategies and tips for smoothly transitioning from PI-SDK to AF-SDK, focusing on converting timestamps with time zone offsets to UTC seconds.

Understanding the Change from PI-SDK to AF-SDK

When upgrading from PI-SDK to AF-SDK, engineers must adapt pre-existing code bases. The biggest hurdle in this transition involves ensuring that existing legacy systems can read and process timestamp data correctly with AF-SDK’s time-related objects and methods.

Converting Timestamps to UTC Seconds

For users accustomed to PI-SDK, migrating to AF-SDK means learning new methods to perform similar tasks. One such task is timestamp conversion that respects timezone offsets. In PI-SDK, the PITimeServer facilitated this, whereas, in AF-SDK, the AFTime structure streamlines the process.

Using AFTime Structure in AF-SDK

AFTime in AF-SDK is designed to effortlessly handle timestamps encoded with ISO-8601 formats. Here is how you can utilize AFTime.Parse to convert a timestamp into an AFTime object and obtain the UTC seconds:

AFTime time = AFTime.Parse("2020-10-06T16:59:01-07:00");
double utcSeconds = time.UtcSeconds;

This snippet demonstrates how AFTime.Parse accounts for the timezone offset and delivers the corresponding UTC seconds, a crucial feature for systems that log data across various time zones.

Legacy Code in Plain C++

In projects bound to plain C++, developers might face challenges due to the lack of modern features like the C++ chrono library. A common workaround is to manually parse and adjust timestamps before using AF SDK.

Example Approach:

  1. Parse Timestamp Manually in Plain C++: Read the string representation and manually calculate the offset from UTC.
  2. Calculate UTC Seconds: Adapt algorithms to convert the parsed timestamp into UTC seconds using basic arithmetic.

Key Considerations

  1. Format Compatibility: Ensure that your input timestamp strings are compatible with the AFTime's accepted formats.
  2. Error Handling: Implement robust error handling to address conversion pitfalls, such as invalid input strings or format mismatches.
  3. Documentation and Testing: Thoroughly document the conversion process and extensively test the conversion logic in your application’s context.

Conclusion

Moving from PI-SDK to AF-SDK necessitates adapting legacy systems but also opens opportunities to streamline time and date operations using AF SDK's more modern capabilities. By understanding how to correctly parse and convert timestamps, engineers can ensure compatibility and reliability during this transitional phase. Implementing these strategies can mitigate operational disruptions and smooth the way forward into AF-SDK’s advanced, supported ecosystem.

Whether you're part of a well-established data infrastructure or building anew, make sure that your approach is robust, taking into consideration the nuances of timezone handling and data consistency.

Tags

#AF SDK
#PI-SDK
#Time Zones
#Legacy Systems
#C++

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni

    Transitioning from PI-SDK to AF-SDK: Navigating the Deprecation with Timestamp and Timezone Conversion | Pisharp Blog | PISharp