Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 [email protected]. 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
4 changes: 2 additions & 2 deletions packages/time/src/tests/isValidDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {isValidDate} from '../utils/isValidDate';
describe('isValidDate', () => {
test('should return true for a valid date', () => {
expect(isValidDate(new Date())).toBe(true);
});
})

test('should return false for an invalid date', () => {
expect(isValidDate(new Date("invalid"))).toBe(false);
Expand All @@ -13,4 +13,4 @@ describe('isValidDate', () => {
test("should return false for null", () => {
expect(isValidDate(null)).toBe(false);
});
});
});