3 Replies Latest reply on Oct 22, 2018 7:46 AM by MDJ

    Custom symbol PITime parser


      Hi All

      (PIVision Custom Symbols for PiVision2017 R2)

      Is there a way to reuse build in PITIme parser to parse/validate inserted time in my own javascript - Custom Symbol? Same time parser/validator that is used to parse start/end time of TimeBar?

      Create own regex to fully match the PiVision time parser is waste of time, and is not correct approach to do that, handle any kind of options that Osisoft intruduced/is introducing/will introduce, should be reusable - keep same behaving in whole PIVision.

      i.e. correctly parse to Time (Dae and Time) 3jan4-1d+2h+34m -> 1/2/2004 2:34:00 AM., 3jan4-y -> is today at 12:00:00 AM, but 3jan4-y-1h is 1/2/2004 11:00:00 PM



        • Re: Custom symbol PITime parser
          Eugene Lee

          I think the time parsing happens on the server side with the data service of PI Vision so there is no way to do it on the client.

          • Re: Custom symbol PITime parser
            Eugene Lee

            Confirmed that the time parsing happens on the server side with the development team.


            One possible workaround to this is to leverage on PI Web API to do the time parsing for you. The steps are


            1.Send a request to the GetValue method of the Stream controller with the timestring in the time parameter. E.g. "*-1h"

            2.Parse out the returned Timestamp field.

            3.Convert the UTC time to your local time if needed.


            Point of note: Remember to consider the timezone when you are trying to resolve the timestring. This is important if the client and the server are in different timezones. The timeZone parameter allows you to define the client time zone. If you do not define the timeZone parameter, the default is the server timezone. The timestamps returned by PI Web API are always in UTC. Check below for more information.


            GetValue GET streams/{webId}/value

            1 of 1 people found this helpful
              • Re: Custom symbol PITime parser

                Thanks for hints,

                I was suspecting that the time parsing is done on server, because none of the scripts from TimeBar of PIVision was containing any direct logic for it. I understand - keep it in privacy, but they should introduce for it some API.


                To use piwebapi as a validator is also one way of workaround, to set time format and parse the answer. If the answer is correct, than the time is valid other wise is invalid.


                  "Errors": [

                  "The specified timestamp is not valid. If more details are needed, please contact your PI Web API administrator for help in enabling debug mode."




                But it is an input field validator of time, which should not do any trafic to server and back.


                I wrote some more restrict regex for it to support validator directly on the client side: Relaive time, Fixied time, date format: MM/dd/YYYY hh:mm:ss (AM/PM)?, dd.MM.yyyy hh:mm:ss (24hours/12hours support).




                or more readable form


                var flexible = '(\\s*([+-])\\s*\\d+([.,]\\d+)?(ms|mo|s|m|h|d|w|y))?(\\s*([+-])?\\s*\\d+([.,]\\d+)?\\s*(ms|mo|s|m|h|d|w|y))*';

                var hours12 = '((0?\\d|1[0-2]):(0?\\d|[1-5]\\d):(0?\\d|[1-5]\\d)\\s+(AM|PM))';

                var hours24 = '(((1\\d|2[0-3]|0?\\d):([1-5]\\d|0?\\d)):([1-5]\\d|0?\\d))';

                var time = '\\s+(' + hours12 + '|' + hours24 +')';

                var monthsName = '(jan|feb|mar|apr|may|jun|jul|aug|sep|okt|nov|dec)';

                var niceDate = '(((0?\\d|[12]\\d|3[01])[-]?)?' + monthsName + '[-]?(19[7-9]\\d|2\\d{3}|\\d{1,2})?)';

                var nameDays = '([ty*])|(mon|tue|wed|thu|fri|sat|sun)|(monday|tuesday|wednesday|thursday|friday|saturday|sunday)';

                var commonDate = '([1][0-2]|[0]?[1-9])\\/([3][01]|[1-2]\\d|[0]?[1-9])(\\/((19[7-9]\\d|2\\d{3})|\\d{1,2}))?|([3][01]|[1-2]\\d|[0]?[1-9])[.]([1][0-2]|[0]?[1-9])([.]((19[7-9]\\d|2\\d{3})|\\d{1,2}))?|([3][01]|[1-2]\\d|[0]?[1-9])';

                var dateTime = '((' + niceDate + '|' + commonDate + ')('+time+')?)';

                var commonDateTime = '\\s*([+\\-]|' + nameDays + '|' + dateTime + ')';

                var regexStr = '^' + commonDateTime +flexible + '$';

                var regex = new RegExp(regexStr, 'gmi');



                Hope will be helpful for some others as well.