当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeOffset.ToMinuteCompare方法代码示例

本文整理汇总了C#中DateTimeOffset.ToMinuteCompare方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.ToMinuteCompare方法的具体用法?C# DateTimeOffset.ToMinuteCompare怎么用?C# DateTimeOffset.ToMinuteCompare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeOffset的用法示例。


在下文中一共展示了DateTimeOffset.ToMinuteCompare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTimeChangeForLocalTime

        private static TimeChange GetTimeChangeForLocalTime(List<TimeChange> changes, DateTimeOffset localTime)
        {
            TimeChange timeChange = null;
            var numberOfChanges = changes.Count - 1;
            for (var i = 0; i <= numberOfChanges; i++)
            {
                var change = changes [i];

                // If the old local time was 02:00 and the new local time is 03:00
                // and the user ask for the timezone on 02:30 they will get this exception
                if (localTime.ToMinuteCompare (change.OldLocalTime.DateTime) == 1 &&
                    localTime.ToMinuteCompare (change.NewLocalTime.DateTime) == -1)
                    throw new LocalTimeDoesNotExistException ("The time and date requested falls between the old and new timezone");

                // If the date the user ask for is older (earlier) than the first time change
                var localTimeIsEarlierThanOldLocalTime = localTime.ToMinuteCompare (change.OldLocalTime.DateTime);
                if (localTimeIsEarlierThanOldLocalTime <= 0)
                {
                    timeChange = change;
                    break;
                }

                // If the date the user ask for is newer or the same date as the new local time
                var localTimeIsLaterThanNewLocalTime = localTime.ToMinuteCompare (change.NewLocalTime.DateTime);
                if (localTimeIsLaterThanNewLocalTime >= 0)
                {
                    // If this is the last time change then this is the timechange the user is in
                    if (i == numberOfChanges)
                    {
                        timeChange = change;
                    }
                    else
                    {
                        // If there is more time changes, and the date the user asks for is later than
                        // the next date. Just continue to the next date. If not, 'change' is the
                        // timechange the localTime is in
                        var next = changes [i + 1];
                        if (localTime.ToMinuteCompare (next.NewLocalTime.DateTime) >= 0)
                            continue; // Could be made recursive
                        else
                        {
                            timeChange = change;
                            break;
                        }
                    }
                }
            }

            return timeChange;
        }
开发者ID:adny,项目名称:libtad-net,代码行数:50,代码来源:Location.cs

示例2: GetUTCOffsetFromLocalTime

        public TimeSpan GetUTCOffsetFromLocalTime(DateTimeOffset localTime)
        {
            if (TimeChanges == null || (TimeChanges != null && TimeChanges.Count () == 0))
                throw new MissingTimeChangesException ("IncludeTimeChanges either set to false or no time changes for this location");

            var firstNewLocalTime = TimeChanges.FirstOrDefault ().NewLocalTime.Year;
            if (localTime.Year > firstNewLocalTime || localTime.Year < firstNewLocalTime)
                throw new QueriedDateOutOfRangeException ("The year specified in localTime is outside the year available for this location");

            TimeChange change;
            if (TimeChanges.Count () == 1)
                change = TimeChanges.SingleOrDefault ();
            else
                change = GetTimeChangeForLocalTime (TimeChanges.ToList (), localTime);

            TimeSpan span;
            if (localTime.ToMinuteCompare (change.OldLocalTime.DateTime) < 0)
            {
                span = change.OldLocalTime.DateTime - change.UtcTime.DateTime;
            }
            else
            {
                span = TimeSpan.FromSeconds (change.NewTotalOffset);
            }

            return span;
        }
开发者ID:adny,项目名称:libtad-net,代码行数:27,代码来源:Location.cs


注:本文中的DateTimeOffset.ToMinuteCompare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。