使用TimePeriod.NET的CalendarPeriodCollector计算“运行时间”不会产生任何结果

时间:2018-06-14 10:18:28

标签: c#

我写了一些代码,我似乎无法开始工作,持续时间似乎返回零我需要它在UTC时区内工作并告诉我指定的时间是否在特定时间段内,并且在每个会话中花费的持续时间。

下面是我写的一些测试代码,看看指定的时间是否在四个会话中的任何一个,然后将编写代码来确定每个会话中花费的时间,但似乎无法得到这个工作总持续时间总是返回零。

private static void TestCode_FxMarketSessions()
    {
        var dtNowGMTOffset = CommonApplication.GetGMTNowDtmOffset();

        var currentSession = CommonApplication.GetCurrentGMTTradingSession(dtNowGMTOffset);
    }

public static FxMarketHours GetCurrentGMTTradingSession(DateTimeOffset dtGMTOffset)
    {
        var sydneySession = new CalendarPeriodCollectorFilter();
        var tokyoSession = new CalendarPeriodCollectorFilter();
        var londonSession = new CalendarPeriodCollectorFilter();
        var newYorkSession = new CalendarPeriodCollectorFilter();

        sydneySession.CollectingHours.Add(new HourRange(17, 24));
        sydneySession.CollectingHours.Add(new HourRange(0, 2));

        tokyoSession.CollectingHours.Add(new HourRange(20, 24));
        tokyoSession.CollectingHours.Add(new HourRange(0, 5));

        londonSession.CollectingHours.Add(new HourRange(3, 12));

        newYorkSession.CollectingHours.Add(new HourRange(8, 17));

        var timePeriod = new CalendarTimeRange(dtGMTOffset.UtcDateTime, dtGMTOffset.UtcDateTime.AddMinutes(60));

        CalendarPeriodCollector collector_sydneySession =
                new CalendarPeriodCollector(sydneySession, timePeriod);
        CalendarPeriodCollector collector_tokyoSession =
                new CalendarPeriodCollector(tokyoSession, timePeriod);
        CalendarPeriodCollector collector_londonSession =
                new CalendarPeriodCollector(londonSession, timePeriod);
        CalendarPeriodCollector collector_newYorkSession =
                new CalendarPeriodCollector(newYorkSession, timePeriod);

        collector_sydneySession.CollectHours();
        collector_tokyoSession.CollectHours();
        collector_londonSession.CollectHours();
        collector_newYorkSession.CollectHours();

        var duration_sydneySession = new DateDiff(collector_sydneySession.Periods.TotalDuration);
        var duration_tokyoSession = new DateDiff(collector_tokyoSession.Periods.TotalDuration);
        var duration_londonSession = new DateDiff(collector_londonSession.Periods.TotalDuration);
        var duration_newYorkSession = new DateDiff(collector_newYorkSession.Periods.TotalDuration);

        //collector.Periods[0].GetRelation()

        if ((duration_sydneySession.Minutes > 0)
            && (duration_tokyoSession.Minutes > 0))
        {
            return (FxMarketHours.Sydney | FxMarketHours.Tokyo);
        }
        else if ((duration_tokyoSession.Minutes > 0)
            && (duration_londonSession.Minutes > 0))
        {
            return (FxMarketHours.Tokyo | FxMarketHours.London);
        }
        else if ((duration_londonSession.Minutes > 0)
            && (duration_newYorkSession.Minutes > 0))
        {
            return (FxMarketHours.London | FxMarketHours.NewYork);
        }
        else if (duration_sydneySession.Minutes > 0)
        {
            return FxMarketHours.Sydney;
        }
        else if (duration_tokyoSession.Minutes > 0)
        {
            return FxMarketHours.Tokyo;
        }
        else if (duration_londonSession.Minutes > 0)
        {
            return FxMarketHours.London;
        }
        else if (duration_newYorkSession.Minutes > 0)
        {
            return FxMarketHours.NewYork;
        }

        return FxMarketHours.Unknown;
    }

0 个答案:

没有答案