adobe / adobe/react-spectrum

Difference between dates in @internationalized/date

Open
#8,612 5 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
15.9k
Forks
1.6k
Avg merge
3d 5h
Merged PRs (30d)
58

Description

### Provide a general summary of the feature here

It would be great if it was possible to return the number of years/months/days etc between two dates/datetimes in `@internationalized/date`. Something like https://moment.github.io/luxon/#/math?id=diffs or https://tc39.es/proposal-temporal/docs/plaindatetime.html#until which can return the difference in a variety of units.

### 🤔 Expected Behavior?

A method on the date/time instances that can be called to get a difference between it and another date, like

```
startDate.diff(endDate) // returns { years: 1, months: 1, ... }
```

### 😯 Current Behavior

Currently no equivalent feature exists.

### 💁 Possible Solution

_No response_

### 🔦 Context

I need to calculate differences between dates to show them in the UI, or change how the UI acts depending on the length of the ranges.

### 💻 Examples

_No response_

### 🧢 Your Company/Team

_No response_

### 🕷 Tracking Issue

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the @internationalized/date API and the linked Luxon and Temporal difference references. Clarify the supported units, result semantics, and date versus datetime behavior with maintainers; done means an agreed API with coverage for the requested differences.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.