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
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:
- Parse Timestamp Manually in Plain C++: Read the string representation and manually calculate the offset from UTC.
- Calculate UTC Seconds: Adapt algorithms to convert the parsed timestamp into UTC seconds using basic arithmetic.
Key Considerations
- Format Compatibility: Ensure that your input timestamp strings are compatible with the AFTime's accepted formats.
- Error Handling: Implement robust error handling to address conversion pitfalls, such as invalid input strings or format mismatches.
- 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
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.
No comments yet
Be the first to share your thoughts on this article.
Related Articles
Developing Expertise in PI System and Related Technologies: A Comprehensive Training Roadmap
This blog outlines a comprehensive training roadmap for developing expertise in the PI System and related technologies. Structured over four weeks, the program covers essential technologies like the PI System, Asset Framework, and various APIs, providing a strong foundation for data management and analytics.
Roshan Soni
Traversing an AF Database Hierarchy to Count All Elements Using OSIsoft AF SDK
Learn how to use the OSIsoft AF SDK in C# to traverse an AF database and count all elements within its hierarchy. This blog post provides a comprehensive guide with code examples for connecting, traversing, and counting AF elements.
Roshan Soni
A Beginner's Guide to Learning the OSIsoft PI System
Unlock the power of real-time data management and analytics with OSIsoft PI System. This beginner's guide provides a structured learning path and key resources to help you effectively learn the PI System.
Roshan Soni