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


C# DateTimeOffset.Add方法代码示例

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


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

示例1: GetAbsoluteExpiration

        protected DateTimeOffset? GetAbsoluteExpiration(DateTimeOffset utcNow, DistributedCacheEntryOptions options)
        {
            // calculate absolute expiration
            DateTimeOffset? absoluteExpiration = null;
            if (options.AbsoluteExpirationRelativeToNow.HasValue)
            {
                absoluteExpiration = utcNow.Add(options.AbsoluteExpirationRelativeToNow.Value);
            }
            else if (options.AbsoluteExpiration.HasValue)
            {
                if (options.AbsoluteExpiration.Value <= utcNow)
                {
                    throw new InvalidOperationException("The absolute expiration value must be in the future.");
                }

                absoluteExpiration = options.AbsoluteExpiration.Value;
            }
            return absoluteExpiration;
        }
开发者ID:hy7pcq,项目名称:Caching,代码行数:19,代码来源:DatabaseOperations.cs

示例2: GetUtcOffset_FromDateTimeOffset

		  public void  GetUtcOffset_FromDateTimeOffset ()
		  {
			  DateTimeOffset offset;

			  offset = new DateTimeOffset(dst1Start, baseUtcOffset);
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1Start_with_baseUtcOffset#before");
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst1Start_with_baseUtcOffset#exact");
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1Start_with_baseUtcOffset#after");

			  offset = new DateTimeOffset(dst1End, dstOffset + baseUtcOffset);
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1End_with_dstOffset+baseUtcOffset#before");
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst1End_with_dstOffset+baseUtcOffset#exact");
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1End_with_dstOffset+baseUtcOffset#after");

			  offset = new DateTimeOffset(dst2Start, baseUtcOffset);
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2Start_with_baseUtcOffset#before");
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst2Start_with_baseUtcOffset#exact");
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2Start_with_baseUtcOffset#after");

			  offset = new DateTimeOffset(dst2End, baseUtcOffset + dstOffset);
			  Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2End_with_dstOffset+baseUtcOffset#before");
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst2End_with_dstOffset+baseUtcOffset#exact");
			  Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2End_with_dstOffset+baseUtcOffset#after");
		  }
开发者ID:ArsenShnurkov,项目名称:mono,代码行数:24,代码来源:TimeZoneInfoTest.cs

示例3: GetTimeOfDayForDate

        /// <summary>
        /// Return a date with time of day reset to this object values. The millisecond value will be zero. 
        /// </summary>
        /// <param name="dateTime"></param>
        public DateTimeOffset? GetTimeOfDayForDate(DateTimeOffset? dateTime)
        {
            if (dateTime == null)
            {
                return null;
            }

            DateTimeOffset cal = new DateTimeOffset(dateTime.Value.Date, dateTime.Value.Offset);
            TimeSpan t = new TimeSpan(0, hour, minute, second);
            return cal.Add(t);
        }
开发者ID:vaskosound,项目名称:FantasyLeagueStats,代码行数:15,代码来源:TimeOfDay.cs

示例4: Add_TimeSpan

 public static void Add_TimeSpan(DateTimeOffset dateTimeOffset, TimeSpan timeSpan, DateTimeOffset expected)
 {
     Assert.Equal(expected, dateTimeOffset.Add(timeSpan));
     Assert.Equal(expected, dateTimeOffset + timeSpan);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:5,代码来源:DateTimeOffsetTests.cs

示例5: SendSession

		public void SendSession(DateTimeOffset start, DateTimeOffset end, int sessionId, Guid version)
		{
			//TODO: errors at this level should be treated as critical
            DateTime utcActualStart = start.Subtract(Settings.SessionWarmUp).UtcDateTime;
            _logger.InfoFormat("Sending StartSessionRequest with SessionId: {0} Version: {1} Start(UTC): {2}",
                version, sessionId, utcActualStart);
			StartSessionRequest startRequest = new StartSessionRequest { Version = version, SessionId = sessionId};
            Send(startRequest, utcActualStart);

            DateTime utcActualEnd = end.Add(Settings.SessionCoolDown).UtcDateTime;
            _logger.InfoFormat("Sending EndSessionRequest with SessionId: {0} Version: {1} End(UTC): {2}",
                version, sessionId, utcActualEnd);
			EndSessionRequest endRequest = new EndSessionRequest { Version = version, SessionId = sessionId };
            Send(endRequest, utcActualEnd);
		}
开发者ID:gbLabs,项目名称:tnLabs,代码行数:15,代码来源:ServiceBusMessageHandler.cs

示例6: AcquireNextTriggers

        /// <summary>
        /// Get a handle to the next trigger to be fired, and mark it as 'reserved'
        ///             by the calling scheduler.
        /// </summary>
        /// <param name="noLaterThan">If &gt; 0, the JobStore should only return a Trigger
        ///             that will fire no later than the time represented in this value as
        ///             milliseconds.</param><param name="maxCount"/><param name="timeWindow"/>
        /// <returns/>
        /// <seealso cref="T:Quartz.ITrigger"/>
        public IList<IOperableTrigger> AcquireNextTriggers(DateTimeOffset noLaterThan, int maxCount, TimeSpan timeWindow)
        {
            ReleaseTriggers();

            var triggers = new List<IOperableTrigger>();

            bool retry = false;

            do
            {
                var acquiredJobHashKeysForNoConcurrentExec = new global::Quartz.Collection.HashSet<string>();

                var score = ToUnixTimeMilliseconds(noLaterThan.Add(timeWindow));

                var waitingStateTriggers =
                    Db.SortedSetRangeByScoreWithScores(
                        RedisJobStoreSchema.TriggerStateSetKey(RedisTriggerState.Waiting), 0, score,
                        Exclude.None, Order.Ascending, 0, maxCount);
                foreach (var sortedSetEntry in waitingStateTriggers)
                {

                    var trigger = RetrieveTrigger(RedisJobStoreSchema.TriggerKey(sortedSetEntry.Element));

                    if (ApplyMisfire(trigger))
                    {
                        retry = true;
                        break;
                    }

                    if (trigger.GetNextFireTimeUtc() == null)
                    {
                        this.UnsetTriggerState(sortedSetEntry.Element);
                        continue;
                    }

                    var jobHashKey = RedisJobStoreSchema.JobHashKey(trigger.JobKey);

                    var job = RetrieveJob(trigger.JobKey);

                    if (job != null && job.ConcurrentExecutionDisallowed)
                    {
                        if (acquiredJobHashKeysForNoConcurrentExec.Contains(jobHashKey))
                        {
                            continue;
                        }
                        acquiredJobHashKeysForNoConcurrentExec.Add(jobHashKey);
                    }

                    LockTrigger(trigger.Key);
                    SetTriggerState(RedisTriggerState.Acquired,
                                         sortedSetEntry.Score, sortedSetEntry.Element);
                    triggers.Add(trigger);
                }

            } while (retry);

            return triggers;
        }
开发者ID:icyice80,项目名称:QuartzRedisJobStore,代码行数:67,代码来源:BaseJobStorage.cs

示例7: ToLocalTime

 public static DateTimeOffset ToLocalTime(DateTimeOffset date)
 {
     TimeSpan offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
     return date.Add(offset).AddHours(BlogSettings.Instance.Timezone);
 }
开发者ID:rajgit31,项目名称:RajBlog,代码行数:5,代码来源:Imaginary.Shared.cs

示例8: Since

 /// <summary>
 /// Returns a <see cref="DateTimeOffset"/> which add current <see cref="TimeSpan"/> since from the <paramref name="time"/>.
 /// </summary>
 /// <param name="source">A <see cref="TimeSpan"/> instance.</param>
 /// <param name="time">A <see cref="DateTimeOffset"/> since from.</param>
 /// <returns>Returns a <see cref="DateTimeOffset"/> which add current <see cref="TimeSpan"/> since from the <paramref name="time"/>.</returns>
 public static DateTimeOffset Since(this TimeSpan source, DateTimeOffset time)
 {
     return time.Add(source);
 }
开发者ID:jittuu,项目名称:NSupport,代码行数:10,代码来源:TimeSpanDateTimeOffset.cs

示例9: CreateWeekRange

        /// <summary>
        /// Creates the week range.
        /// </summary>
        /// <param name="current">The current</param>
        /// <param name="cultureInfo">The culture info</param>
        /// <returns>Set of days</returns>
        public static DateRange CreateWeekRange(DateTimeOffset current, CultureInfo cultureInfo)
        {
            DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
            int diff = (7 + ((int)current.DayOfWeek - (int)firstDay)) % 7;

            DateTimeOffset start = new DateTimeOffset(current.Year, current.Month, current.Day - diff, 0, 0, 0, 0, TimeSpan.Zero);
            DateTimeOffset end = start.Add(new TimeSpan(7, 0, 0, 0, -1));

            return new DateRange(start, end);
        }
开发者ID:eserozvataf,项目名称:tasslehoff,代码行数:16,代码来源:DateRange.cs

示例10: CreateMetadataForSession

        private static SessionMetadata CreateMetadataForSession(int sessionId, DateTimeOffset startTime, TimeSpan duration)
        {
            var metadata = new SessionMetadata
            {
                SessionID = sessionId,
                BitFlags = 59
            };

            metadata.PipeInfo = new PipeInfo { Streamed = true, Reused = false, CltReuse = false };
            const string format = @"yyyy-MM-ddTHH\:mm\:ss.fffffffzzz";
            metadata.SessionTimers = new SessionTimers
            {
                ClientConnected = startTime.ToString(format),
                ClientBeginRequest = startTime.ToString(format),
                GotRequestHeaders = startTime.ToString(format),
                ClientDoneRequest = startTime.ToString(format),
                ServerConnected = startTime.ToString(format),
                FiddlerBeginRequest = startTime.ToString(format),
                ServerGotRequest = startTime.ToString(format),
                ServerBeginResponse = startTime.Add(duration).ToString(format),
                GotResponseHeaders = startTime.Add(duration).ToString(format),
                ServerDoneResponse = startTime.Add(duration).ToString(format),
                ClientBeginResponse = startTime.Add(duration).ToString(format),
                ClientDoneResponse = startTime.Add(duration).ToString(format)
            };

            metadata.SessionFlags.Add(new SessionFlag { Name = SessionFlag.ClientIP, Value = "127.0.0.1" });
            metadata.SessionFlags.Add(new SessionFlag { Name = SessionFlag.ProcessInfo, Value = "apidocs.exe:1234" });

            return metadata;
        }
开发者ID:rgregg,项目名称:markdown-scanner,代码行数:31,代码来源:HttpLogGenerator.cs

示例11: RunSingleEpoch

        private Epoch RunSingleEpoch(double sampleRate, int nChannels, IEpochPersistor epochPersistor)
        {
            Epoch e;
            IExternalDevice dev0;
            RenderedStimulus stim1;
            IExternalDevice dev1;
            RenderedStimulus stim2;
            IList<IMeasurement> stimData;
            var controller = SetupController(sampleRate, out e, out dev0, out stim1, out dev1, out stim2, out stimData, nChannels);

            var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6));

            var h5Persistor = epochPersistor as H5EpochPersistor;
            if (h5Persistor != null)
            {
                h5Persistor.BeginEpochBlock(e.ProtocolID, e.ProtocolParameters, time);
            }
            else
            {
                epochPersistor.BeginEpochBlock(e.ProtocolID, e.ProtocolParameters);
            }

            controller.RunEpoch(e, epochPersistor);

            if (h5Persistor != null)
            {
                h5Persistor.EndEpochBlock(time.Add(e.Duration));
            }
            else
            {
                epochPersistor.EndEpochBlock();
            }

            Assert.AreEqual((TimeSpan)stim1.Duration, e.Responses[dev0].Duration);
            if (nChannels > 1)
                Assert.AreEqual((TimeSpan)stim2.Duration, e.Responses[dev1].Duration);

            var inputData = e.Responses[dev0].Data;
            const double MAX_VOLTAGE_DIFF = 0.001;
            int failures = inputData.Select((t, i) => t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits)
                .Count(dif => Math.Abs(dif) > (decimal) MAX_VOLTAGE_DIFF);

            Assert.AreEqual(0, failures);

            return e;
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:46,代码来源:SimulationIntegration.cs

示例12: CheckForAvailableResources

        public int CheckForAvailableResources(int subscriptionId, DateTimeOffset sessionStart, DateTimeOffset sessionEnd)
        {
            int availableCPUs;

            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                //TODO: move warmUP and coolDown into the config
                TimeSpan warmUp = new TimeSpan(0, 20, 0);
                //there is an extra +5 as this is a safe assumption as how long will it take for azure to
                //delete the VMs
                TimeSpan coolDown = new TimeSpan(0, 30 + 5, 0);

                DateTimeOffset start = sessionStart.Subtract(warmUp);
                DateTimeOffset end = sessionEnd.Add(coolDown);

                var sameWindowSessions = context.Sessions.Where(x => x.SubscriptionId == subscriptionId &&
                    x.StartDate <= end && x.EndDate >= start && !x.Removed).ToList();

                //int projectedCPUs = sameWindowSessions.Sum(x => Sessions.CalculateSessionCPUs(x));
                int projectedCPUs = MaxOverlappingCPUs(sameWindowSessions);

                //now check how many VMs programmed are running at the moment
                List<VmSizeEnum> runningVMs = context.VirtualMachines
                    .Where(x => !x.Deleted && !x.Stopped && x.Session.SubscriptionId == subscriptionId)
                    .Select(x => x.Session.VmSize).ToList()
                    .Select(x => (VmSizeEnum)Enum.Parse(typeof(VmSizeEnum), x)).ToList();

                int currentPlannedCPUs = runningVMs.Sum(x => (int)x);

                Subscription subscription = context.Subscriptions
                        .Single(x => x.SubscriptionId == subscriptionId);

                IVMManagement management = AzureFacadeFactory.VMManagement(subscription.AzureSubscriptionId,
                    subscription.Certificate, subscription.CertificateKey, subscription.BlobStorageName,
                    subscription.BlobStorageKey);
                SubscriptionDetails subscriptionDetails = management.GetSubscriptionDetails();
                int unknownCPUs = subscriptionDetails.MaxCoreCount - subscriptionDetails.AvailableCoreCount -
                    currentPlannedCPUs;

                unknownCPUs = Math.Max(unknownCPUs, 0);

                availableCPUs = subscriptionDetails.MaxCoreCount - unknownCPUs - projectedCPUs;
            }

            return availableCPUs;
        }
开发者ID:Beterer,项目名称:tnLabs,代码行数:46,代码来源:SubscriptionService.cs


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