HourBeg Function

This topic contains 5 replies, has 2 voices, and was last updated by Mikhail Mikhail 5 months, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4024

    jacklondon
    Participant

    Hi Mikhail,

    could you please explain why the hour beginning condition is entered as

    nowDT.Minute == 1

    and not

    nowDT.Minute == 0?

    Regards

    #4025
    Mikhail
    Mikhail
    Moderator

    Hi,

    Where in the source code these lines are located?

    #4032

    jacklondon
    Participant

    They are taken from “CalcEngine.cs”, Formulas Table HourBeg():

    bool HourBeg()
    {
        DateTime nowDT = DateTime.Now;
        DateTime execDT;
        if (nowDT.Minute == 1 && (!HourBegDict.TryGetValue(CnlNum, out execDT) || 
            execDT < new DateTime(nowDT.Year, nowDT.Month, nowDT.Day, nowDT.Hour, 0, 0)))
        {
            HourBegDict[CnlNum] = nowDT;
            return true;
        }
        else
        {
            return false;
        }
    }
    #4038
    Mikhail
    Mikhail
    Moderator

    This approach is useful to store values in the archive in the beginning of a new hour and then reset them, for example.
    You can write HourBeg2() with your own logic.

    #4055

    jacklondon
    Participant

    Hi Mikhail,

    Yes, i understood that already. The question is why you implemented it the condition nowDT.Minute == 1 (and not == 0) as the hour begins with for example 12:00.

    Regards

    #4059
    Mikhail
    Mikhail
    Moderator

    Hi,
    If you change it to == 0, the function may be executed before hourly data are stored in the archive. In most cases this doesn’t fit.
    How do you plan to use this function?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.