Does anyone have an idea how to convert a PI time expression like T+8H based on a historical date\time lets say 1/1/2019 6:30 AM ...?
I thought about something like NCalc, but of course would be easier if something is already available ....
I think it is simply this:
AFTime.TryParse("T+8h",new AFTime("1/1/2019 6:30", out var result)
Good day Holger,
I'm a bit confused about what you are asking. A PI time expression like 'T+8H' returns an instance in time (in .NET this would be a DateTime or AFTime object). The fixed historical date\time of '1/1/2019 6:30 AM' also returns an instance in time (again a DateTime or AFTime object). BTW, its of no concern that the latter is a historcal date\time, but rather that its a specific DateTime.
This boils down to now having 2 specific DateTime instances and both of them are in local time. The most immediate DateTime operation available is to subtract them to calculate a TimeSpan.
What else where you planning to do with them?
Or are you wanting to apply PI time expressions to DateTime objects? You can't do that directly, but you can use AFTime for that.
Sure, sure, .... i want to back fill a custom calculations where the user enter the date time in relative form.
So in the backfill calculation I have a historical datetime and have to parse it using the expression. So basically simulate the realtime execution. PI Recalculator should perform a very similar function ...
To schedule re-calculations is up to the Analysis Service and that service obviously understands fixed dates and times, or what we would call a "wall clock". Any .NET code you write would use dates as you would expect when scheduling recalcuations.
However, an analysis that is executing does not know about "wall clock". Thus 'T+8h' does NOT mean Today plus 8 hours. Rather it means the the start of day for the executing trigger time plus 8 hours. Ditto for 'Y' - its also relative to the trigger time.
So if you ask for a re-calculation for '1/1/2019 6:30 AM' (local time on host running analysis service), then an executing analysis will consider 'T' to be 1/1/2019 at midnight, and 'Y' would be 12/31/2018 also at midnight.
If I have this wrong, I ask David Pugal to correct me.
So how does pi analysis\recalculator do that ...? Any snippets you could share ...?
I can either share skimpy snippets here and its up to you to fill in the blanks, or I can share a console application formerly available on GitHub but that requires you to agree to some terms and conditions.
Meanwhile, there is this help:
and this method of interest
Retrieving data ...