Skip to content

Duration: support negative values#1249

Merged
mikearnaldi merged 2 commits intomainfrom
spec/duration-negative-values
Feb 16, 2026
Merged

Duration: support negative values#1249
mikearnaldi merged 2 commits intomainfrom
spec/duration-negative-values

Conversation

@mikearnaldi
Copy link
Copy Markdown
Member

Summary

  • Unclamp Duration.make — negative numbers now produce negative Millis/Nanos values instead of being clamped to zero. -Infinity maps to the new NegativeInfinity variant; NaN maps to zero.
  • New NegativeInfinity variant added to DurationValue discriminated union, with full support across ordering (NegativeInfinity < finite < Infinity), arithmetic (signed-infinity rules following IEEE 754), conversions (toMillis, toHrTime, parts, format), and pattern matching (match/matchPair).
  • New functions: isNegative, isPositive, abs, negate; updated isFinite and isZero.
  • Consumer guards added for 6 call sites that would break with negative inputs: RateLimiter (window ≥ 1ms), OtlpExporter (interval ≥ 100ms), PersistedQueue (intervals ≥ 1ms), Persistence (skip negative TTL), RpcClient (TTL ≥ 1s), Metric (maxAge ≥ 0).
  • Schema encode handles NegativeInfinity (maps to Millis(0) since the schema already rejects negatives via validation).
  • Tests: 5 existing tests updated for new behavior, comprehensive negative value test suite added.

Validation

  • pnpm lint-fix — 0 errors
  • pnpm check — passes
  • pnpm test — 5472 tests, 203 files, all pass
  • pnpm build — passes
  • pnpm docgen — passes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 16, 2026

📊 JSDoc Documentation Analysis

📈 Current Analysis Results
Analyzing 125 TypeScript files in packages/effect/src/ (including schema and config subdirectories)...

============================================================
         EFFECT JSDOC ANALYSIS REPORT
============================================================

📊 SUMMARY STATISTICS
------------------------------
Total files analyzed: 125
Total exported members: 4044
Missing @example: 1925 (47.6%)
Missing @category: 436 (10.8%)

🎯 TOP FILES NEEDING ATTENTION
----------------------------------------
1. Schema.ts
   📝 458 missing examples, 🏷️  262 missing categories
   📦 458 total exports
2. Array.ts
   📝 136 missing examples, 🏷️  2 missing categories
   📦 141 total exports
3. SchemaRepresentation.ts
   📝 96 missing examples, 🏷️  13 missing categories
   📦 96 total exports
4. SchemaAST.ts
   📝 77 missing examples, 🏷️  21 missing categories
   📦 77 total exports
5. Cause.ts
   📝 75 missing examples, 🏷️  2 missing categories
   📦 75 total exports
6. Channel.ts
   📝 76 missing examples, 🏷️  0 missing categories
   📦 147 total exports
7. Option.ts
   📝 66 missing examples, 🏷️  3 missing categories
   📦 66 total exports
8. Sink.ts
   📝 64 missing examples, 🏷️  2 missing categories
   📦 81 total exports
9. Predicate.ts
   📝 57 missing examples, 🏷️  0 missing categories
   📦 57 total exports
10. SchemaGetter.ts
   📝 49 missing examples, 🏷️  0 missing categories
   📦 49 total exports
11. SchemaTransformation.ts
   📝 29 missing examples, 🏷️  18 missing categories
   📦 29 total exports
12. Result.ts
   📝 45 missing examples, 🏷️  0 missing categories
   📦 45 total exports
13. Config.ts
   📝 33 missing examples, 🏷️  5 missing categories
   📦 33 total exports
14. Types.ts
   📝 37 missing examples, 🏷️  0 missing categories
   📦 37 total exports
15. JsonSchema.ts
   📝 17 missing examples, 🏷️  17 missing categories
   📦 17 total exports

✅ PERFECTLY DOCUMENTED FILES
-----------------------------------
   Chunk.ts (87 exports)
   Clock.ts (5 exports)
   FiberHandle.ts (15 exports)
   FiberMap.ts (19 exports)
   FiberSet.ts (14 exports)
   HKT.ts (4 exports)
   HashMap.ts (44 exports)
   HashSet.ts (21 exports)
   Match.ts (57 exports)
   MutableHashSet.ts (9 exports)
   MutableRef.ts (17 exports)
   NonEmptyIterable.ts (3 exports)
   Random.ts (7 exports)
   Redacted.ts (9 exports)
   RegExp.ts (3 exports)
   Runtime.ts (3 exports)
   Symbol.ts (1 exports)
   Trie.ts (29 exports)
   TxChunk.ts (22 exports)
   TxHashMap.ts (41 exports)
   TxHashSet.ts (24 exports)
   TxRef.ts (7 exports)
   TxSemaphore.ts (14 exports)
   Unify.ts (8 exports)
   index.ts (0 exports)

🔍 SAMPLE MISSING ITEMS FROM Schema.ts
-----------------------------------
   Optionality (type, line 60): missing example, category
   Mutability (type, line 67): missing example, category
   ConstructorDefault (type, line 74): missing example, category
   MakeOptions (interface, line 82): missing example, category
   Bottom (interface, line 106): missing example, category
   declareConstructor (interface, line 158): missing example, category
   declareConstructor (function, line 182): missing example
   declare (interface, line 206): missing example
   declare (function, line 215): missing example, category
   revealBottom (function, line 235): missing example, category

📋 BREAKDOWN BY EXPORT TYPE
-----------------------------------
const: 959 missing examples, 124 missing categories
interface: 302 missing examples, 124 missing categories
type: 223 missing examples, 71 missing categories
function: 337 missing examples, 96 missing categories
namespace: 47 missing examples, 20 missing categories
class: 57 missing examples, 1 missing categories

📈 DOCUMENTATION PROGRESS
------------------------------
Examples: 2119/4044 (52.4% complete)
Categories: 3608/4044 (89.2% complete)

============================================================
Analysis complete! 2361 items need attention.
============================================================

📄 Detailed results saved to: jsdoc-analysis-results.json

This comment is automatically updated on each push. View the analysis script for details.

@github-actions
Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.27 KB 6.27 KB 0.00 KB (0.00%)
batching.ts 8.53 KB 8.53 KB 0.00 KB (0.00%)
brand.ts 6.21 KB 6.21 KB 0.00 KB (0.00%)
cache.ts 9.73 KB 9.63 KB +0.10 KB (+1.06%)
config.ts 16.15 KB 16.15 KB 0.00 KB (0.00%)
differ.ts 14.35 KB 14.35 KB 0.00 KB (0.00%)
http-client.ts 19.17 KB 19.08 KB +0.09 KB (+0.47%)
logger.ts 8.88 KB 8.85 KB +0.03 KB (+0.29%)
metric.ts 8.79 KB 8.79 KB 0.00 KB (0.00%)
optic.ts 7.46 KB 7.46 KB 0.00 KB (0.00%)
pubsub.ts 13.24 KB 13.16 KB +0.09 KB (+0.65%)
queue.ts 11.10 KB 11.02 KB +0.08 KB (+0.72%)
schedule.ts 9.85 KB 9.76 KB +0.09 KB (+0.96%)
schema-representation-roundtrip.ts 23.89 KB 23.89 KB 0.00 KB (0.00%)
schema-string-transformation.ts 11.39 KB 11.32 KB +0.07 KB (+0.64%)
schema-string.ts 9.63 KB 9.63 KB 0.00 KB (0.00%)
schema-template-literal.ts 12.14 KB 12.14 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 16.37 KB 16.37 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 19.23 KB 19.23 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 15.22 KB 15.22 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 15.49 KB 15.49 KB 0.00 KB (0.00%)
schema-toFormatter.ts 15.36 KB 15.36 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 17.96 KB 17.96 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 16.15 KB 16.15 KB 0.00 KB (0.00%)
schema.ts 15.00 KB 15.00 KB 0.00 KB (0.00%)
stm.ts 12.11 KB 12.03 KB +0.08 KB (+0.68%)
stream.ts 8.48 KB 8.48 KB 0.00 KB (0.00%)

@mikearnaldi mikearnaldi mentioned this pull request Feb 16, 2026
5 tasks
@mikearnaldi mikearnaldi force-pushed the spec/duration-negative-values branch from 5f42e38 to a755047 Compare February 16, 2026 14:11
@mikearnaldi mikearnaldi requested a review from IMax153 February 16, 2026 14:18
@mikearnaldi
Copy link
Copy Markdown
Member Author

@copilot rebase this on main

Copy link
Copy Markdown

Copilot AI commented Feb 16, 2026

@mikearnaldi I've opened a new pull request, #1257, to work on those changes. Once the pull request is ready, I'll request review from you.

Unclamp the make constructor to allow negative durations. Add
NegativeInfinity variant to DurationValue, new predicates (isNegative,
isPositive, abs, negate), and update all arithmetic, conversions,
ordering, and formatting to handle negatives with IEEE 754 sign rules.

Guard consumers that would break with negative inputs: RateLimiter,
OtlpExporter, PersistedQueue, Persistence, RpcClient, Metric.
OtlpExporter: clamp to zero instead of 100ms to preserve valid sub-100ms intervals.
RpcClient: revert timeToLive guard entirely; Pool.makeWithTTL handles DurationInput directly.
@mikearnaldi mikearnaldi force-pushed the spec/duration-negative-values branch from a755047 to 7be5e4c Compare February 16, 2026 21:08
@mikearnaldi mikearnaldi merged commit 8db5333 into main Feb 16, 2026
13 of 14 checks passed
@mikearnaldi mikearnaldi deleted the spec/duration-negative-values branch February 16, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants