{"record":{"id":"2c4a5a218ae830b7","repo":"dotnet/reactive","slug":"duration-observable-time","errorCode":null,"errorMessage":"duration","messagePattern":"duration","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":953,"sourceCode":"        /// <para>\n        /// Specifying a TimeSpan.Zero value for <paramref name=\"duration\"/> doesn't guarantee no elements will be dropped from the start of the source sequence.\n        /// This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded\n        /// may not execute immediately, despite the TimeSpan.Zero due time.\n        /// </para>\n        /// <para>\n        /// Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the <paramref name=\"duration\"/>.\n        /// </para>\n        /// </remarks>\n        public static IObservable<TSource> Skip<TSource>(this IObservable<TSource> source, TimeSpan duration)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (duration < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(duration));\n            }\n\n            return s_impl.Skip(source, duration);\n        }\n\n        /// <summary>\n        /// Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to skip elements for.</param>\n        /// <param name=\"duration\">Duration for skipping elements from the start of the sequence.</param>\n        /// <param name=\"scheduler\">Scheduler to run the timer on.</param>\n        /// <returns>An observable sequence with the elements skipped during the specified duration from the start of the source sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"duration\"/> is less than TimeSpan.Zero.</exception>\n        /// <remarks>\n        /// <para>\n        /// Specifying a TimeSpan.Zero value for <paramref name=\"duration\"/> doesn't guarantee no elements will be dropped from the start of the source sequence.","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L935-L971","documentation":"The time-based Skip<TSource>(IObservable<TSource>, TimeSpan) operator throws ArgumentOutOfRangeException when the duration is negative (duration < TimeSpan.Zero). Skipping a negative amount of time is meaningless; zero is allowed and skips nothing.","triggerScenarios":"Calling source.Skip(TimeSpan.FromSeconds(-2)) — any negative TimeSpan as the duration, typically from inverted date arithmetic or an unvalidated config value.","commonSituations":"Computing duration from timestamps in the wrong order; a config value like '-5s' parsed without validation; arithmetic on TimeSpan that underflows.","solutions":["Clamp the duration: Math.Max(TimeSpan.Zero, computed) before calling Skip.","Validate config/user input so negative durations are rejected upstream.","Fix the timestamp arithmetic that produced the negative value."],"exampleFix":"// before\nvar skipBy = end - start; // may be negative\nvar result = source.Skip(skipBy); // ArgumentOutOfRangeException\n\n// after\nvar skipBy = end > start ? end - start : TimeSpan.Zero;\nvar result = source.Skip(skipBy);","handlingStrategy":"validation","validationCode":"if (duration < TimeSpan.Zero)\n    throw new ArgumentException($\"duration must be >= 0, was {duration}\");\nvar result = source.Skip(duration);","typeGuard":"static bool IsValidDuration(TimeSpan duration) => duration >= TimeSpan.Zero;","tryCatchPattern":"try\n{\n    var result = source.Skip(duration);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    var result = source; // skip nothing as a safe fallback\n}","preventionTips":["Clamp durations from timestamp differences: Math.Max(TimeSpan.Zero, diff).","Reject negative durations when parsing config or user input.","Remember TimeSpan.Zero is valid and skips nothing — use it as the floor."],"tags":["argument-out-of-range","rx","skip","timespan"],"backgroundTag":"argument-out-of-range","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}