Skip to content

feat(#4792): add useTemporal #4793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JonathanSchndr
Copy link
Contributor

@JonathanSchndr JonathanSchndr commented Jun 3, 2025

Description

Issue: #4792

This PR introduces useTemporal, a new composable that provides a reactive wrapper around the modern Temporal API (TC39 proposal) using the @js-temporal/polyfill package. This implementation addresses the limitations of the legacy Date object by providing:

  • 🌍 Robust timezone handling with conversion utilities
  • 📅 Support for multiple calendar systems (Gregorian, Islamic, Hebrew, etc.)
  • ⚡ Configurable reactive updates
  • 🎯 Comprehensive TypeScript support
  • 🔧 Rich set of date/time manipulation functions

The implementation includes:

  • Full test coverage (index.test.ts)
  • Comprehensive documentation (index.md)
  • Interactive demo component (demo.vue)
  • Two main exports:
    • useTemporal(): Reactive composable
    • createTemporal(): Static utility function

I have:

  • Read the Contributing Guidelines
  • Read the Pull Request Guidelines
  • Verified no similar PR exists
  • Included comprehensive tests
  • Added detailed documentation
  • Created a demo component

Additional context

This implementation is particularly focused on:

  1. Type safety: Full TypeScript support with proper Temporal types
  2. Flexibility: Support for different timezones and calendar systems
  3. Performance: Efficient updates using shallowRef
  4. Testing: Comprehensive test coverage including edge cases
  5. Documentation: Detailed API documentation with examples

The demo component showcases real-world usage scenarios including:

  • World clock functionality
  • Calendar system conversion
  • Duration-based calculations
  • Formatting options

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request new function labels Jun 3, 2025
Adds createTemporal and useTemporal functions along with their
corresponding ./useTemporal module exports.
@JonathanSchndr
Copy link
Contributor Author

I would like to discuss again whether https://github.com/fullcalendar/temporal-polyfill is not the better polyfill? What is your opinion?

Screenshot 2025-06-04 at 08 48 15

Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are on hold for introducing new functions, and also that Temporal is still in Stage 3, https://github.com/tc39/proposal-temporal. I think we'd better leave it to community until the propose is land.

@JonathanSchndr
Copy link
Contributor Author

We are on hold for introducing new functions, and also that Temporal is still in Stage 3, https://github.com/tc39/proposal-temporal. I think we'd better leave it to community until the propose is land.

My reason was that Firefox is now the first browser to support this natively and I have the hope that the others will soon follow suit. Therefore, my idea was to support this transition with the polyfill. But let’s wait until it has a better native coverage, then the polyfill would be removed and the PR would revise it. What do you think of the procedure? I think everyone hates new date 😅

@antfu
Copy link
Member

antfu commented Jun 5, 2025

Stage 3 is not stable enough. Once the proposal is landed, I think we can have it in the core package and without the polyfill (polyfill should be something for users to install themselves if needed)

@JonathanSchndr
Copy link
Contributor Author

Great, then I would wait for it and adjust the PR as soon as it has increased the coverage and stability. You are also welcome to ping me if you think it is the right time. Thank you 😊👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new function size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants