4 Replies Latest reply on Feb 23, 2011 4:48 PM by charlie@osisoft.com

    start time / end time

    jimmilton

      We have confused ourselves a little with when a timestamp is in UTC and when it is not.  If someone could clear this up for us, that would be great.

       

      I have a little code: 

       

       

       
      piro.UtcStartdate = Convert.ToDateTime(textBox3.Text).ToUniversalTime();
      piro.UtcEndtime = Convert.ToDateTime(textBox4.Text).ToUniversalTime();
      
      .....
      
      NamedValues nValues = point.Data.Summaries(piro.UtcStartdate, piro.UtcEndtime,
                                                                                  GetBoundrySetting(piro.SummaryType), GetSummaryType(piro.SummaryType),
                                                                                  Convert.ToInt32(intv),
                                                         CalculationBasisConstants.cbTimeWeightedContinuous
                                                                                  , null);
      

       

       

      piro.UtcStartdate and piro.UtcEndtime are datetime objects.  Is the summaries function expecting datetime in local time or UTC?  If its expecting time in local, how do you specify first vs second Hour Ending 2 on the long day?  The timestamps that are returned, are they in UTC?

       

       

       
      piro.CollectedData.Add(v.TimeStamp.LocalDate.AddSeconds(piro.IntervalSeconds).ToString(), Convert.ToDouble(v.Value.ToString()));
      

       

       

      What I expect to do is to take a date time for start and end from the user, convert it to UTC, ask the PI server for the data in the UTC interval times, and get back a set of data with time in UTC.  Then I can choose to convert it to local time or to leave in UTC.  99% of the time we will want to leave it in UTC when we load it into another db server.  Only when we return it to a client do we want to have it in local time again, but that is very very rare.  

       

       

       

       

        • Re: start time / end time
          jimmilton

          ok quick update, I did some testing and seem to have a better understanding, but it seems that our server and our customer's server are returning different results.  Is there a setting somewhere that specifies whether the timestamps are returned in UTC vs Local?

          • Re: start time / end time
            hanyong

            Hi James,

             

            James McMurry

            Is the summaries function expecting datetime in local time or UTC?

            The function should be expecting local time if you are passing in a datetime object. You can refer to a similar discussion here

             

            James McMurry

            If its expecting time in local, how do you specify first vs second Hour Ending 2 on the long day?
             
            I'm afraid I'm not sure how to answer this part of your question, because I am not very familiar on dealing with DST as well, lets see what others in the community has to suggest about this.

             

            James McMurry

            The timestamps that are returned, are they in UTC?

            The timestamps associated with the returned result (in the form of NamedValues and PIValues collection) are PITime object where you can get either the local datetime or UTC from it. 

             

            Hope this helps 

              • Re: start time / end time

                Han Yong

                The timestamps associated with the returned result are PITime object where you can get either the local datetime or UTC from it. 
                You can read the timestamp from the PITime object through its LocalDate or UTCSeconds properties. LocalDate will return a standard .NET DateTime object, which has a variety of methods to deal time arithmetics and time zone (e.g. ToUniversalTime). The UTCSeconds property gives you the number of seconds elapsed since January 1st, 1970 UTC; you can use that number to initialize a standard .NET DateTime object.

                 

                Hope this helps!

                  • Re: start time / end time

                    The input of any method can take a variety of input timestamps.  The type of the input object determines how the PISDK method evaluates the timestamp.  See the Summaries method help page which describes the input values that are legal.

                     

                    For instance, a string will be parsed using PITimeFormat.InputString from the PITimeServer to parse the value.  Strings are assumed to be local time and thus use the local system time zone to generate UTC (TAI - we call it UTC but leap seconds are not used) values.  If the DateTime translates to a VT_DATE, it will be translated using the PITime.LocalDate method, also translated using the local time zone.

                     

                    Any Integer or Double will translate into a UTC with no conversion.

                     

                    Using a PITime, PITimeFormat, or DynamicTime is also legal, and these store UTC timestamp internally at the time any property is set.  The one exception is DynamicTime, which will evaluate '*' when any timestamp is requested.  This is useful for things like trends in which the current time is the end time.

                     

                    All timestamps sent to the PI server are UTC timestamps.  All timestamps retrieved from the PI server are UTC timestamps.

                     

                    Most methods will return a PITime object which can hand out UTC seconds or LocalDate (based on local time zone).  PITimeFormat may be used to set a time zone other than the local one and generate a LocalDate or OutputString based on the time zone setting.