Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
169e06d
refactor: update isValidDate return type for improved type safety
bart-krakowski May 29, 2024
75cb7b3
refactor: update isValidDate return type for improved type safety
bart-krakowski May 29, 2024
5dca8d5
refactor: update isValidDate return type for improved type safety
bart-krakowski May 30, 2024
4fb89ec
test: refactor tests for the parse util
bart-krakowski May 30, 2024
b2bbb4d
refactor: types for utils
bart-krakowski May 30, 2024
e9e4be9
revert: isValidDate util
bart-krakowski May 30, 2024
780b2da
Merge branch 'v0' into chore/vitest-config
bart-krakowski May 30, 2024
ae48b69
docs: architecture md file
bart-krakowski May 30, 2024
d64d04a
feat: useCalendar hook
bart-krakowski Jun 1, 2024
28b4304
test: useCalendar tests
bart-krakowski Jun 2, 2024
28f491c
docs: useCalendar hook
bart-krakowski Jun 2, 2024
468dc26
docs: useCalendar hook
bart-krakowski Jun 2, 2024
0b9bdeb
test: useCalendar tests
bart-krakowski Jun 2, 2024
5b6533e
test: useCalendar tests
bart-krakowski Jun 2, 2024
37effd4
test: overlaping events
bart-krakowski Jun 2, 2024
c0e5713
docs: add the choosing-a-date-time-handling-solution adr
bart-krakowski Jun 2, 2024
096f95d
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski Jun 3, 2024
26b0e1e
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski Jun 3, 2024
3cf89c3
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski Jun 3, 2024
4ae3c45
refactor: reducer
bart-krakowski Jun 3, 2024
4009dae
refactor: reducer
bart-krakowski Jun 3, 2024
fa3716a
refactor(useCalendar): types
bart-krakowski Jun 4, 2024
131984b
refactor(useCalendar): types
bart-krakowski Jun 4, 2024
e542934
refactor: useCalendar reducer
bart-krakowski Jun 4, 2024
a149778
refactor: useCalendar reducer
bart-krakowski Jun 5, 2024
28ac64f
refactor: useCalendar reducer
bart-krakowski Jun 5, 2024
dfa353a
feat: add the isToday field
bart-krakowski Jun 5, 2024
8742087
feat: add the isToday field
bart-krakowski Jun 5, 2024
3d6f74a
feat: add the isToday field
bart-krakowski Jun 5, 2024
d93b29d
docs: useCalendar
bart-krakowski Jun 5, 2024
6432973
feat: useCalendar hook
bart-krakowski Jun 5, 2024
75a445a
cd
bart-krakowski Jun 5, 2024
7536efc
feat: useCalendar hook
bart-krakowski Jun 5, 2024
29d20ae
feat: useCalendar hook
bart-krakowski Jun 5, 2024
e37dbf7
feat: useCalendar hook
bart-krakowski Jun 5, 2024
d76ddc1
feat: useCalendar hook
bart-krakowski Jun 5, 2024
f6b6f29
test: useCalendar
bart-krakowski Jun 5, 2024
d9ed5e7
test: useCalendar
bart-krakowski Jun 5, 2024
7b8662b
test: useCalendar
bart-krakowski Jun 5, 2024
be2e360
feat: custom reducer
bart-krakowski Jun 6, 2024
4ccd56b
docs: tsdocs
bart-krakowski Jun 6, 2024
cc59409
docs: tsdocs
bart-krakowski Jun 6, 2024
8d51b58
docs: tsdocs
bart-krakowski Jun 6, 2024
1e71684
refactor: useCalendar
bart-krakowski Jun 6, 2024
e134065
refactor: useCalendar
bart-krakowski Jun 6, 2024
f3f47ed
refactor: useCalendar
bart-krakowski Jun 6, 2024
1ee814a
refactor: change viewMode type
bart-krakowski Jun 9, 2024
c2419de
refactor: change viewMode type
bart-krakowski Jun 9, 2024
215f722
fix: missing days in view
bart-krakowski Jun 9, 2024
0f05c00
refactor: api
bart-krakowski Jun 11, 2024
def6499
refactor: api
bart-krakowski Jun 11, 2024
110e8be
fix: types
bart-krakowski Jun 11, 2024
3333fcb
fix: types
bart-krakowski Jun 11, 2024
492405b
fix: types
bart-krakowski Jun 11, 2024
7bee6b4
fix: types
bart-krakowski Jun 11, 2024
83f0724
docs: useCalendar
bart-krakowski Jun 11, 2024
e4fb70a
docs: useCalendar
bart-krakowski Jun 11, 2024
e598c20
fix: types
bart-krakowski Jun 11, 2024
a9665a7
refactor: add the fillMissingDays argument
bart-krakowski Jun 11, 2024
d9e9b88
refactor: add the fillMissingDays argument
bart-krakowski Jun 11, 2024
fe13c2c
refactor: add the fillMissingDays argument
bart-krakowski Jun 11, 2024
9f99846
refactor: move utilities to the core package
bart-krakowski Jun 11, 2024
93b519a
fix: getCurrentTimeMarkerProps
bart-krakowski Jun 12, 2024
87544e2
docs: update jsdocs
bart-krakowski Jun 12, 2024
b5ae21e
test: useCalendar
bart-krakowski Jun 12, 2024
f5bd2b7
refactor: getCurrentTimeMarkerProps
bart-krakowski Jun 12, 2024
c03128c
feat: calendar core
bart-krakowski Jun 13, 2024
3c48a5e
feat: calendar core
bart-krakowski Jun 13, 2024
6499475
feat: calendar core
bart-krakowski Jun 13, 2024
2ac6065
docs: calendar core
bart-krakowski Jun 13, 2024
a71f5a8
refactor: useCalendar
bart-krakowski Jun 13, 2024
965de14
test: calendar core
bart-krakowski Jun 17, 2024
301d4b8
refactor: useCalendar
bart-krakowski Jun 17, 2024
1324311
refactor: useCalendar
bart-krakowski Jun 17, 2024
042bb13
refactor: useCalendar
bart-krakowski Jun 17, 2024
82c1c87
refactor(useCalendar): types
bart-krakowski Jun 17, 2024
f61a99d
refactor: move calendar-related files to the core directory
bart-krakowski Jun 20, 2024
dc3bcbf
refactor: update CalendarCoreOptions interface to use default generic…
bart-krakowski Jun 20, 2024
1465e85
refactor: Update CalendarCoreOptions interface in calendar.ts
bart-krakowski Jun 20, 2024
55751f8
feat: date picker core
bart-krakowski Jun 20, 2024
3f4ef79
test: imports
bart-krakowski Jun 20, 2024
ce4fa6b
feat: date picker core
bart-krakowski Jun 20, 2024
bff5f34
docs: typo
bart-krakowski Jun 20, 2024
1c10f14
refactor: DatePickerCore
bart-krakowski Jun 21, 2024
57c547e
refactor: DatePickerCore
bart-krakowski Jun 21, 2024
3dc223d
refactor: weekInfoPolyfill
bart-krakowski Jun 23, 2024
2eabee4
refactor: weekInfoPolyfill
bart-krakowski Jun 23, 2024
564c4e7
refactor: weekInfoPolyfill
bart-krakowski Jun 23, 2024
1a5f193
refactor: weekInfoPolyfill
bart-krakowski Jun 24, 2024
3331c17
refactor: date defaults
bart-krakowski Jun 24, 2024
e1f9c12
refactor: date defaults
bart-krakowski Jun 24, 2024
1dfecfb
refactor: date defaults
bart-krakowski Jun 24, 2024
277f416
refactor: types
bart-krakowski Jun 25, 2024
4131b8e
docs: jsdocs
bart-krakowski Jun 25, 2024
b7f67f0
refactor: types
bart-krakowski Jun 25, 2024
4165b20
refactor: types
bart-krakowski Jun 25, 2024
1b71c7e
test: useCalendar
bart-krakowski Jun 25, 2024
604c8bb
refactor: useIsomorphicLayoutEffect
bart-krakowski Jun 25, 2024
a1812ee
chore: resolve conflicts
bart-krakowski Jun 25, 2024
4ee4be4
chore: resolve conflicts
bart-krakowski Jun 25, 2024
bd1d3e3
docs: jsdocs
bart-krakowski Jun 25, 2024
6311195
docs: calendar
bart-krakowski Jun 26, 2024
6627c0c
docs: calendar
bart-krakowski Jun 26, 2024
df925d4
refactor: zonedDateTime
bart-krakowski Jun 28, 2024
c65b760
refactor: rename startDate to start and endDate to end
bart-krakowski Jun 28, 2024
18ad00c
refactor: remove the getCurrentTimeMarkerProps method
bart-krakowski Jun 28, 2024
403df99
refactor: weekInfoPolyfill
bart-krakowski Jun 30, 2024
a805131
refactor: add a resources field to event
bart-krakowski Jun 30, 2024
e17f0cd
refactor: add a resources field to event
bart-krakowski Jun 30, 2024
396d629
refactor: add a resources field to event
bart-krakowski Jun 30, 2024
adc9998
refactor: add startOf and endOf helpers
bart-krakowski Jun 30, 2024
31470b4
refactor: remove all the layout specific code
bart-krakowski Jun 30, 2024
16867e8
refactor: update getDaysNames method to accept weekday parameter
bart-krakowski Jul 1, 2024
be68798
refactor: update useCalendar test to mock current date and time
bart-krakowski Jul 1, 2024
c3ba0c9
refactor: update useCalendar test to mock current date and time
bart-krakowski Jul 1, 2024
5afea3e
test: update useCalendar tests
bart-krakowski Jul 1, 2024
15aced5
test: update useCalendar tests
bart-krakowski Jul 1, 2024
eb8b7b7
test: useCalendar
bart-krakowski Jul 1, 2024
4d71196
refactor: update CalendarCore tests to mock current date and time
bart-krakowski Jul 1, 2024
fbbae15
refactor: Update CalendarCore to use destructuring assignment for dat…
bart-krakowski Jul 2, 2024
ce9b924
feat: add the activeDate property
bart-krakowski Jul 2, 2024
66bfe53
refactor: use compare method
bart-krakowski Jul 2, 2024
06f633d
feat: add workWeek unit
bart-krakowski Jul 2, 2024
0c8c868
feat: add workWeek unit
bart-krakowski Jul 2, 2024
4b7ea40
test: tests reorganisation
bart-krakowski Jul 2, 2024
d544348
chore: add the get-week-info-polyfill
bart-krakowski Jul 3, 2024
d090483
feat: getWeekInfo polyfill
bart-krakowski Jul 3, 2024
178aa34
refactor: getEventProps
bart-krakowski Jul 3, 2024
79fdfdd
refactor: getEventProps
bart-krakowski Jul 3, 2024
20fb06d
refactor: Update generateDateRange to accept string inputs
bart-krakowski Jul 3, 2024
8ae1bcd
chore: upgrade polyfill
bart-krakowski Jul 4, 2024
0e974ac
fix: getEventProps
bart-krakowski Jul 4, 2024
85c6a77
fix: getEventProps
bart-krakowski Jul 4, 2024
72d43d4
refactor: update date inputs to accept string format
bart-krakowski Jul 4, 2024
cbc2186
refactor: convert activeDate, currentPeriod to string in useCalendar
bart-krakowski Jul 4, 2024
1f6048e
refactor: startOf and endOf helpers
bart-krakowski Jul 18, 2024
291cfb1
test: calendar core
bart-krakowski Jul 18, 2024
3aa0488
refactor: update useCalendar to accept string inputs for activeDate a…
bart-krakowski Jul 20, 2024
8850d2a
refactor: Update get-week-info-polyfill dependency to version 1.0.6
bart-krakowski Jul 20, 2024
fe67772
refactor: Update startOf and endOf helpers to accept string inputs
bart-krakowski Jul 20, 2024
e17fa79
docs: update architecture
bart-krakowski Jul 24, 2024
de02743
# This is a combination of 6 commits.
bart-krakowski Aug 7, 2024
b693102
docs: readme
bart-krakowski Aug 8, 2024
e2c36c4
chore: dependencies update
bart-krakowski Apr 25, 2025
12c8af3
chore: dependencies update
bart-krakowski Apr 25, 2025
691b3bb
Merge branch 'TanStack:v0' into v0
bart-krakowski May 7, 2025
b489069
chore: resolve conflicts
bart-krakowski Jan 9, 2026
b38caa8
Merge pull request #1 from bart-krakowski/chore/vitest-config
bart-krakowski Jan 9, 2026
6843cc4
docs: architecture
bart-krakowski Jan 9, 2026
6c46b9e
Merge branch 'v0-1-0' into docs/readme
bart-krakowski Jan 9, 2026
24d03e6
docs: readme
bart-krakowski Jan 9, 2026
7dafbf3
docs: adr choosing a date and time handling solution
bart-krakowski Jan 9, 2026
42b842a
fix: parse util
bart-krakowski Jan 9, 2026
9015ee6
fix: parse util
bart-krakowski Jan 9, 2026
ee3b26e
test: parse
bart-krakowski Jan 9, 2026
b081caf
fix: parse util
bart-krakowski Jan 9, 2026
b4e62cc
Merge branch 'v0-1-0' of github.com:bart-krakowski/time into v0-1-0
bart-krakowski Jan 9, 2026
4250b76
chore: resolve conflicts
bart-krakowski Jan 10, 2026
1895a01
chore: resolve conflicts
bart-krakowski Jan 10, 2026
23881aa
chore: resolve conflicts
bart-krakowski Jan 10, 2026
d2a89c7
test: update temporal mocks
bart-krakowski Jan 10, 2026
dc32b51
chore: update the lock file
bart-krakowski Jan 10, 2026
e2b5cb7
fix: lint
bart-krakowski Jan 10, 2026
40f58d3
fix: lint
bart-krakowski Jan 10, 2026
e536094
fix: lint
bart-krakowski Jan 10, 2026
e1785a4
feat: basic example
bart-krakowski Jan 10, 2026
5ad20ac
feat: basic example
bart-krakowski Jan 10, 2026
07ef441
feat: basic example
bart-krakowski Jan 10, 2026
bad6db8
feat: calendar
bart-krakowski Jan 11, 2026
cbfc28a
feat: calendar
bart-krakowski Jan 11, 2026
7bb371c
feat: calendar
bart-krakowski Jan 11, 2026
227a2df
feat: calendar
bart-krakowski Jan 11, 2026
1e7308f
feat: calendar
bart-krakowski Jan 11, 2026
dcbd9ef
feat: calendar
bart-krakowski Jan 11, 2026
1e0f970
chore: resolve conflicts
bart-krakowski Jan 11, 2026
6c761cb
feat: date picker
bart-krakowski Jan 11, 2026
cb6bfce
feat: date picker
bart-krakowski Jan 12, 2026
f01f1bd
feat: date picker
bart-krakowski Jan 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
Empty file.
81 changes: 81 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Overview

`@tanstack/time` is a headless utility library designed to facilitate the creation of time and calendar components across various JavaScript frameworks, including TypeScript/JavaScript, React, Solid, Vue, Svelte, and Angular. This document provides an overview of the architecture and design principles of the library.


## Design Principles

### Headless utilities
The library provides core functionalities without imposing any UI constraints, allowing developers to build custom UI components tailored to their specific needs.

### Framework agnostic
Core logic is implemented in a framework-agnostic manner, ensuring compatibility across multiple frameworks.

### Modular and extensible
The library is designed to be modular, enabling developers to use only the parts they need and extend functionalities when required.

### Type safety
Leveraging TypeScript to provide a strongly typed API, ensuring better developer experience and reducing runtime errors.

### Standards-based
The library uses standards-based core logic, aligning with modern web standards and best practices.
Internationalization and localization
TanStack Time is designed to handle various locales, calendars, and timezones, addressing the complexities of global date and time representation.
Core Modules
### Time utilities
The library provides a set of utilities for working with time, including parsing, formatting, and manipulating time values.

### Calendar utilities
Calendar utilities enable developers to work with calendar-related functionalities, such as date range calculations, month view generation, and event scheduling.

### Date manipulation
Utilities for performing date math, comparisons, grouping, and range operations.
Formatting
Flexible date and time formatting options based on locale, calendar, and timezone.

## Project Structure

The project is structured as follows:
```lua
├── packages # Contains individual packages for different frameworks
│ ├── time # Core logic shared across all packages
│ ├── src # Core logic implementation
│ ├── test # Unit tests
│ ├── {framework}-time # Adapters for specific frameworks (e.g., react-time, vue-time)
├── examples # Example applications demonstrating library usage
├── docs # Documentation files
├── scripts # Build and test scripts
```

The core logic is implemented in the `time` package, which contains the shared functionality across all framework-specific packages. Each framework-specific package (e.g., `react-time`, `vue-time`) contains the necessary adapters to integrate the core logic with the respective framework.


## API Design

The API of @tanstack/time is designed to be intuitive and flexible. It provides a set of core functions that can be easily composed to build complex time and calendar functionalities. The API is consistent across different frameworks, ensuring a seamless developer experience when switching between frameworks.

### Key API features include:

Parsing of RFC 3339 date time strings, epoch time, and Date objects
Formatting based on Intl.DateTimeFormat standards
Date math operations
Comparison and sorting utilities
Grouping and range operations
Timezone and DST handling

## Extensibility
The library is designed to be extensible, allowing developers to add custom functionalities or modify existing ones to suit their requirements. Developers can extend the core logic by creating custom utilities or by composing existing utilities in new ways.

### Temporal API Integration
TanStack Time leverages the upcoming Temporal API, using a polyfill maintained by the TC39 champions until it's fully ratified and implemented by all major browsers. This ensures forward compatibility and access to advanced date and time manipulation features.

### Internationalization
The library is built with internationalization in mind, addressing the complexities of different calendar systems, date formats, and time representations across various cultures and regions.

### Performance Considerations

Memoization is used for formatters to improve performance when repeatedly formatting dates.
The library provides options for working with "simple" date representations (strings or numbers) to facilitate easier memoization in application code.

### Compatibility
While focusing on modern standards, TanStack Time also provides compatibility options for working with legacy date formats and parsing methods, ensuring broad applicability across different project requirements.
81 changes: 81 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Code of Conduct
id: code-of-conduct
---

# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at TANNERLINSLEY@GMAIL.COM. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# time
# TanStack Time

![TanStack Time Header](media/repo-header.png)

🤖⏰ Headless utilities for building time and calendar components in TS/JS, React, Solid, Vue, Svelte and Angular

<a href="https://twitter.com/intent/tweet?button_hashtag=TanStack" target="\_parent">
<img alt="#TanStack" src="https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack">
</a><a href="https://discord.com/invite/WrRKjPJ" target="\_parent">
<img alt="" src="https://img.shields.io/badge/Discord-TanStack-%235865F2" />
</a><a href="https://npmjs.com/package/@tanstack/time" target="\_parent">
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/time.svg" />
</a><a href="https://bundlephobia.com/result?p=@tanstack/time" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/time" />
</a><a href="#badge">
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
</a><a href="https://github.com/tanstack/time/discussions">
<img alt="Join the discussion on Github" src="https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue" />
</a><a href="https://bestofjs.org/projects/time"><img alt="Best of JS" src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=tanstack%2Ftime%26since=daily" /></a><a href="https://github.com/tanstack/time" target="\_parent">
<img alt="" src="https://img.shields.io/github/stars/tanstack/time.svg?style=social&label=Star" />
</a><a href="https://twitter.com/tan_stack" target="\_parent">
<img alt="" src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social&label=Follow @TanStack" />
</a><a href="https://twitter.com/tannerlinsley" target="\_parent">
<img alt="" src="https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow @TannerLinsley" />
</a>

Enjoy this library? Try the entire [TanStack](https://tanstack.com)!

## Visit [tanstack.com/time](https://tanstack.com/time) for docs, guides, API and more!
91 changes: 91 additions & 0 deletions adr/choosing-a-date-time-handling-solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# ADR: Choosing a Date and Time Handling Solution

## Status

Accepted, decided on Temporal API.

## Context

In modern web applications, accurate and efficient handling of dates and times is crucial. Traditional JavaScript `Date`` objects have several limitations and pitfalls, including:
- Lack of support for different calendars
- Difficulties with time zone conversions
- Ambiguous and error-prone APIs for date and time manipulation

These issues often lead to bugs and inefficiencies in handling date and time data, especially in complex applications that require extensive date and time manipulations, such as calendar applications.

## Decision

After evaluating several options, we have decided to adopt the Temporal API for all date and time handling in our application. Temporal is a new standard for working with dates and times in JavaScript, designed to provide a more reliable, readable, and easy-to-use API.

### Evaluation of Alternatives

1. **JavaScript `Date`**
- **Pros**:
- Built-in and requires no additional dependencies.
- Supported natively in all JavaScript environments.
- **Cons**:
- Ambiguous and error-prone API.
- Poor support for time zones and different calendars.
- Mutable objects, leading to potential bugs.
- Date arithmetic is complex and error-prone.

2. **moment.js**
- **Pros**:
- Widely used and battle-tested.
- Rich feature set for date manipulation and formatting.
- **Cons**:
- Large library size, affecting bundle size.
- Mutable objects, leading to potential bugs.
- Moment.js is in maintenance mode, with no new features planned.

3. **date-fns**
- **Pros**:
- Modular approach, allowing selective imports to reduce bundle size.
- Immutable and functional API.
- Good support for date arithmetic and formatting.
- **Cons**:
- Limited support for time zones without additional libraries.
- Requires combining multiple functions for complex operations.

### Reasons for Choosing Temporal

1. **Clarity and Readability**: Temporal's API is designed to be intuitive and readable. For example, creating a date in Temporal is straightforward and unambiguous:
```javascript
const date = Temporal.PlainDate.from('2024-06-01');
```
This is much clearer than the equivalent using `Date`:
```javascript
const date = new Date('2024-06-01');
```

2. **Immutability**: Temporal objects are immutable, meaning that once created, they cannot be changed. This immutability prevents common bugs related to date manipulation and makes the code easier to reason about.

3. **Comprehensive Support for Calendars and Time Zones**: Temporal natively supports different calendars and time zones, making it ideal for applications that need to handle internationalization and localization.

4. **Precise Arithmetic Operations**: Temporal provides precise and easy-to-use methods for date and time arithmetic, avoiding the pitfalls of JavaScript `Date` arithmetic:
```javascript
const nextMonth = date.add({ months: 1 });
```

5. **Better Error Handling**: Temporal's API is designed to throw errors for invalid operations, which helps in catching bugs early in the development process.

6. **Standardization**: Temporal is an upcoming standard for date and time handling in JavaScript, which means it will have long-term support and improvements from the community and browser vendors.

## Consequences

### Positive

- **Reduced Bugs**: By using Temporal, we expect to see a reduction in date and time-related bugs, especially those related to time zone conversions and date arithmetic.
- **Improved Code Quality**: The clarity and immutability of Temporal will lead to more readable and maintainable code.
- **Enhanced Features**: Support for multiple calendars and time zones will allow us to build more robust and feature-rich internationalized applications.

### Negative

- **Learning Curve**: Developers will need to learn the new Temporal API, which might slow down initial development.
- **Polyfill Requirement**: Until Temporal is fully supported in all target environments, we will need to include a polyfill, which may slightly increase the bundle size.

## Conclusion

After evaluating various options for date and time handling in JavaScript, we have decided to adopt the Temporal API. Temporal provides a robust, readable, and reliable API that addresses the shortcomings of the existing `Date` object and offers comprehensive support for internationalization and time zone handling. Despite the initial learning curve and the need for a polyfill, the long-term benefits make Temporal the best choice for our application's needs.

By documenting this decision, we ensure that future developers understand the rationale behind adopting Temporal and can build upon this foundation with confidence.
Loading