3 Replies Latest reply on Jun 7, 2018 7:20 PM by Rick Davin

    AFTime Constructor (String) issue

    John Messinger

      When creating a new AFTime object from a String, one can pass in a standard PI time string such as "*-8h" or "t+6.5h" etc, however it seems not all valid PI time strings are accepted by this constructor. For example, I might want to initialise a new AFTime object for 6:00am on the 1st day of the current month, and so I would ordinarily use a time string of "1 6:". This is a valid PI time string that I can use elsewhere, such as PI ProcessBook (in fact, I seem to recall that this format used to be mentioned as a valid PI time string in PI Client training courses), however it is not supported in the AFSDK. Is there a particular reason for this, and are there any other limitations on which PI time strings can be passed when using this constructor? I didn't see anything in the documentation that indicated this limitation, so I'm curious to know what else there might be.

        • Re: AFTime Constructor (String) issue
          Eugene Lee

          The library to parse the time string in Processbook is PITimeServer. That is why you are seeing a difference. However you are right that AF SDK is unable to parse "1 6:". You can see the parse results using AFTime.TryParse. Regarding whether this is a bug or a design decision, I will leave that for our devs to answer.

          • Re: AFTime Constructor (String) issue

            Hi John,


            This limitation is documented in the AF SDK reference: AFTime Constructor (String).


            Some formats with missing hours, minutes, and/or seconds that were supported by PI Time are not supported. For example "hh:mm" is supported, but "hh::ss", ":mm:ss", and "::s" are some formats that are not supported. The format must be supported by the DateTime.TryParse method.


            I encourage you to check out the documentation for detailed information, in case you have questions about whether other time formats are supported.

            1 of 1 people found this helpful
            • Re: AFTime Constructor (String) issue
              Rick Davin

              Hey John, I trust you've moved on after 3 years, but for anyone else reading this, the correct syntax would be new AFTime("1+6h").  This would produce a time at 6 AM local time of the first of the current month.  To get 6 AM local time for the first of the current year, the correct time string would be "1/1+6h".